{"id":16025,"library":"fast-base64-decode","title":"Fast Base64 Decode","description":"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.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/LinusU/fast-base64-decode","tags":["javascript","base64-decode","base64","decode","typescript"],"install":[{"cmd":"npm install fast-base64-decode","lang":"bash","label":"npm"},{"cmd":"yarn add fast-base64-decode","lang":"bash","label":"yarn"},{"cmd":"pnpm add fast-base64-decode","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Since v2.0.0, the package is ESM-only and must be imported using native `import` syntax. It exports a default function.","wrong":"const base64Decode = require('fast-base64-decode')","symbol":"base64Decode","correct":"import base64Decode from 'fast-base64-decode'"}],"quickstart":{"code":"import base64Decode from 'fast-base64-decode';\n\n// Example: Decoding 'SGVsbG8sIFdvcmxkIQ==' (which is 'Hello, World!')\n// The decoded length for 'SGVsbG8sIFdvcmxkIQ==' is 13 bytes.\nconst encodedString = 'SGVsbG8sIFdvcmxkIQ==';\nconst resultBuffer = new Uint8Array(13); // Pre-allocate buffer for the decoded data\n\n// Decode the string into the pre-allocated buffer\nbase64Decode(encodedString, resultBuffer);\n\n// Convert the Uint8Array to a string for display (for demonstration)\nconst decodedString = new TextDecoder().decode(resultBuffer);\n\nconsole.log(`Encoded: ${encodedString}`);\nconsole.log(`Decoded: ${decodedString}`);\n// Expected output: Decoded: Hello, World!\n","lang":"typescript","description":"Demonstrates how to import and use `base64Decode` to decode a Base64 string into a pre-allocated `Uint8Array` buffer."},"warnings":[{"fix":"Refactor `require()` statements to `import` statements. For CommonJS environments, consider using dynamic `import()` or sticking to `fast-base64-decode@1.x`.","message":"Package converted to ESM, requiring `import` syntax.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure Node.js version is `^12.20.0 || ^14.13.1 || >=16.0.0` or newer.","message":"Dropped support for older Node.js versions.","severity":"breaking","affected_versions":">=2.0.0"},{"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.","message":"Low-level API requires pre-allocation of `Uint8Array` with correct length.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Change `const base64Decode = require('fast-base64-decode');` to `import base64Decode from 'fast-base64-decode';` and ensure your project is configured for ESM.","cause":"Attempting to `require()` an ESM-only package.","error":"ERR_REQUIRE_ESM"},{"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()`.","cause":"Using a default import with a CommonJS `require` call in a mixed environment, or incorrect import syntax.","error":"TypeError: base64Decode is not a function"},{"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.","cause":"Providing a `Uint8Array` buffer that is too small for the decoded Base64 data.","error":"RangeError: Offset is outside the bounds of the DataView"}],"ecosystem":"npm"}