Skip to main content
Skip to main content

BufferConstructor

Raw data is stored in instances of the Buffer class. A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. A Buffer cannot be resized. Valid string encodings: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'base64url'|'binary'(deprecated)|'hex'

Methods

Constructors

constructor

**new BufferConstructor**(str, encoding?)

Allocates a new buffer containing the given {str}.

Parameters

strstringRequired
String to store in buffer.
encoding to use, optional. Default is 'utf8'

Deprecated

since v10.0.0 - Use Buffer.from(string[, encoding]) instead.

**new BufferConstructor**(size)

Allocates a new buffer of {size} octets.

Parameters

sizenumberRequired
count of octets to allocate.

Deprecated

since v10.0.0 - Use Buffer.alloc() instead (also see Buffer.allocUnsafe()).

**new BufferConstructor**(array)

Allocates a new buffer containing the given {array} of octets.

Parameters

arrayUint8ArrayRequired
The octets to store.

Deprecated

since v10.0.0 - Use Buffer.from(array) instead.

**new BufferConstructor**(arrayBuffer)

Produces a Buffer backed by the same allocated memory as the given {ArrayBuffer}/{SharedArrayBuffer}.

Parameters

arrayBufferArrayBuffer | SharedArrayBufferRequired
The ArrayBuffer with which to share memory.

Deprecated

since v10.0.0 - Use Buffer.from(arrayBuffer[, byteOffset[, length]]) instead.

**new BufferConstructor**(array)

Allocates a new buffer containing the given {array} of octets.

Parameters

arrayreadonly any[]Required
The octets to store.

Deprecated

since v10.0.0 - Use Buffer.from(array) instead.

**new BufferConstructor**(buffer)

Copies the passed {buffer} data onto a new {Buffer} instance.

Parameters

bufferBufferRequired
The buffer to copy.

Deprecated

since v10.0.0 - Use Buffer.from(buffer) instead.

Properties

poolSizenumberRequired
This is the size (in bytes) of pre-allocated internal Buffer instances used for pooling. This value may be modified.
Was this section helpful?