A polyfill for the modern Buffer API (Buffer.alloc, Buffer.from, Buffer.allocUnsafe, Buffer.allocUnsafeSlow) that works on Node.js from 0.8 to current, but unlike safe-buffer it does not silently allow the deprecated Buffer() constructor. Latest version: 2.1.2. This package is a drop-in replacement that forces the use of the safe API by exporting only the safe Buffer methods, eliminating the security footgun of uninitialized memory allocation. It is intended as a temporary measure for projects that must support older Node.js versions. For modern Node.js (>=4.5.0 and >=5.9.0), direct use of the built-in Buffer.alloc and Buffer.from is recommended.
npm install safer-bufferVerified import paths — ran on the pinned version, not inferred.
Demonstrates safe Buffer usage with safer-buffer: alloc, from, concat, and the prevention of the unsafe Buffer() constructor.
Replace all Buffer() and new Buffer() calls with Buffer.alloc() or Buffer.from() accordingly.
Remove the require/import of safer-buffer and use the global Buffer (which already has .alloc and .from) if your minimum Node version is 4.5+ or 5.9+.
Use import { Buffer } from 'safer-buffer'; do not use import SaferBuffer from 'safer-buffer'.Always assign the result of require('safer-buffer').Buffer to a local variable named Buffer in each module that needs it.Replace const Buffer = require('safe-buffer').Buffer with const Buffer = require('safer-buffer').Buffer.Use Buffer.alloc() or Buffer.from() instead of Buffer().
Add const Buffer = require('safer-buffer').Buffer at the top of the file.Use require('safer-buffer').Buffer instead of require('safer-buffer').No dependency data recorded yet.