Registry / serialization / fast-base64-decode

fast-base64-decode

JSON →
library2.0.0jsnpmunverified

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.

npm install fast-base64-decode
INSTALL
IMPORT
SIG · FAST-BASE64-DECODE
F
fast-base64-decode
serializationjavascriptv2.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

base64Decode
import base64Decode from 'fast-base64-decode'
const base64Decode = require('fast-base64-decode')
Since v2.0.0, the package is ESM-only and must be imported using native `import` syntax. It exports a default function.

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!
Debug
Known issues
breakingPackage converted to ESM, requiring `import` syntax.
fix
Refactor `require()` statements to `import` statements. For CommonJS environments, consider using dynamic `import()` or sticking to `fast-base64-decode@1.x`.
affects: >=2.0.0
breakingDropped support for older Node.js versions.
fix
Ensure Node.js version is `^12.20.0 || ^14.13.1 || >=16.0.0` or newer.
affects: >=2.0.0
gotchaLow-level API requires pre-allocation of `Uint8Array` with correct length.
fix
You must know the exact decoded length of the Base64 string beforehand and create a `new Uint8Array(decodedLength)` to pass as the second argument. Incorrect length will lead to truncated or padded data.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to `require()` an ESM-only package.
fix
Change `const base64Decode = require('fast-base64-decode');` to `import base64Decode from 'fast-base64-decode';` and ensure your project is configured for ESM.
TypeError: base64Decode is not a function
Using a default import with a CommonJS `require` call in a mixed environment, or incorrect import syntax.
fix
If using ESM, ensure `import base64Decode from 'fast-base64-decode';`. If forced to use CommonJS for older Node or project setup, use `fast-base64-decode@1.x` or dynamic `import()`.
RangeError: Offset is outside the bounds of the DataView
Providing a `Uint8Array` buffer that is too small for the decoded Base64 data.
fix
Calculate the exact required length for the decoded Base64 string and initialize the `Uint8Array` with that size. Base64 strings are generally 4 characters for every 3 bytes, plus padding, so roughly `(string.length / 4) * 3` for estimation.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
fast-base64-decode — npm install fast-base64-decode · libregistry