Fast Base64 Decode

2.0.0 · active · verified Tue Apr 21

fast-base64-decode is a JavaScript library providing a high-performance, low-level Base64 decoder. Its current stable version is 2.0.0, released in October 2022. The library differentiates itself by offering a direct, byte-array-oriented API, requiring the user to pre-allocate `Uint8Array` buffers and specify the exact output length. This approach is optimized for speed and memory efficiency, contrasting with higher-level alternatives like `base64-js` which handle buffer allocation automatically. It is primarily used for decoding Base64 strings where performance is critical and granular control over the output buffer is desired. The package has a moderate release cadence, with major versions aligning with significant architectural shifts like its recent conversion to an ECMAScript module.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use `base64Decode` to decode a Base64 string into a pre-allocated `Uint8Array` buffer.

import base64Decode from 'fast-base64-decode';

// Example: Decoding 'SGVsbG8sIFdvcmxkIQ==' (which is 'Hello, World!')
// The decoded length for 'SGVsbG8sIFdvcmxkIQ==' is 13 bytes.
const encodedString = 'SGVsbG8sIFdvcmxkIQ==';
const resultBuffer = new Uint8Array(13); // Pre-allocate buffer for the decoded data

// Decode the string into the pre-allocated buffer
base64Decode(encodedString, resultBuffer);

// Convert the Uint8Array to a string for display (for demonstration)
const decodedString = new TextDecoder().decode(resultBuffer);

console.log(`Encoded: ${encodedString}`);
console.log(`Decoded: ${decodedString}`);
// Expected output: Decoded: Hello, World!

view raw JSON →