Registry / serialization / buffer-shims

buffer-shims

JSON →
library1.0.0jsnpmunverified

Buffer-shims is a JavaScript utility, currently at version 1.0.0, designed to provide polyfills for modern Node.js `Buffer` constructor methods like `Buffer.from`, `Buffer.alloc`, `Buffer.allocUnsafe`, and `Buffer.allocUnsafeSlow` in older Node.js environments and browsers. Released around 2014-2017 and last updated on npm about 7 years ago, its primary purpose was to bridge compatibility gaps before these methods became standard. The package does not patch the global `Buffer` object but exposes these methods via its own export. With modern Node.js versions and widely adopted browser standards, the need for this specific shim has largely diminished, making it mostly obsolete for new development.

npm install buffer-shims
INSTALL
IMPORT
SIG · BUFFER-SHIMS
B
buffer-shims
serializationjavascriptv1.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.

bufferShim
const bufferShim = require('buffer-shims');
This package is CommonJS-only and provides named methods on the imported object. There is no ESM export or TypeScript types available.
Buffer.from
const bufferShim = require('buffer-shims'); const buf = bufferShim.from('hello');
const buf = Buffer.from('hello');
The shim provides `from` as a property of the imported `bufferShim` object, not by patching the global `Buffer` constructor.
Buffer.alloc
const bufferShim = require('buffer-shims'); const buf = bufferShim.alloc(10);
const buf = Buffer.alloc(10);
Similar to `Buffer.from`, `alloc` is a method of the `bufferShim` object and does not directly extend the global `Buffer`.

Demonstrates how to use the `buffer-shims` module to create various types of buffers using its shims for `Buffer.from`, `alloc`, `allocUnsafe`, and `allocUnsafeSlow`.

const bufferShim = require('buffer-shims'); // Create a Buffer from a string (equivalent to Buffer.from('foo')) const buf1 = bufferShim.from('foo'); console.log('Buffer from string:', buf1.toString()); // Allocate a new Buffer of 9 bytes, filled with 'cafeface' in hex // (equivalent to Buffer.alloc(9, 'cafeface', 'hex')) const buf2 = bufferShim.alloc(9, 'cafeface', 'hex'); console.log('Allocated and filled buffer:', buf2.toString('hex')); // Allocate an uninitialized Buffer of 15 bytes (unsafe) // (equivalent to Buffer.allocUnsafe(15)) const buf3 = bufferShim.allocUnsafe(15); console.log('Unsafe allocated buffer length:', buf3.length); // Allocate an uninitialized Buffer of 21 bytes from a slower pool (unsafe slow) // (equivalent to Buffer.allocUnsafeSlow(21)) const buf4 = bufferShim.allocUnsafeSlow(21); console.log('Unsafe slow allocated buffer length:', buf4.length);
Debug
Known issues
deprecatedThe functionality provided by `buffer-shims` (Buffer.from, Buffer.alloc, etc.) is natively available in all actively supported Node.js versions and modern browser environments. Using this package is largely unnecessary and adds a dependency without clear benefit in contemporary projects.
fix
Remove `buffer-shims` and use native `Buffer.from()`, `Buffer.alloc()`, etc., directly. Ensure your target environments support these methods or use a more comprehensive polyfill if targeting extremely old, unsupported runtimes.
affects: >=1.0.0
gotchaThis package does not patch the global `Buffer` object. It exports an object containing the shimmed functions. Developers expecting `Buffer.from()` or `Buffer.alloc()` to work directly after requiring `buffer-shims` will encounter runtime errors.
fix
Always invoke the methods on the object returned by `require('buffer-shims')`, e.g., `bufferShim.from('data')`, not `Buffer.from('data')`.
affects: >=1.0.0
deprecatedThe package has not seen updates in approximately 7 years, indicating it is abandoned. It lacks maintenance for potential bugs, security vulnerabilities, or compatibility issues with future JavaScript or Node.js versions.
fix
Migrate to native Node.js `Buffer` APIs or an actively maintained, purpose-built polyfill if supporting extremely old environments is still a strict requirement. For most cases, simply remove this dependency.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Buffer.from is not a function
Attempting to use `Buffer.from()` or `Buffer.alloc()` directly on the global `Buffer` object after only requiring `buffer-shims`. This package does not modify the global `Buffer` object.
fix
Access the `from` method via the imported `bufferShim` object: `const bufferShim = require('buffer-shims'); bufferShim.from('data');`
ReferenceError: Buffer is not defined
Attempting to use `Buffer` in a browser environment without a browserify setup or a global `Buffer` polyfill, and `buffer-shims` is only imported but not properly integrated for global availability. While `buffer-shims` provides constructor methods, it doesn't create a global `Buffer` object itself.
fix
For browser environments, consider using a full `buffer` polyfill (e.g., from `buffer` npm package often bundled by tools like Browserify or Webpack) if global `Buffer` is required, or ensure your build tool handles Node.js `Buffer` APIs for browser compatibility.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
Bingbot
1
OpenAI (training)
1
Resources
buffer-shims — npm install buffer-shims · libregistry