time-to-botec/js/node_modules/@stdlib/buffer/from-array
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00
..
docs feat: add the node modules 2022-12-03 12:44:49 +00:00
lib feat: add the node modules 2022-12-03 12:44:49 +00:00
package.json feat: add the node modules 2022-12-03 12:44:49 +00:00
README.md feat: add the node modules 2022-12-03 12:44:49 +00:00

array2buffer

Allocate a buffer using an octet array.

Usage

var array2buffer = require( '@stdlib/buffer/from-array' );

array2buffer( arr )

Allocates a buffer using an array (or array-like object) of octets.

var buf = array2buffer( [ 1, 2, 3, 4 ] );
// returns <Buffer>[ 1, 2, 3, 4 ]

Examples

var array2buffer = require( '@stdlib/buffer/from-array' );

var octets;
var buf;
var str;
var i;

// Define a string we want to convert to a buffer:
str = 'this is a string.';

// Manually convert the string to an array of octets...
octets = new Array( str.length );
for ( i = 0; i < str.length; i++ ) {
    octets[ i ] = str.charCodeAt( i ) % 256;
}

// Create a buffer from the octet array:
buf = array2buffer( octets );
console.log( buf.toString() );