🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

buffer-from

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
b

buffer-from

A [ponyfill](https://ponyfill.com) for `Buffer.from`, uses native implementation if available.

1.1.2
latest
100

Supply Chain Security

100

Vulnerability

88

Quality

76

Maintenance

100

License

Version published
Maintainers
1
Created
Issues
3

What is buffer-from?

The buffer-from npm package is a polyfill for the `Buffer.from` method that was added in Node.js v5.10.0. It allows users to create `Buffer` objects from various types of data such as strings, arrays, or other buffers. This package is particularly useful for environments that do not support the newer `Buffer.from` API.

What are buffer-from's main functionalities?

Creating a buffer from a string

This feature allows you to create a buffer from a string. The second argument specifies the string encoding.

const bufferFrom = require('buffer-from');
const buffer = bufferFrom('hello world', 'utf8');

Creating a buffer from an array

This feature allows you to create a buffer from an array of bytes.

const bufferFrom = require('buffer-from');
const buffer = bufferFrom([0x68, 0x65, 0x6c, 0x6c, 0x6f]);

Creating a buffer from another buffer

This feature allows you to create a new buffer from an existing buffer. The new buffer will be a copy of the original.

const bufferFrom = require('buffer-from');
const buffer1 = Buffer.alloc(10).fill('a');
const buffer2 = bufferFrom(buffer1);

Other packages similar to buffer-from

FAQs

Package last updated on 29 Jul 2021

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