infinity.base64¶
Provides Base64-encoding and decoding functionality for strings, files and streams. The standard Base64 alphabet with = padding is used; encoded output contains no line breaks.
Module: infinity.encoding
Example:
infinity.loadModule('infinity.encoding');
let encodedData = infinity.base64.encode('AUO_ÄÜÖ ß-"+&,?.<=>');
console.debug(encodedData);
//QVVPX8OEw5zDliDDny0iKyYsPy48PT4=
let decodedData = infinity.base64.decode(encodedData);
console.debug(decodedData);
//AUO_ÄÜÖ ß-"+&,?.<=>
decode()¶
Decodes the given Base64 string to bytes and returns them as a string, decoded with the given encoding. Returns an empty string if value is empty.
Signature:
decode( value: string, encoding?: infinity.encoding ): string
Parameters:
-
value:
stringThe string to decode.
-
encoding:
infinity.encoding, optionalThe encoding of the decoded bytes. Defaults to
infinity.encoding.utf8.
Return type: string
Example:
infinity.loadModule('infinity.encoding');
let decodedData = infinity.base64.decode(encodedData, infinity.encoding.utf8);
decodeFile()¶
Reads out the contents of the given file, decodes them from Base64 and returns the decoded bytes as a string. The bytes are decoded with the system default encoding (the ANSI code page on Windows, UTF-8 on Linux and macOS). To get binary data or a specific encoding, use the variant with an output file or decode().
Signature:
decodeFile( fileName: string ): string
Parameters:
- fileName:
stringFilename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to the encoded file.
Return type: string
Example:
infinity.loadModule('infinity.encoding');
let decodedData = infinity.base64.decodeFile('encodedData.txt');
decodeFile()¶
Reads out the contents of the given file, decodes them from Base64 and writes the resulting bytes to a file at the specified location. The output file is created or overwritten.
Signature:
decodeFile( inFileName: string, outFileName: string ): void
Parameters:
-
inFileName:
stringFilename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to the encoded file.
-
outFileName:
stringFilename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to the file which should contain the decoded output.
Example:
infinity.loadModule('infinity.encoding');
infinity.base64.decodeFile('encodedData.txt', 'decodedData.txt');
decodeStream()¶
Reads the contents of the given stream, decodes them from Base64 and writes the resulting bytes to another given stream. Both streams are positioned at their beginning first: the whole input stream is decoded, and the output is written from position 0 (existing data is overwritten, but the stream is not truncated).
Signature:
decodeStream( inStream: infinity.stream, outStream: infinity.stream ): void
Parameters:
-
inStream:
infinity.streamThe stream object to decode from. See infinity.stream.
-
outStream:
infinity.streamThe stream object to write to. See infinity.stream.
Example:
infinity.loadModule('infinity.encoding');
infinity.base64.decodeStream(inStream, outStream);
encode()¶
Converts the given string to bytes using the given encoding, encodes them with Base64 and returns the results.
Signature:
encode( value: string, encoding?: infinity.encoding ): string
Parameters:
-
value:
stringThe string to encode.
-
encoding:
infinity.encoding, optionalThe encoding used to convert the string to bytes. Defaults to
infinity.encoding.utf8.
Return type: string
Example:
infinity.loadModule('infinity.encoding');
let encodedData = infinity.base64.encode(dataToEncode, infinity.encoding.utf8);
encodeFile()¶
Reads out the contents of the given file, encodes them to Base64 and writes the results to a file at the specified location. The output file is created or overwritten.
Signature:
encodeFile( inFileName: string, outFileName: string ): void
Parameters:
-
inFileName:
stringFilename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to the file which has to be encoded.
-
outFileName:
stringFilename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to the file which should contain the encoded output.
Example:
infinity.loadModule('infinity.encoding');
infinity.base64.encodeFile('dataToEncode.txt', 'encoded.txt');
encodeFile()¶
Reads out the contents of the given file, encodes them to Base64 and returns the results.
Signature:
encodeFile( fileName: string ): string
Parameters:
- fileName:
stringFilename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to the file which has to be encoded.
Return type: string
Example:
infinity.loadModule('infinity.encoding');
let encodedData = infinity.base64.encodeFile('dataToEncode.txt');
encodeStream()¶
Reads the contents of the given stream, encodes them to Base64 and writes the results to another given stream. Both streams are positioned at their beginning first: the whole input stream is encoded, and the output is written from position 0 (existing data is overwritten, but the stream is not truncated).
Signature:
encodeStream( inStream: infinity.stream, outStream: infinity.stream ): void
Parameters:
-
inStream:
infinity.streamThe stream object to encode data from. See infinity.stream.
-
outStream:
infinity.streamThe stream object to write to. See infinity.stream.
Example:
infinity.loadModule('infinity.encoding');
infinity.base64.encodeStream(inStream, outStream);