buffer

D._unsafe. Namespace

buffer

Description:
  • The buffer library is a global type for dealing with binary data directly. It can be constructed in a variety of ways. Buffer objects are used to represent a fixed-length sequence of bytes.

    The Buffer class is a subclass of JavaScript's Uint8Array class and extends it with methods that cover additional use cases. The API accepts plain Uint8Arrays wherever Buffers are supported as well.

    https://nodejs.org/docs/latest-v14.x/api/buffer.html

Methods

(static) alloc(length, fillopt, encodingopt) → {Buffer}

Description:
  • Allocates a new buffer of size bytes. If fill is undefined, the Buffer will be zero-filled. A TypeError will be thrown if size is not a number. If size is larger than buffer.constants.MAX_LENGTH or smaller than 0, ERR_INVALID_OPT_VALUE is thrown.
See:
Example
D._unsafe.buffer.alloc(8,'1') - returns '11111111'
Parameters:
Name Type Attributes Default Description
length integer The desired length of the new Buffer.
fill string | Buffer | Unit8Array | integer <optional>
0 A value to pre-fill the new Buffer with.
encoding string <optional>
utf8 If fill is a string, this is its encoding.
Returns:
Type
Buffer

(static) concat(data, length) → {Buffer}

Description:
  • Returns a new Buffer which is the result of concatenating all the Buffer instances in the list together. If the list has no items, or if the length is 0, then a new zero-length Buffer is returned. If length is not provided, it is calculated from the Buffer instances in list by adding their lengths. If length is provided, it is coerced to an unsigned integer. If the combined length of the Buffers in data list exceeds length, the result is truncated to length.
See:
Parameters:
Name Type Description
data Array.<Buffer> | Array.<Unit8Array> List of Buffer or Uint8Array instances to concatenate.
length integer Total length of the Buffer instances in list when concatenated.
Returns:
Type
Buffer

(static) from(data, offsetOrEncodingopt, lengthopt) → {Buffer}

Description:
  • Allocates a new Buffer using multiple types of input data (array, arrayBuffer, buffer, object, string)
See:
Parameters:
Name Type Attributes Default Description
data Array.<integer> | ArrayBuffer | SharedArrayBuffer | Unit8array | Buffer | string
offsetOrEncoding integer | string <optional>
0 | utf8 Index of first byte to expose or encoding of string
length integer <optional>
Number of bytes to expose.
Returns:
Type
Buffer