base64-encoding
Version:
Fast Base64 encoding and decoding powered by WebAssembly.
67 lines (66 loc) • 2.06 kB
TypeScript
export interface Base64EncoderOptions {
/**
* Whether this encoder is set to encode data as URL-friendly Base64.
*
* URL-friendly here means that `+` maps to `-`, `/` maps to `_`, and
* the padding characters `=` are is omitted,
* while the rest of the alphabet is shared.
*/
url?: boolean;
/** @deprecated Use `url` instead. */
urlFriendly?: boolean;
}
/**
* Base64 encoder class to encode binary data in Base64 strings,
* similar to `TextEncoder`.
*/
export declare class Base64Encoder {
#private;
/**
* Whether this encoder is set to encode data as URL-friendly Base64.
*/
get url(): boolean;
/**
* @deprecated Use `url` instead.
*/
get urlFriendly(): boolean;
/**
* Creates a new encoder object with underlying WebAssembly instance.
*
* Note that the WASM instance might grow its internal memory to fit large
* array buffers.
*/
constructor(options?: Base64EncoderOptions);
/**
* Optimize this encoder to use the faster WASM implementation.
* @returns This encoder after WASM initialization has completed.
*/
optimize(): Promise<this>;
/**
* Encodes an array buffer into a Base64 string.
*
* @param input Binary data to be Base64 encoded
* @returns The provided array buffer encoded as a Base64 string
*/
encode(input: BufferSource): string;
}
/**
* Base64 Decoder class to convert Base64 strings into array buffers,
* similar to `TextDecoder`.
*/
export declare class Base64Decoder {
#private;
/**
* Optimize this decoder to use the faster WASM implementation.
* @returns This decoder after WASM initialization has completed.
*/
optimize(): Promise<this>;
/**
* Decodes a Base64 string and returns a new array buffer.
*
* @param input A Base64 string. Can be either URL friendly or not and
* padding may be omitted.
* @returns The binary data as an array buffer.
*/
decode(input: string): Uint8Array;
}