3.2 KiB
3.2 KiB
Buffer
Buffer constructor.
Usage
var Buffer = require( '@stdlib/buffer/ctor' );
Buffer( size )
Allocates a Buffer
having a specified number of bytes.
var b = new Buffer( 10 );
// returns <Buffer>
Buffer( array )
Allocates a Buffer
from an array of octets.
var b = new Buffer( [ 1, 2, 3, 4 ] );
// returns <Buffer>[ 1, 2, 3, 4 ]
Buffer( buffer )
Copies buffer data to a new Buffer
instance.
var b1 = new Buffer( [ 1, 2, 3, 4 ] );
var b2 = new Buffer( b1 );
// returns <Buffer>[ 1, 2, 3, 4 ]
Buffer( str[, encoding] )
Returns a Buffer
containing a provided string
.
var b = new Buffer( 'beep boop' );
// returns <Buffer>
Properties
TODO: add properties
Methods
TODO: add methods
Examples
var ctor = require( '@stdlib/buffer/ctor' );
var b;
var i;
// Allocate uninitialized memory:
if ( typeof ctor.alloc === 'function' ) {
b = ctor.alloc( 10 );
} else {
b = new ctor( 10 );
}
// Zero fill the buffer...
for ( i = 0; i < b.length; i++ ) {
b[ i ] = 0;
}
console.log( b );