base64-encoding
Version:
Fast Base64 encoding and decoding powered by WebAssembly.
28 lines (27 loc) • 1.15 kB
TypeScript
/**
* Slightly modernized version of [`base64-js`][1].
* Performance is slightly improved due to pre-allocating arrays.
*
* This version drops support for platforms that don't provide
* `Uint8Array` and `DataView`. Use the original in those cases.
*
* [1]: https://github.com/beatgammit/base64-js
* [2]: https://tools.ietf.org/html/rfc3986#section-2.3
*/
/**
* Takes a base 64 string and converts it to an array buffer.
* Accepts both regular Base64 and the URL-friendly variant,
* where `+` => `-`, `/` => `_`, and the padding character is omitted.
*
* @param str A Base64 string in either regular or URL-friendly representation.
* @returns The binary data as `Uint8Array`.
*/
export declare function toByteArray(str: string): Uint8Array;
/**
* Encodes binary data provided in an array buffer as a Base64 string.
* @param bufferSource The raw data to encode.
* @param urlFriendly Set to true to encode in a URL-friendly way.
* @returns The contents a Base64 string.
*/
export declare function fromByteArray(bufferSource: BufferSource, urlFriendly?: boolean): string;
export { fromByteArray as encode, toByteArray as decode, };