{"library":"safer-buffer","title":"safer-buffer","description":"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.","language":"javascript","status":"maintenance","last_verified":"Sat Apr 25","install":{"commands":["npm install safer-buffer"],"cli":null},"imports":["const Buffer = require('safer-buffer').Buffer","import { Buffer } from 'safer-buffer'","Buffer.alloc(size, fill, encoding)","Buffer.from(array)"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const Buffer = require('safer-buffer').Buffer;\n\n// Safe allocation (initialized to zero)\nconst buf1 = Buffer.alloc(10);\nconsole.log(buf1); // <Buffer 00 00 00 00 00 00 00 00 00 00>\n\n// Safe creation from string\nconst buf2 = Buffer.from('hello', 'utf8');\nconsole.log(buf2.toString()); // 'hello'\n\n// Safe concatenation\nconst buf3 = Buffer.concat([buf1, buf2]);\nconsole.log(buf3.length); // 15\n\n// Note: The following would throw an error because Buffer() is not exported:\n// const buf4 = Buffer(10); // TypeError: Buffer is not a function (or similar)\n\n// To use the deprecated API (unsafe), you must explicitly require the original buffer\nconst OriginalBuffer = require('buffer').Buffer;\nconst unsafeBuf = new OriginalBuffer(10); // not recommended","lang":"javascript","description":"Demonstrates safe Buffer usage with safer-buffer: alloc, from, concat, and the prevention of the unsafe Buffer() constructor.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}