Node.js Buffer Module
Buffer
Buffer objects are used to represent a fixed-length sequence of bytes.
Many Node.js APIs support Buffers.
Buffer objects are used to represent a fixed-length sequence of bytes.
Many Node.js APIs support Buffers.
When converting between Buffers and strings, a character encoding may be specified.
If no character encoding is specified, UTF-8 will be used as the default.
Buffer instances are also JavaScript Uint8Array and TypedArray instances.
All TypedArray methods are available on Buffers.
There are, however, subtle incompatibilities between the Buffer API and the TypedArray API.
Buffer instances can be iterated over using for..of syntax.
Additionally, the buf.values(), buf.keys(), and buf.entries() methods can be used to create iterators.
size <integer> The desired length of the new Buffer.
fill <string> | <Buffer> | <Uint8Array> | <integer> A value to pre-fill the new Buffer with. Default: 0.
size <integer> The desired length of the new Buffer.
Returns: <Buffer>
size <integer> The desired length of the new Buffer.
Returns: <Buffer>
string <string> | <Buffer> | <TypedArray> | <DataView> | <ArrayBuffer> | <SharedArrayBuffer> A value to calculate the length of.
buf1 <Buffer> | <Uint8Array>
buf2 <Buffer> | <Uint8Array>
list <Buffer[]> | <Uint8Array[]> List of Buffer or Uint8Array instances to concatenate.
totalLength <integer> Total length of the Buffer instances in list when concatenated.
view <TypedArray> The <TypedArray> to copy.
offset <integer> The starting offset within view. Default:: 0.
array <integer[]>
Returns: <Buffer>
arrayBuffer <ArrayBuffer> | <SharedArrayBuffer> An ArrayBuffer, SharedArrayBuffer, for example the .buffer property of a TypedArray.
buffer <Buffer> | <Uint8Array> An existing Buffer or Uint8Array from which to copy data.
Returns: <Buffer>
object <Object> An object supporting Symbol.toPrimitive or valueOf().
offsetOrEncoding <integer> | <string> A byte-offset or encoding.
string <string> A string to encode.
encoding <string> The encoding of string. Default: 'utf8'.
Returns: <Buffer>
obj <Object>
Returns: <boolean>
Returns true if obj is a Buffer, false otherwise.
encoding <string> A character encoding name to check.
Returns: <boolean>
<integer> Default: 8192
This is the size (in bytes) of pre-allocated internal Buffer instances used for pooling. This value may be modified.
index <integer>
The index operator [index] can be used to get and set the octet at position index in buf. The values refer to individual bytes, so the legal value range is between 0x00 and 0xFF (hex) or 0 and 255 (decimal).
<ArrayBuffer> The underlying ArrayBuffer object based on which this Buffer object is created.
<integer> The byteOffset of the Buffers underlying ArrayBuffer object.
target <Buffer> | <Uint8Array> A Buffer or Uint8Array with which to compare buf.
targetStart <integer> The offset within target at which to begin comparison. Default: 0.
target <Buffer> | <Uint8Array> A Buffer or Uint8Array to copy into.
targetStart <integer> The offset within target at which to begin writing. Default: 0.
Returns: <Iterator>
Creates and returns an iterator of [index, byte] pairs from the contents of buf.
otherBuffer <Buffer> | <Uint8Array> A Buffer or Uint8Array with which to compare buf.
Returns: <boolean>
value <string> | <Buffer> | <Uint8Array> | <integer> The value with which to fill buf. Empty value (string, Uint8Array, Buffer) is coerced to 0.
offset <integer> Number of bytes to skip before starting to fill buf. Default: 0.
value <string> | <Buffer> | <Uint8Array> | <integer> What to search for.
byteOffset <integer> Where to begin searching in buf. If negative, then offset is calculated from the end of buf. Default: 0.
value <string> | <Buffer> | <Uint8Array> | <integer> What to search for.
byteOffset <integer> Where to begin searching in buf. If negative, then offset is calculated from the end of buf. Default: 0.
Returns: <Iterator>
Creates and returns an iterator of buf keys (indexes).
value <string> | <Buffer> | <Uint8Array> | <integer> What to search for.
byteOffset <integer> Where to begin searching in buf. If negative, then offset is calculated from the end of buf. Default: buf.length - 1.
<integer>
Returns the number of bytes in buf.
offset <integer> Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 8. Default: 0.
Returns: <bigint>
offset <integer> Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 8. Default: 0.
Returns: <bigint>
offset <integer> Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 8. Default: 0.
Returns: <bigint>
offset <integer> Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 8. Default: 0.
Returns: <bigint>
offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 8. Default: 0.
Returns: <number>
Reads a 64-bit, big-endian double from buf at the specified offset.
offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 8. Default: 0.
Returns: <number>
offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.
Returns: <number>
Reads a 32-bit, big-endian float from buf at the specified offset.
offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.
Returns: <number>
Reads a 32-bit, little-endian float from buf at the specified offset.
offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 1. Default: 0.
Returns: <integer>
Reads a signed 8-bit integer from buf at the specified offset.
offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 2. Default: 0.
Returns: <integer>
Reads a signed, big-endian 16-bit integer from buf at the specified offset.
offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 2. Default: 0.
Returns: <integer>
Reads a signed, little-endian 16-bit integer from buf at the specified offset.
offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.
Returns: <integer>
Reads a signed, big-endian 32-bit integer from buf at the specified offset.
offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.
Returns: <integer>
Reads a signed, little-endian 32-bit integer from buf at the specified offset.
offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - byteLength.
byteLength <integer> Number of bytes to read. Must satisfy 0 < byteLength <= 6.
Returns: <integer>
offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - byteLength.
byteLength <integer> Number of bytes to read. Must satisfy 0 < byteLength <= 6.
Returns: <integer>
offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 1. Default: 0.
Returns: <integer>
Reads an unsigned 8-bit integer from buf at the specified offset.
offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 2. Default: 0.
Returns: <integer>
Reads an unsigned, big-endian 16-bit integer from buf at the specified offset.
offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 2. Default: 0.
Returns: <integer>
Reads an unsigned, little-endian 16-bit integer from buf at the specified offset.
offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.
Returns: <integer>
Reads an unsigned, big-endian 32-bit integer from buf at the specified offset.
offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.
Returns: <integer>
Reads an unsigned, little-endian 32-bit integer from buf at the specified offset.
offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - byteLength.
byteLength <integer> Number of bytes to read. Must satisfy 0 < byteLength <= 6.
Returns: <integer>
offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - byteLength.
byteLength <integer> Number of bytes to read. Must satisfy 0 < byteLength <= 6.
Returns: <integer>
start <integer> Where the new Buffer will start. Default: 0.
end <integer> Where the new Buffer will end (not inclusive). Default: buf.length.
Returns: <Buffer>
Returns: <Buffer> A reference to buf.
Interprets buf as an array of unsigned 16-bit integers and swaps the byte order in-place.
Throws ERR_INVALID_BUFFER_SIZE if buf.length is not a multiple of 2.
Returns: <Buffer> A reference to buf.
Interprets buf as an array of unsigned 32-bit integers and swaps the byte order in-place.
Throws ERR_INVALID_BUFFER_SIZE if buf.length is not a multiple of 4.
Returns: <Buffer> A reference to buf.
Interprets buf as an array of 64-bit numbers and swaps byte order in-place.
Throws ERR_INVALID_BUFFER_SIZE if buf.length is not a multiple of 8.
Returns: <Object>
Returns a JSON representation of buf. JSON.stringify() implicitly calls this function when stringifying a Buffer instance.
encoding <string> The character encoding to use. Default: 'utf8'.
start <integer> The byte offset to start decoding at. Default: 0.
end <integer> The byte offset to stop decoding at (not inclusive). Default: buf.length.
Returns: <Iterator>
Creates and returns an iterator for buf values (bytes). This function is called automatically when a Buffer is used in a for..of statement.
string <string> String to write to buf.
offset <integer> Number of bytes to skip before starting to write string. Default: 0.
length <integer> Maximum number of bytes to write (written bytes will not exceed buf.length - offset). Default: buf.length - offset.
value <bigint> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 8. Default: 0.
Returns: <integer> offset plus the number of bytes written.
value <bigint> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 8. Default: 0.
Returns: <integer> offset plus the number of bytes written.
value <bigint> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 8. Default: 0.
Returns: <integer> offset plus the number of bytes written.
value <bigint> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 8. Default: 0.
Returns: <integer> offset plus the number of bytes written.
value <number> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 8. Default: 0.
Returns: <integer> offset plus the number of bytes written.
value <number> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 8. Default: 0.
Returns: <integer> offset plus the number of bytes written.
value <number> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.
Returns: <integer> offset plus the number of bytes written.
value <number> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.
Returns: <integer> offset plus the number of bytes written.
value <integer> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 1. Default: 0.
Returns: <integer> offset plus the number of bytes written.
value <integer> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 2. Default: 0.
Returns: <integer> offset plus the number of bytes written.
value <integer> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 2. Default: 0.
Returns: <integer> offset plus the number of bytes written.
value <integer> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.
Returns: <integer> offset plus the number of bytes written.
value <integer> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.
Returns: <integer> offset plus the number of bytes written.
value <integer> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - byteLength.
byteLength <integer> Number of bytes to write. Must satisfy 0 < byteLength <= 6.
value <integer> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - byteLength.
byteLength <integer> Number of bytes to write. Must satisfy 0 < byteLength <= 6.
value <integer> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 1. Default: 0.
Returns: <integer> offset plus the number of bytes written.
value <integer> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 2. Default: 0.
Returns: <integer> offset plus the number of bytes written.
value <integer> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 2. Default: 0.
Returns: <integer> offset plus the number of bytes written.
value <integer> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.
Returns: <integer> offset plus the number of bytes written.
value <integer> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.
Returns: <integer> offset plus the number of bytes written.
value <integer> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - byteLength.
byteLength <integer> Number of bytes to write. Must satisfy 0 < byteLength <= 6.
value <integer> Number to be written to buf.
offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - byteLength.
byteLength <integer> Number of bytes to write. Must satisfy 0 < byteLength <= 6.
buffer.constants.MAX_LENGTH
<integer> The largest size allowed for a single Buffer instance.