Registry / serialization / buffer-es6

buffer-es6

JSON →
library4.9.3jsnpmunverified

buffer-es6 provides a robust and performant implementation of the Node.js Buffer API, specifically re-engineered using ES6 syntax for browser environments. It is optimized for bundlers like Rollup, enabling better tree-shaking compared to its predecessor. The current stable version is 4.9.3. While no explicit release cadence is provided, the package appears actively maintained as a specialized fork of the main `buffer` package. Its key differentiators include identical API compatibility with Node.js Buffer, broad browser support (down to IE6), and a remarkably small bundle size (5.04KB minified + gzipped). It internally bundles `ieee754` and `base64-js`, providing a self-contained solution for binary data manipulation in the browser.

npm install buffer-es6
INSTALL
IMPORT
SIG · BUFFER-ES6
B
buffer-es6
serializationjavascriptv4.9.3
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

Buffer
✓ import { Buffer } from 'buffer-es6';
✗ import Buffer from 'buffer-es6';
For ES Modules, `Buffer` is a named export. Attempting a default import will result in a TypeError.
Buffer
✓ const Buffer = require('buffer-es6');
✗ const { Buffer } = require('buffer-es6');
For CommonJS, the module directly exports the `Buffer` constructor. Destructuring `require('buffer-es6')` is incorrect.
Buffer (alternative core Buffer package import)
✓ const Buffer = require('buffer/').Buffer;
✗ import { Buffer } from 'buffer';
This specific import path (`require('buffer/')`) is for the *main* `buffer` npm package, not `buffer-es6`. It is critical to distinguish between `buffer-es6` and the core `buffer` package, as they have different installation and import conventions. Confusion between the two is a common pitfall.

Demonstrates various fundamental Buffer operations including creation, writing, reading, concatenation, and type checking, using ES module syntax.

import { Buffer } from 'buffer-es6'; // Create a new Buffer of 10 bytes and fill it with zeros const buf1 = Buffer.alloc(10); console.log('Buffer 1 (alloc):', buf1.toString('hex')); // Create a Buffer from a string, using UTF-8 encoding const buf2 = Buffer.from('Hello Buffer!', 'utf8'); console.log('Buffer 2 (from string):', buf2.toString()); // Write data to an existing buffer buf1.write('ABC', 0, 3, 'utf8'); console.log('Buffer 1 after write:', buf1.toString('utf8')); // Concatenate two buffers const buf3 = Buffer.concat([buf1, buf2]); console.log('Buffer 3 (concat):', buf3.toString('utf8')); // Check buffer length console.log('Buffer 3 length:', buf3.length); // Access individual bytes console.log('Byte at index 1 of buf2:', buf2[1]); // Prints 'e' ASCII value // Convert to JSON const json = buf2.toJSON(); console.log('Buffer 2 as JSON:', json); // Create a Buffer from a JavaScript ArrayBuffer const arrayBuffer = new ArrayBuffer(5); const uint8Array = new Uint8Array(arrayBuffer); uint8Array[0] = 72; // 'H' uint8Array[1] = 105; // 'i' const buf4 = Buffer.from(arrayBuffer); console.log('Buffer 4 (from ArrayBuffer):', buf4.toString()); // Check if a variable is a Buffer console.log('Is buf1 a Buffer?', Buffer.isBuffer(buf1)); console.log('Is "Hello" a Buffer?', Buffer.isBuffer('Hello'));
Debug
Known issues
breakingIn older browsers lacking Typed Array support (e.g., IE6-9), `buf.slice()` returns a new Buffer that does NOT share underlying memory with the original. Modifications to one will not affect the other, unlike Node.js behavior and modern browser implementations.
fix
For critical applications in very old browser environments, avoid relying on shared memory behavior of `slice()` or implement custom copying logic. This typically does not affect modern browsers.
affects: <=4.9.3
gotchaThe `buffer-es6` package is a distinct npm package from the more commonly known `buffer` package. They have different installation commands (`npm install buffer-es6` vs `npm install buffer`) and different primary import paths. Confusing the two can lead to module not found errors or unexpected behavior.
fix
Always ensure you install `buffer-es6` if that is the intended package, and use `import { Buffer } from 'buffer-es6'` (ESM) or `const Buffer = require('buffer-es6')` (CJS) for correct imports.
affects: >=1.0.0
gotcha`buffer-es6` explicitly disables certain Node.js compatibility features present in the core `buffer` package. This was done to facilitate Rollup tree-shaking. While generally beneficial for bundle size, it might remove specific behaviors or polyfills expected in highly specialized or legacy contexts.
fix
Review the specific 'compatibility stuff' turned off by inspecting the `buffer-es6` source or consulting its documentation if you encounter unexpected behavior related to Buffer operations, especially when migrating from the standard `buffer` package.
affects: >=1.0.0
gotchaThe bundled `base64-js` dependency, as mentioned in the README, has an 'MIT with no author listed' license attribution. While MIT is permissive, the lack of an author might be a concern for projects with strict license compliance requirements.
fix
If this is a legal concern, review the license information of `base64-js` within the `buffer-es6` package or consult legal counsel. Alternatively, consider using a different Buffer implementation if this specific licensing detail is problematic.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Buffer is not a constructor
Attempting to use `Buffer` as a constructor or class when it was imported incorrectly, often via a default import instead of a named export (ESM) or by destructuring `require('buffer-es6')` (CJS).
fix
For ESM, use `import { Buffer } from 'buffer-es6';`. For CJS, use `const Buffer = require('buffer-es6');`.
Cannot find module 'buffer-es6'
The `buffer-es6` package has not been installed, or the import path is incorrect.
fix
Run `npm install buffer-es6` or `yarn add buffer-es6`. Ensure the import path is exactly `'buffer-es6'` for both ESM and CJS.
Cannot find module 'buffer'
Attempting to import the core `buffer` module or the `buffer` npm package when `buffer-es6` is installed and the environment expects the specific `buffer-es6` module. This often happens due to confusion between the two packages.
fix
If intending to use `buffer-es6`, ensure all your import paths reference `'buffer-es6'`. If you truly need the main `buffer` npm package (which provides Node.js core-like Buffer behavior), install it with `npm install buffer` and adjust imports accordingly (e.g., `require('buffer/').Buffer` for CJS).
Upgrade
Version history
4.9.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
buffer-es6 — npm install buffer-es6 · libregistry