Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

safer-buffer

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

safer-buffer

Modern Buffer API polyfill without footguns

  • 2.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
39M
decreased by-19.16%
Maintainers
1
Weekly downloads
 
Created

What is safer-buffer?

The safer-buffer package provides a safer alternative to the Node.js Buffer API, which has had security and usability issues, especially Buffer constructor being overloaded and not initializing memory to zero. safer-buffer provides a polyfill for the Buffer.alloc(), Buffer.allocUnsafe(), and Buffer.from() methods that were introduced in Node.js v4.5.0 and v5.10.0 as a safer API. It allows developers to write code that works with older versions of Node.js without the risk of introducing security vulnerabilities.

What are safer-buffer's main functionalities?

Creating a buffer with initialized memory

This feature allows the creation of a new Buffer with its memory initialized to zero, preventing the risk of sensitive data being leaked.

var saferBuffer = require('safer-buffer').Buffer;
var buffer = saferBuffer.alloc(10); // creates a buffer of 10 bytes with memory set to zero

Creating a buffer with uninitialized memory

This feature creates a new Buffer with uninitialized memory for better performance, but it should be used with caution as it may contain old or sensitive data.

var saferBuffer = require('safer-buffer').Buffer;
var buffer = saferBuffer.allocUnsafe(10); // creates a buffer of 10 bytes without initializing memory

Creating a buffer from an existing array

This feature allows the creation of a Buffer from an existing array of bytes or other data types.

var saferBuffer = require('safer-buffer').Buffer;
var buffer = saferBuffer.from([0x62, 0x75, 0x66]); // creates a buffer from an array of bytes

Other packages similar to safer-buffer

FAQs

Package last updated on 08 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc