{"id":12918,"library":"buffer-shims","title":"Buffer Shims","description":"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.","status":"abandoned","version":"1.0.0","language":"javascript","source_language":"en","source_url":"git@github.com:calvinmetcalf/buffer-shims","tags":["javascript"],"install":[{"cmd":"npm install buffer-shims","lang":"bash","label":"npm"},{"cmd":"yarn add buffer-shims","lang":"bash","label":"yarn"},{"cmd":"pnpm add buffer-shims","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only and provides named methods on the imported object. There is no ESM export or TypeScript types available.","symbol":"bufferShim","correct":"const bufferShim = require('buffer-shims');"},{"note":"The shim provides `from` as a property of the imported `bufferShim` object, not by patching the global `Buffer` constructor.","wrong":"const buf = Buffer.from('hello');","symbol":"Buffer.from","correct":"const bufferShim = require('buffer-shims');\nconst buf = bufferShim.from('hello');"},{"note":"Similar to `Buffer.from`, `alloc` is a method of the `bufferShim` object and does not directly extend the global `Buffer`.","wrong":"const buf = Buffer.alloc(10);","symbol":"Buffer.alloc","correct":"const bufferShim = require('buffer-shims');\nconst buf = bufferShim.alloc(10);"}],"quickstart":{"code":"const bufferShim = require('buffer-shims');\n\n// Create a Buffer from a string (equivalent to Buffer.from('foo'))\nconst buf1 = bufferShim.from('foo');\nconsole.log('Buffer from string:', buf1.toString());\n\n// Allocate a new Buffer of 9 bytes, filled with 'cafeface' in hex\n// (equivalent to Buffer.alloc(9, 'cafeface', 'hex'))\nconst buf2 = bufferShim.alloc(9, 'cafeface', 'hex');\nconsole.log('Allocated and filled buffer:', buf2.toString('hex'));\n\n// Allocate an uninitialized Buffer of 15 bytes (unsafe)\n// (equivalent to Buffer.allocUnsafe(15))\nconst buf3 = bufferShim.allocUnsafe(15);\nconsole.log('Unsafe allocated buffer length:', buf3.length);\n\n// Allocate an uninitialized Buffer of 21 bytes from a slower pool (unsafe slow)\n// (equivalent to Buffer.allocUnsafeSlow(21))\nconst buf4 = bufferShim.allocUnsafeSlow(21);\nconsole.log('Unsafe slow allocated buffer length:', buf4.length);","lang":"javascript","description":"Demonstrates how to use the `buffer-shims` module to create various types of buffers using its shims for `Buffer.from`, `alloc`, `allocUnsafe`, and `allocUnsafeSlow`."},"warnings":[{"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.","message":"The 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.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Always invoke the methods on the object returned by `require('buffer-shims')`, e.g., `bufferShim.from('data')`, not `Buffer.from('data')`.","message":"This 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The 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.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Access the `from` method via the imported `bufferShim` object: `const bufferShim = require('buffer-shims'); bufferShim.from('data');`","cause":"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.","error":"TypeError: Buffer.from is not a function"},{"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.","cause":"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.","error":"ReferenceError: Buffer is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}