Socket
Socket
Sign inDemoInstall

buffer-alloc

Package Overview
Dependencies
2
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

buffer-alloc

A [ponyfill](https://ponyfill.com) for `Buffer.alloc`.


Version published
Maintainers
1
Weekly downloads
4,303,447
decreased by-7.81%

Weekly downloads

Package description

What is buffer-alloc?

The buffer-alloc package is a utility for allocating buffer memory in Node.js. It provides a way to create a buffer of a specified size filled with zeros or another specified value. This is particularly useful in scenarios where you need to ensure that newly allocated memory does not contain old or sensitive data. It mimics the Buffer.alloc method introduced in Node.js v5.10.0, offering a polyfill for older versions of Node.js or an alternative method for newer versions.

What are buffer-alloc's main functionalities?

Allocating a buffer filled with zeros

This feature allows for the creation of a new buffer of a specified size, with each byte initialized to zero. It's useful for when you need a clean buffer with no pre-existing data.

const bufferAlloc = require('buffer-alloc');
const buffer = bufferAlloc(10); // creates a 10-byte buffer filled with zeros

Allocating a buffer filled with a specific value

This feature enables the creation of a buffer where each byte is initialized to a specific value provided by the user. This can be useful for initializing a buffer to a non-zero state for specific use cases.

const bufferAlloc = require('buffer-alloc');
const buffer = bufferAlloc(10, 0x1); // creates a 10-byte buffer filled with 0x1

Other packages similar to buffer-alloc

Readme

Source

Buffer Alloc

A ponyfill for Buffer.alloc.

Works as Node.js: v7.0.0
Works on Node.js: v0.10.0

Installation

npm install --save buffer-alloc

Usage

const alloc = require('buffer-alloc')

console.log(alloc(4))
//=> <Buffer 00 00 00 00>

console.log(alloc(6, 0x41))
//=> <Buffer 41 41 41 41 41 41>

console.log(alloc(10, 'linus', 'utf8'))
//=> <Buffer 6c 69 6e 75 73 6c 69 6e 75 73>

API

alloc(size[, fill[, encoding]])

  • size <Integer> The desired length of the new Buffer
  • fill <String> | <Buffer> | <Integer> A value to pre-fill the new Buffer with. Default: 0
  • encoding <String> If fill is a string, this is its encoding. Default: 'utf8'

Allocates a new Buffer of size bytes. If fill is undefined, the Buffer will be zero-filled.

See also

Keywords

FAQs

Last updated on 29 May 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc