{ "type": "module", "source": "doc/api/buffer.md", "modules": [ { "textRaw": "Buffer", "name": "buffer", "introduced_in": "v0.1.90", "stability": 2, "stabilityText": "Stable", "desc": "

Prior to the introduction of TypedArray, the JavaScript language had no\nmechanism for reading or manipulating streams of binary data. The Buffer class\nwas introduced as part of the Node.js API to enable interaction with octet\nstreams in TCP streams, file system operations, and other contexts.

\n

With TypedArray now available, the Buffer class implements the\nUint8Array API in a manner that is more optimized and suitable for\nNode.js.

\n

Instances of the Buffer class are similar to arrays of integers from 0 to\n255 (other integers are coerced to this range by & 255 operation) but\ncorrespond to fixed-sized, raw memory allocations outside the V8 heap.\nThe size of the Buffer is established when it is created and cannot be\nchanged.

\n

The Buffer class is within the global scope, making it unlikely that one\nwould need to ever use require('buffer').Buffer.

\n
// Creates a zero-filled Buffer of length 10.\nconst buf1 = Buffer.alloc(10);\n\n// Creates a Buffer of length 10, filled with 0x1.\nconst buf2 = Buffer.alloc(10, 1);\n\n// Creates an uninitialized buffer of length 10.\n// This is faster than calling Buffer.alloc() but the returned\n// Buffer instance might contain old data that needs to be\n// overwritten using either fill() or write().\nconst buf3 = Buffer.allocUnsafe(10);\n\n// Creates a Buffer containing [0x1, 0x2, 0x3].\nconst buf4 = Buffer.from([1, 2, 3]);\n\n// Creates a Buffer containing UTF-8 bytes [0x74, 0xc3, 0xa9, 0x73, 0x74].\nconst buf5 = Buffer.from('tést');\n\n// Creates a Buffer containing Latin-1 bytes [0x74, 0xe9, 0x73, 0x74].\nconst buf6 = Buffer.from('tést', 'latin1');\n
", "modules": [ { "textRaw": "`Buffer.from()`, `Buffer.alloc()`, and `Buffer.allocUnsafe()`", "name": "`buffer.from()`,_`buffer.alloc()`,_and_`buffer.allocunsafe()`", "desc": "

In versions of Node.js prior to 6.0.0, Buffer instances were created using the\nBuffer constructor function, which allocates the returned Buffer\ndifferently based on what arguments are provided:

\n\n

Because the behavior of new Buffer() is different depending on the type of the\nfirst argument, security and reliability issues can be inadvertently introduced\ninto applications when argument validation or Buffer initialization is not\nperformed.

\n

For example, if an attacker can cause an application to receive a number where\na string is expected, the application may call new Buffer(100)\ninstead of new Buffer(\"100\"), it will allocate a 100 byte buffer instead\nof allocating a 3 byte buffer with content \"100\". This is commonly possible\nusing JSON API calls. Since JSON distinguishes between numeric and string types,\nit allows injection of numbers where a naive application might expect to always\nreceive a string. Before Node.js 8.0.0, the 100 byte buffer might contain\narbitrary pre-existing in-memory data, so may be used to expose in-memory\nsecrets to a remote attacker. Since Node.js 8.0.0, exposure of memory cannot\noccur because the data is zero-filled. However, other attacks are still\npossible, such as causing very large buffers to be allocated by the server,\nleading to performance degradation or crashing on memory exhaustion.

\n

To make the creation of Buffer instances more reliable and less error-prone,\nthe various forms of the new Buffer() constructor have been deprecated\nand replaced by separate Buffer.from(), Buffer.alloc(), and\nBuffer.allocUnsafe() methods.

\n

Developers should migrate all existing uses of the new Buffer() constructors\nto one of these new APIs.

\n\n

Buffer instances returned by Buffer.allocUnsafe() may be allocated off\na shared internal memory pool if size is less than or equal to half\nBuffer.poolSize. Instances returned by Buffer.allocUnsafeSlow()\nnever use the shared internal memory pool.

", "modules": [ { "textRaw": "The `--zero-fill-buffers` command line option", "name": "the_`--zero-fill-buffers`_command_line_option", "meta": { "added": [ "v5.10.0" ], "changes": [] }, "desc": "

Node.js can be started using the --zero-fill-buffers command line option to\ncause all newly allocated Buffer instances to be zero-filled upon creation by\ndefault. Before Node.js 8.0.0, this included buffers allocated by new Buffer(size). Since Node.js 8.0.0, buffers allocated with new are always\nzero-filled, whether this option is used or not.\nBuffer.allocUnsafe(), Buffer.allocUnsafeSlow(), and new SlowBuffer(size). Use of this flag can have a significant negative impact on\nperformance. Use of the --zero-fill-buffers option is recommended only when\nnecessary to enforce that newly allocated Buffer instances cannot contain old\ndata that is potentially sensitive.

\n
$ node --zero-fill-buffers\n> Buffer.allocUnsafe(5);\n<Buffer 00 00 00 00 00>\n
", "type": "module", "displayName": "The `--zero-fill-buffers` command line option" }, { "textRaw": "What makes `Buffer.allocUnsafe()` and `Buffer.allocUnsafeSlow()` \"unsafe\"?", "name": "what_makes_`buffer.allocunsafe()`_and_`buffer.allocunsafeslow()`_\"unsafe\"?", "desc": "

When calling Buffer.allocUnsafe() and Buffer.allocUnsafeSlow(), the\nsegment of allocated memory is uninitialized (it is not zeroed-out). While\nthis design makes the allocation of memory quite fast, the allocated segment of\nmemory might contain old data that is potentially sensitive. Using a Buffer\ncreated by Buffer.allocUnsafe() without completely overwriting the\nmemory can allow this old data to be leaked when the Buffer memory is read.

\n

While there are clear performance advantages to using\nBuffer.allocUnsafe(), extra care must be taken in order to avoid\nintroducing security vulnerabilities into an application.

", "type": "module", "displayName": "What makes `Buffer.allocUnsafe()` and `Buffer.allocUnsafeSlow()` \"unsafe\"?" } ], "type": "module", "displayName": "`Buffer.from()`, `Buffer.alloc()`, and `Buffer.allocUnsafe()`" }, { "textRaw": "Buffers and Character Encodings", "name": "buffers_and_character_encodings", "meta": { "changes": [ { "version": "v6.4.0", "pr-url": "https://github.com/nodejs/node/pull/7111", "description": "Introduced `latin1` as an alias for `binary`." }, { "version": "v5.0.0", "pr-url": "https://github.com/nodejs/node/pull/2859", "description": "Removed the deprecated `raw` and `raws` encodings." } ] }, "desc": "

When string data is stored in or extracted out of a Buffer instance, a\ncharacter encoding may be specified.

\n
const buf = Buffer.from('hello world', 'ascii');\n\nconsole.log(buf.toString('hex'));\n// Prints: 68656c6c6f20776f726c64\nconsole.log(buf.toString('base64'));\n// Prints: aGVsbG8gd29ybGQ=\n\nconsole.log(Buffer.from('fhqwhgads', 'ascii'));\n// Prints: <Buffer 66 68 71 77 68 67 61 64 73>\nconsole.log(Buffer.from('fhqwhgads', 'utf16le'));\n// Prints: <Buffer 66 00 68 00 71 00 77 00 68 00 67 00 61 00 64 00 73 00>\n
\n

The character encodings currently supported by Node.js include:

\n\n

Modern Web browsers follow the WHATWG Encoding Standard which aliases\nboth 'latin1' and 'ISO-8859-1' to 'win-1252'. This means that while doing\nsomething like http.get(), if the returned charset is one of those listed in\nthe WHATWG specification it is possible that the server actually returned\n'win-1252'-encoded data, and using 'latin1' encoding may incorrectly decode\nthe characters.

", "type": "module", "displayName": "Buffers and Character Encodings" }, { "textRaw": "Buffers and TypedArray", "name": "buffers_and_typedarray", "meta": { "changes": [ { "version": "v3.0.0", "pr-url": "https://github.com/nodejs/node/pull/2002", "description": "The `Buffer`s class now inherits from `Uint8Array`." } ] }, "desc": "

Buffer instances are also Uint8Array instances. However, there are\nsubtle incompatibilities with TypedArray. For example, while\nArrayBuffer#slice() creates a copy of the slice, the implementation of\nBuffer#slice() creates a view over the existing Buffer\nwithout copying, making Buffer#slice() far more efficient.

\n

It is also possible to create new TypedArray instances from a Buffer\nwith the following caveats:

\n
    \n
  1. \n

    The Buffer object's memory is copied to the TypedArray, not shared.

    \n
  2. \n
  3. \n

    The Buffer object's memory is interpreted as an array of distinct\nelements, and not as a byte array of the target type. That is,\nnew Uint32Array(Buffer.from([1, 2, 3, 4])) creates a 4-element\nUint32Array with elements [1, 2, 3, 4], not a Uint32Array with a\nsingle element [0x1020304] or [0x4030201].

    \n
  4. \n
\n

It is possible to create a new Buffer that shares the same allocated memory as\na TypedArray instance by using the TypedArray object's .buffer\nproperty.

\n
const arr = new Uint16Array(2);\n\narr[0] = 5000;\narr[1] = 4000;\n\n// Copies the contents of `arr`.\nconst buf1 = Buffer.from(arr);\n// Shares memory with `arr`.\nconst buf2 = Buffer.from(arr.buffer);\n\nconsole.log(buf1);\n// Prints: <Buffer 88 a0>\nconsole.log(buf2);\n// Prints: <Buffer 88 13 a0 0f>\n\narr[1] = 6000;\n\nconsole.log(buf1);\n// Prints: <Buffer 88 a0>\nconsole.log(buf2);\n// Prints: <Buffer 88 13 70 17>\n
\n

When creating a Buffer using a TypedArray's .buffer, it is\npossible to use only a portion of the underlying ArrayBuffer by passing in\nbyteOffset and length parameters.

\n
const arr = new Uint16Array(20);\nconst buf = Buffer.from(arr.buffer, 0, 16);\n\nconsole.log(buf.length);\n// Prints: 16\n
\n

The Buffer.from() and TypedArray.from() have different signatures and\nimplementations. Specifically, the TypedArray variants accept a second\nargument that is a mapping function that is invoked on every element of the\ntyped array:

\n\n

The Buffer.from() method, however, does not support the use of a mapping\nfunction:

\n", "type": "module", "displayName": "Buffers and TypedArray" }, { "textRaw": "Buffers and iteration", "name": "buffers_and_iteration", "desc": "

Buffer instances can be iterated over using for..of syntax:

\n
const buf = Buffer.from([1, 2, 3]);\n\nfor (const b of buf) {\n  console.log(b);\n}\n// Prints:\n//   1\n//   2\n//   3\n
\n

Additionally, the buf.values(), buf.keys(), and\nbuf.entries() methods can be used to create iterators.

", "type": "module", "displayName": "Buffers and iteration" }, { "textRaw": "Class: `Buffer`", "name": "class:_`buffer`", "desc": "

The Buffer class is a global type for dealing with binary data directly.\nIt can be constructed in a variety of ways.

", "modules": [ { "textRaw": "`new Buffer(array)`", "name": "`new_buffer(array)`", "meta": { "deprecated": [ "v6.0.0" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/19524", "description": "Calling this constructor emits a deprecation warning when run from code outside the `node_modules` directory." }, { "version": "v7.2.1", "pr-url": "https://github.com/nodejs/node/pull/9529", "description": "Calling this constructor no longer emits a deprecation warning." }, { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/8169", "description": "Calling this constructor emits a deprecation warning now." } ] }, "stability": 0, "stabilityText": "Deprecated: Use [`Buffer.from(array)`][] instead.", "desc": "\n

Allocates a new Buffer using an array of octets.

\n
// Creates a new Buffer containing the UTF-8 bytes of the string 'buffer'.\nconst buf = new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);\n
", "type": "module", "displayName": "`new Buffer(array)`" }, { "textRaw": "`new Buffer(arrayBuffer[, byteOffset[, length]])`", "name": "`new_buffer(arraybuffer[,_byteoffset[,_length]])`", "meta": { "added": [ "v3.0.0" ], "deprecated": [ "v6.0.0" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/19524", "description": "Calling this constructor emits a deprecation warning when run from code outside the `node_modules` directory." }, { "version": "v7.2.1", "pr-url": "https://github.com/nodejs/node/pull/9529", "description": "Calling this constructor no longer emits a deprecation warning." }, { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/8169", "description": "Calling this constructor emits a deprecation warning now." }, { "version": "v6.0.0", "pr-url": "https://github.com/nodejs/node/pull/4682", "description": "The `byteOffset` and `length` parameters are supported now." } ] }, "stability": 0, "stabilityText": "Deprecated: Use\n[`Buffer.from(arrayBuffer[, byteOffset[, length]])`][`Buffer.from(arrayBuf)`]\ninstead.", "desc": "\n

This creates a view of the ArrayBuffer or SharedArrayBuffer without\ncopying the underlying memory. For example, when passed a reference to the\n.buffer property of a TypedArray instance, the newly created Buffer\nwill share the same allocated memory as the TypedArray.

\n

The optional byteOffset and length arguments specify a memory range within\nthe arrayBuffer that will be shared by the Buffer.

\n
const arr = new Uint16Array(2);\n\narr[0] = 5000;\narr[1] = 4000;\n\n// Shares memory with `arr`.\nconst buf = new Buffer(arr.buffer);\n\nconsole.log(buf);\n// Prints: <Buffer 88 13 a0 0f>\n\n// Changing the original Uint16Array changes the Buffer also.\narr[1] = 6000;\n\nconsole.log(buf);\n// Prints: <Buffer 88 13 70 17>\n
", "type": "module", "displayName": "`new Buffer(arrayBuffer[, byteOffset[, length]])`" }, { "textRaw": "`new Buffer(buffer)`", "name": "`new_buffer(buffer)`", "meta": { "deprecated": [ "v6.0.0" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/19524", "description": "Calling this constructor emits a deprecation warning when run from code outside the `node_modules` directory." }, { "version": "v7.2.1", "pr-url": "https://github.com/nodejs/node/pull/9529", "description": "Calling this constructor no longer emits a deprecation warning." }, { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/8169", "description": "Calling this constructor emits a deprecation warning now." } ] }, "stability": 0, "stabilityText": "Deprecated: Use [`Buffer.from(buffer)`][] instead.", "desc": "\n

Copies the passed buffer data onto a new Buffer instance.

\n
const buf1 = new Buffer('buffer');\nconst buf2 = new Buffer(buf1);\n\nbuf1[0] = 0x61;\n\nconsole.log(buf1.toString());\n// Prints: auffer\nconsole.log(buf2.toString());\n// Prints: buffer\n
", "type": "module", "displayName": "`new Buffer(buffer)`" }, { "textRaw": "`new Buffer(size)`", "name": "`new_buffer(size)`", "meta": { "deprecated": [ "v6.0.0" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/19524", "description": "Calling this constructor emits a deprecation warning when run from code outside the `node_modules` directory." }, { "version": "v8.0.0", "pr-url": "https://github.com/nodejs/node/pull/12141", "description": "The `new Buffer(size)` will return zero-filled memory by default." }, { "version": "v7.2.1", "pr-url": "https://github.com/nodejs/node/pull/9529", "description": "Calling this constructor no longer emits a deprecation warning." }, { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/8169", "description": "Calling this constructor emits a deprecation warning now." } ] }, "stability": 0, "stabilityText": "Deprecated: Use [`Buffer.alloc()`][] instead (also see\n[`Buffer.allocUnsafe()`][]).", "desc": "\n

Allocates a new Buffer of size bytes. If size is larger than\nbuffer.constants.MAX_LENGTH or smaller than 0, ERR_INVALID_OPT_VALUE\nis thrown. A zero-length Buffer is created if size is 0.

\n

Prior to Node.js 8.0.0, the underlying memory for Buffer instances\ncreated in this way is not initialized. The contents of a newly created\nBuffer are unknown and may contain sensitive data. Use\nBuffer.alloc(size) instead to initialize a Buffer\nwith zeroes.

\n
const buf = new Buffer(10);\n\nconsole.log(buf);\n// Prints: <Buffer 00 00 00 00 00 00 00 00 00 00>\n
", "type": "module", "displayName": "`new Buffer(size)`" }, { "textRaw": "`new Buffer(string[, encoding])`", "name": "`new_buffer(string[,_encoding])`", "meta": { "deprecated": [ "v6.0.0" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/19524", "description": "Calling this constructor emits a deprecation warning when run from code outside the `node_modules` directory." }, { "version": "v7.2.1", "pr-url": "https://github.com/nodejs/node/pull/9529", "description": "Calling this constructor no longer emits a deprecation warning." }, { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/8169", "description": "Calling this constructor emits a deprecation warning now." } ] }, "stability": 0, "stabilityText": "Deprecated:\nUse [`Buffer.from(string[, encoding])`][`Buffer.from(string)`] instead.", "desc": "\n

Creates a new Buffer containing string. The encoding parameter identifies\nthe character encoding of string.

\n
const buf1 = new Buffer('this is a tést');\nconst buf2 = new Buffer('7468697320697320612074c3a97374', 'hex');\n\nconsole.log(buf1.toString());\n// Prints: this is a tést\nconsole.log(buf2.toString());\n// Prints: this is a tést\nconsole.log(buf1.toString('ascii'));\n// Prints: this is a tC)st\n
", "type": "module", "displayName": "`new Buffer(string[, encoding])`" }, { "textRaw": "Class Method: `Buffer.alloc(size[, fill[, encoding]])`", "name": "class_method:_`buffer.alloc(size[,_fill[,_encoding]])`", "meta": { "added": [ "v5.10.0" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18129", "description": "Attempting to fill a non-zero length buffer with a zero length buffer triggers a thrown exception." }, { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/17427", "description": "Specifying an invalid string for `fill` triggers a thrown exception." }, { "version": "v8.9.3", "pr-url": "https://github.com/nodejs/node/pull/17428", "description": "Specifying an invalid string for `fill` now results in a zero-filled buffer." } ] }, "desc": "\n

Allocates a new Buffer of size bytes. If fill is undefined, the\nBuffer will be zero-filled.

\n
const buf = Buffer.alloc(5);\n\nconsole.log(buf);\n// Prints: <Buffer 00 00 00 00 00>\n
\n

If size is larger than\nbuffer.constants.MAX_LENGTH or smaller than 0, ERR_INVALID_OPT_VALUE\nis thrown. A zero-length Buffer is created if size is 0.

\n

If fill is specified, the allocated Buffer will be initialized by calling\nbuf.fill(fill).

\n
const buf = Buffer.alloc(5, 'a');\n\nconsole.log(buf);\n// Prints: <Buffer 61 61 61 61 61>\n
\n

If both fill and encoding are specified, the allocated Buffer will be\ninitialized by calling buf.fill(fill, encoding).

\n
const buf = Buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64');\n\nconsole.log(buf);\n// Prints: <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64>\n
\n

Calling Buffer.alloc() can be significantly slower than the alternative\nBuffer.allocUnsafe() but ensures that the newly created Buffer instance\ncontents will never contain sensitive data.

\n

A TypeError will be thrown if size is not a number.

", "type": "module", "displayName": "Class Method: `Buffer.alloc(size[, fill[, encoding]])`" }, { "textRaw": "Class Method: `Buffer.allocUnsafe(size)`", "name": "class_method:_`buffer.allocunsafe(size)`", "meta": { "added": [ "v5.10.0" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7079", "description": "Passing a negative `size` will now throw an error." } ] }, "desc": "\n

Allocates a new Buffer of size bytes. If size is larger than\nbuffer.constants.MAX_LENGTH or smaller than 0, ERR_INVALID_OPT_VALUE\nis thrown. A zero-length Buffer is created if size is 0.

\n

The underlying memory for Buffer instances created in this way is not\ninitialized. The contents of the newly created Buffer are unknown and\nmay contain sensitive data. Use Buffer.alloc() instead to initialize\nBuffer instances with zeroes.

\n
const buf = Buffer.allocUnsafe(10);\n\nconsole.log(buf);\n// Prints (contents may vary): <Buffer a0 8b 28 3f 01 00 00 00 50 32>\n\nbuf.fill(0);\n\nconsole.log(buf);\n// Prints: <Buffer 00 00 00 00 00 00 00 00 00 00>\n
\n

A TypeError will be thrown if size is not a number.

\n

The Buffer module pre-allocates an internal Buffer instance of\nsize Buffer.poolSize that is used as a pool for the fast allocation of new\nBuffer instances created using Buffer.allocUnsafe() and the deprecated\nnew Buffer(size) constructor only when size is less than or equal to\nBuffer.poolSize >> 1 (floor of Buffer.poolSize divided by two).

\n

Use of this pre-allocated internal memory pool is a key difference between\ncalling Buffer.alloc(size, fill) vs. Buffer.allocUnsafe(size).fill(fill).\nSpecifically, Buffer.alloc(size, fill) will never use the internal Buffer\npool, while Buffer.allocUnsafe(size).fill(fill) will use the internal\nBuffer pool if size is less than or equal to half Buffer.poolSize. The\ndifference is subtle but can be important when an application requires the\nadditional performance that Buffer.allocUnsafe() provides.

", "type": "module", "displayName": "Class Method: `Buffer.allocUnsafe(size)`" }, { "textRaw": "Class Method: `Buffer.allocUnsafeSlow(size)`", "name": "class_method:_`buffer.allocunsafeslow(size)`", "meta": { "added": [ "v5.12.0" ], "changes": [] }, "desc": "\n

Allocates a new Buffer of size bytes. If size is larger than\nbuffer.constants.MAX_LENGTH or smaller than 0, ERR_INVALID_OPT_VALUE\nis thrown. A zero-length Buffer is created if size is 0.

\n

The underlying memory for Buffer instances created in this way is not\ninitialized. The contents of the newly created Buffer are unknown and\nmay contain sensitive data. Use buf.fill(0) to initialize\nsuch Buffer instances with zeroes.

\n

When using Buffer.allocUnsafe() to allocate new Buffer instances,\nallocations under 4KB are sliced from a single pre-allocated Buffer. This\nallows applications to avoid the garbage collection overhead of creating many\nindividually allocated Buffer instances. This approach improves both\nperformance and memory usage by eliminating the need to track and clean up as\nmany persistent objects.

\n

However, in the case where a developer may need to retain a small chunk of\nmemory from a pool for an indeterminate amount of time, it may be appropriate\nto create an un-pooled Buffer instance using Buffer.allocUnsafeSlow() and\nthen copying out the relevant bits.

\n
// Need to keep around a few small chunks of memory.\nconst store = [];\n\nsocket.on('readable', () => {\n  let data;\n  while (null !== (data = readable.read())) {\n    // Allocate for retained data.\n    const sb = Buffer.allocUnsafeSlow(10);\n\n    // Copy the data into the new allocation.\n    data.copy(sb, 0, 0, 10);\n\n    store.push(sb);\n  }\n});\n
\n

Buffer.allocUnsafeSlow() should be used only as a last resort after a\ndeveloper has observed undue memory retention in their applications.

\n

A TypeError will be thrown if size is not a number.

", "type": "module", "displayName": "Class Method: `Buffer.allocUnsafeSlow(size)`" }, { "textRaw": "Class Method: `Buffer.byteLength(string[, encoding])`", "name": "class_method:_`buffer.bytelength(string[,_encoding])`", "meta": { "added": [ "v0.1.90" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/8946", "description": "Passing invalid input will now throw an error." }, { "version": "v5.10.0", "pr-url": "https://github.com/nodejs/node/pull/5255", "description": "The `string` parameter can now be any `TypedArray`, `DataView` or `ArrayBuffer`." } ] }, "desc": "\n

Returns the actual byte length of a string. This is not the same as\nString.prototype.length since that returns the number of characters in\na string.

\n

For 'base64' and 'hex', this function assumes valid input. For strings that\ncontain non-Base64/Hex-encoded data (e.g. whitespace), the return value might be\ngreater than the length of a Buffer created from the string.

\n
const str = '\\u00bd + \\u00bc = \\u00be';\n\nconsole.log(`${str}: ${str.length} characters, ` +\n            `${Buffer.byteLength(str, 'utf8')} bytes`);\n// Prints: ½ + ¼ = ¾: 9 characters, 12 bytes\n
\n

When string is a Buffer/DataView/TypedArray/ArrayBuffer/\nSharedArrayBuffer, the actual byte length is returned.

", "type": "module", "displayName": "Class Method: `Buffer.byteLength(string[, encoding])`" }, { "textRaw": "Class Method: `Buffer.compare(buf1, buf2)`", "name": "class_method:_`buffer.compare(buf1,_buf2)`", "meta": { "added": [ "v0.11.13" ], "changes": [ { "version": "v8.0.0", "pr-url": "https://github.com/nodejs/node/pull/10236", "description": "The arguments can now be `Uint8Array`s." } ] }, "desc": "\n

Compares buf1 to buf2 typically for the purpose of sorting arrays of\nBuffer instances. This is equivalent to calling\nbuf1.compare(buf2).

\n
const buf1 = Buffer.from('1234');\nconst buf2 = Buffer.from('0123');\nconst arr = [buf1, buf2];\n\nconsole.log(arr.sort(Buffer.compare));\n// Prints: [ <Buffer 30 31 32 33>, <Buffer 31 32 33 34> ]\n// (This result is equal to: [buf2, buf1].)\n
", "type": "module", "displayName": "Class Method: `Buffer.compare(buf1, buf2)`" }, { "textRaw": "Class Method: `Buffer.concat(list[, totalLength])`", "name": "class_method:_`buffer.concat(list[,_totallength])`", "meta": { "added": [ "v0.7.11" ], "changes": [ { "version": "v8.0.0", "pr-url": "https://github.com/nodejs/node/pull/10236", "description": "The elements of `list` can now be `Uint8Array`s." } ] }, "desc": "\n

Returns a new Buffer which is the result of concatenating all the Buffer\ninstances in the list together.

\n

If the list has no items, or if the totalLength is 0, then a new zero-length\nBuffer is returned.

\n

If totalLength is not provided, it is calculated from the Buffer instances\nin list. This however causes an additional loop to be executed in order to\ncalculate the totalLength, so it is faster to provide the length explicitly if\nit is already known.

\n

If totalLength is provided, it is coerced to an unsigned integer. If the\ncombined length of the Buffers in list exceeds totalLength, the result is\ntruncated to totalLength.

\n
// Create a single `Buffer` from a list of three `Buffer` instances.\n\nconst buf1 = Buffer.alloc(10);\nconst buf2 = Buffer.alloc(14);\nconst buf3 = Buffer.alloc(18);\nconst totalLength = buf1.length + buf2.length + buf3.length;\n\nconsole.log(totalLength);\n// Prints: 42\n\nconst bufA = Buffer.concat([buf1, buf2, buf3], totalLength);\n\nconsole.log(bufA);\n// Prints: <Buffer 00 00 00 00 ...>\nconsole.log(bufA.length);\n// Prints: 42\n
", "type": "module", "displayName": "Class Method: `Buffer.concat(list[, totalLength])`" }, { "textRaw": "Class Method: `Buffer.from(array)`", "name": "class_method:_`buffer.from(array)`", "meta": { "added": [ "v5.10.0" ], "changes": [] }, "desc": "\n

Allocates a new Buffer using an array of octets.

\n
// Creates a new Buffer containing UTF-8 bytes of the string 'buffer'.\nconst buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);\n
\n

A TypeError will be thrown if array is not an Array or other type\nappropriate for Buffer.from() variants.

", "type": "module", "displayName": "Class Method: `Buffer.from(array)`" }, { "textRaw": "Class Method: `Buffer.from(arrayBuffer[, byteOffset[, length]])`", "name": "class_method:_`buffer.from(arraybuffer[,_byteoffset[,_length]])`", "meta": { "added": [ "v5.10.0" ], "changes": [] }, "desc": "\n

This creates a view of the ArrayBuffer without copying the underlying\nmemory. For example, when passed a reference to the .buffer property of a\nTypedArray instance, the newly created Buffer will share the same\nallocated memory as the TypedArray.

\n
const arr = new Uint16Array(2);\n\narr[0] = 5000;\narr[1] = 4000;\n\n// Shares memory with `arr`.\nconst buf = Buffer.from(arr.buffer);\n\nconsole.log(buf);\n// Prints: <Buffer 88 13 a0 0f>\n\n// Changing the original Uint16Array changes the Buffer also.\narr[1] = 6000;\n\nconsole.log(buf);\n// Prints: <Buffer 88 13 70 17>\n
\n

The optional byteOffset and length arguments specify a memory range within\nthe arrayBuffer that will be shared by the Buffer.

\n
const ab = new ArrayBuffer(10);\nconst buf = Buffer.from(ab, 0, 2);\n\nconsole.log(buf.length);\n// Prints: 2\n
\n

A TypeError will be thrown if arrayBuffer is not an ArrayBuffer or a\nSharedArrayBuffer or other type appropriate for Buffer.from() variants.

", "type": "module", "displayName": "Class Method: `Buffer.from(arrayBuffer[, byteOffset[, length]])`" }, { "textRaw": "Class Method: `Buffer.from(buffer)`", "name": "class_method:_`buffer.from(buffer)`", "meta": { "added": [ "v5.10.0" ], "changes": [] }, "desc": "\n

Copies the passed buffer data onto a new Buffer instance.

\n
const buf1 = Buffer.from('buffer');\nconst buf2 = Buffer.from(buf1);\n\nbuf1[0] = 0x61;\n\nconsole.log(buf1.toString());\n// Prints: auffer\nconsole.log(buf2.toString());\n// Prints: buffer\n
\n

A TypeError will be thrown if buffer is not a Buffer or other type\nappropriate for Buffer.from() variants.

", "type": "module", "displayName": "Class Method: `Buffer.from(buffer)`" }, { "textRaw": "Class Method: `Buffer.from(object[, offsetOrEncoding[, length]])`", "name": "class_method:_`buffer.from(object[,_offsetorencoding[,_length]])`", "meta": { "added": [ "v8.2.0" ], "changes": [] }, "desc": "\n

For objects whose valueOf() function returns a value not strictly equal to\nobject, returns Buffer.from(object.valueOf(), offsetOrEncoding, length).

\n
const buf = Buffer.from(new String('this is a test'));\n// Prints: <Buffer 74 68 69 73 20 69 73 20 61 20 74 65 73 74>\n
\n

For objects that support Symbol.toPrimitive, returns\nBuffer.from(object[Symbol.toPrimitive](), offsetOrEncoding, length).

\n
class Foo {\n  [Symbol.toPrimitive]() {\n    return 'this is a test';\n  }\n}\n\nconst buf = Buffer.from(new Foo(), 'utf8');\n// Prints: <Buffer 74 68 69 73 20 69 73 20 61 20 74 65 73 74>\n
\n

A TypeError will be thrown if object has not mentioned methods or is not of\nother type appropriate for Buffer.from() variants.

", "type": "module", "displayName": "Class Method: `Buffer.from(object[, offsetOrEncoding[, length]])`" }, { "textRaw": "Class Method: `Buffer.from(string[, encoding])`", "name": "class_method:_`buffer.from(string[,_encoding])`", "meta": { "added": [ "v5.10.0" ], "changes": [] }, "desc": "\n

Creates a new Buffer containing string. The encoding parameter identifies\nthe character encoding of string.

\n
const buf1 = Buffer.from('this is a tést');\nconst buf2 = Buffer.from('7468697320697320612074c3a97374', 'hex');\n\nconsole.log(buf1.toString());\n// Prints: this is a tést\nconsole.log(buf2.toString());\n// Prints: this is a tést\nconsole.log(buf1.toString('ascii'));\n// Prints: this is a tC)st\n
\n

A TypeError will be thrown if string is not a string or other type\nappropriate for Buffer.from() variants.

", "type": "module", "displayName": "Class Method: `Buffer.from(string[, encoding])`" }, { "textRaw": "Class Method: `Buffer.isBuffer(obj)`", "name": "class_method:_`buffer.isbuffer(obj)`", "meta": { "added": [ "v0.1.101" ], "changes": [] }, "desc": "\n

Returns true if obj is a Buffer, false otherwise.

", "type": "module", "displayName": "Class Method: `Buffer.isBuffer(obj)`" }, { "textRaw": "Class Method: `Buffer.isEncoding(encoding)`", "name": "class_method:_`buffer.isencoding(encoding)`", "meta": { "added": [ "v0.9.1" ], "changes": [] }, "desc": "\n

Returns true if encoding contains a supported character encoding, or false\notherwise.

\n
console.log(Buffer.isEncoding('utf-8'));\n// Prints: true\n\nconsole.log(Buffer.isEncoding('hex'));\n// Prints: true\n\nconsole.log(Buffer.isEncoding('utf/8'));\n// Prints: false\n\nconsole.log(Buffer.isEncoding(''));\n// Prints: false\n
", "type": "module", "displayName": "Class Method: `Buffer.isEncoding(encoding)`" }, { "textRaw": "Class Property: `Buffer.poolSize`", "name": "class_property:_`buffer.poolsize`", "meta": { "added": [ "v0.11.3" ], "changes": [] }, "desc": "\n

This is the size (in bytes) of pre-allocated internal Buffer instances used\nfor pooling. This value may be modified.

", "type": "module", "displayName": "Class Property: `Buffer.poolSize`" }, { "textRaw": "`buf[index]`", "name": "`buf[index]`", "meta": { "type": "property", "name": [ "index" ], "changes": [] }, "desc": "\n

The index operator [index] can be used to get and set the octet at position\nindex in buf. The values refer to individual bytes, so the legal value\nrange is between 0x00 and 0xFF (hex) or 0 and 255 (decimal).

\n

This operator is inherited from Uint8Array, so its behavior on out-of-bounds\naccess is the same as UInt8Array. In other words, getting returns undefined\nand setting does nothing.

\n
// Copy an ASCII string into a `Buffer` one byte at a time.\n\nconst str = 'Node.js';\nconst buf = Buffer.allocUnsafe(str.length);\n\nfor (let i = 0; i < str.length; i++) {\n  buf[i] = str.charCodeAt(i);\n}\n\nconsole.log(buf.toString('ascii'));\n// Prints: Node.js\n
", "type": "module", "displayName": "`buf[index]`" }, { "textRaw": "`buf.buffer`", "name": "`buf.buffer`", "desc": "\n

This ArrayBuffer is not guaranteed to correspond exactly to the original\nBuffer. See the notes on buf.byteOffset for details.

\n
const arrayBuffer = new ArrayBuffer(16);\nconst buffer = Buffer.from(arrayBuffer);\n\nconsole.log(buffer.buffer === arrayBuffer);\n// Prints: true\n
", "type": "module", "displayName": "`buf.buffer`" }, { "textRaw": "`buf.byteOffset`", "name": "`buf.byteoffset`", "desc": "\n

When setting byteOffset in Buffer.from(ArrayBuffer, byteOffset, length)\nor sometimes when allocating a buffer smaller than Buffer.poolSize the\nbuffer doesn't start from a zero offset on the underlying ArrayBuffer.

\n

This can cause problems when accessing the underlying ArrayBuffer directly\nusing buf.buffer, as the first bytes in this ArrayBuffer may be unrelated\nto the buf object itself.

\n

A common issue is when casting a Buffer object to a TypedArray object,\nin this case one needs to specify the byteOffset correctly:

\n
// Create a buffer smaller than `Buffer.poolSize`.\nconst nodeBuffer = new Buffer.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);\n\n// When casting the Node.js Buffer to an Int8 TypedArray remember to use the\n// byteOffset.\nnew Int8Array(nodeBuffer.buffer, nodeBuffer.byteOffset, nodeBuffer.length);\n
", "type": "module", "displayName": "`buf.byteOffset`" }, { "textRaw": "`buf.compare(target[, targetStart[, targetEnd[, sourceStart[, sourceEnd]]]])`", "name": "`buf.compare(target[,_targetstart[,_targetend[,_sourcestart[,_sourceend]]]])`", "meta": { "added": [ "v0.11.13" ], "changes": [ { "version": "v8.0.0", "pr-url": "https://github.com/nodejs/node/pull/10236", "description": "The `target` parameter can now be a `Uint8Array`." }, { "version": "v5.11.0", "pr-url": "https://github.com/nodejs/node/pull/5880", "description": "Additional parameters for specifying offsets are supported now." } ] }, "desc": "\n

Compares buf with target and returns a number indicating whether buf\ncomes before, after, or is the same as target in sort order.\nComparison is based on the actual sequence of bytes in each Buffer.

\n\n
const buf1 = Buffer.from('ABC');\nconst buf2 = Buffer.from('BCD');\nconst buf3 = Buffer.from('ABCD');\n\nconsole.log(buf1.compare(buf1));\n// Prints: 0\nconsole.log(buf1.compare(buf2));\n// Prints: -1\nconsole.log(buf1.compare(buf3));\n// Prints: -1\nconsole.log(buf2.compare(buf1));\n// Prints: 1\nconsole.log(buf2.compare(buf3));\n// Prints: 1\nconsole.log([buf1, buf2, buf3].sort(Buffer.compare));\n// Prints: [ <Buffer 41 42 43>, <Buffer 41 42 43 44>, <Buffer 42 43 44> ]\n// (This result is equal to: [buf1, buf3, buf2].)\n
\n

The optional targetStart, targetEnd, sourceStart, and sourceEnd\narguments can be used to limit the comparison to specific ranges within target\nand buf respectively.

\n
const buf1 = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9]);\nconst buf2 = Buffer.from([5, 6, 7, 8, 9, 1, 2, 3, 4]);\n\nconsole.log(buf1.compare(buf2, 5, 9, 0, 4));\n// Prints: 0\nconsole.log(buf1.compare(buf2, 0, 6, 4));\n// Prints: -1\nconsole.log(buf1.compare(buf2, 5, 6, 5));\n// Prints: 1\n
\n

ERR_OUT_OF_RANGE is thrown if targetStart < 0, sourceStart < 0,\ntargetEnd > target.byteLength, or sourceEnd > source.byteLength.

", "type": "module", "displayName": "`buf.compare(target[, targetStart[, targetEnd[, sourceStart[, sourceEnd]]]])`" }, { "textRaw": "`buf.copy(target[, targetStart[, sourceStart[, sourceEnd]]])`", "name": "`buf.copy(target[,_targetstart[,_sourcestart[,_sourceend]]])`", "meta": { "added": [ "v0.1.90" ], "changes": [] }, "desc": "\n

Copies data from a region of buf to a region in target even if the target\nmemory region overlaps with buf.

\n
// Create two `Buffer` instances.\nconst buf1 = Buffer.allocUnsafe(26);\nconst buf2 = Buffer.allocUnsafe(26).fill('!');\n\nfor (let i = 0; i < 26; i++) {\n  // 97 is the decimal ASCII value for 'a'.\n  buf1[i] = i + 97;\n}\n\n// Copy `buf1` bytes 16 through 19 into `buf2` starting at byte 8 of `buf2`.\nbuf1.copy(buf2, 8, 16, 20);\n\nconsole.log(buf2.toString('ascii', 0, 25));\n// Prints: !!!!!!!!qrst!!!!!!!!!!!!!\n
\n
// Create a `Buffer` and copy data from one region to an overlapping region\n// within the same `Buffer`.\n\nconst buf = Buffer.allocUnsafe(26);\n\nfor (let i = 0; i < 26; i++) {\n  // 97 is the decimal ASCII value for 'a'.\n  buf[i] = i + 97;\n}\n\nbuf.copy(buf, 0, 4, 10);\n\nconsole.log(buf.toString());\n// Prints: efghijghijklmnopqrstuvwxyz\n
", "type": "module", "displayName": "`buf.copy(target[, targetStart[, sourceStart[, sourceEnd]]])`" }, { "textRaw": "`buf.entries()`", "name": "`buf.entries()`", "meta": { "added": [ "v1.1.0" ], "changes": [] }, "desc": "\n

Creates and returns an iterator of [index, byte] pairs from the contents\nof buf.

\n
// Log the entire contents of a `Buffer`.\n\nconst buf = Buffer.from('buffer');\n\nfor (const pair of buf.entries()) {\n  console.log(pair);\n}\n// Prints:\n//   [0, 98]\n//   [1, 117]\n//   [2, 102]\n//   [3, 102]\n//   [4, 101]\n//   [5, 114]\n
", "type": "module", "displayName": "`buf.entries()`" }, { "textRaw": "`buf.equals(otherBuffer)`", "name": "`buf.equals(otherbuffer)`", "meta": { "added": [ "v0.11.13" ], "changes": [ { "version": "v8.0.0", "pr-url": "https://github.com/nodejs/node/pull/10236", "description": "The arguments can now be `Uint8Array`s." } ] }, "desc": "\n

Returns true if both buf and otherBuffer have exactly the same bytes,\nfalse otherwise.

\n
const buf1 = Buffer.from('ABC');\nconst buf2 = Buffer.from('414243', 'hex');\nconst buf3 = Buffer.from('ABCD');\n\nconsole.log(buf1.equals(buf2));\n// Prints: true\nconsole.log(buf1.equals(buf3));\n// Prints: false\n
", "type": "module", "displayName": "`buf.equals(otherBuffer)`" }, { "textRaw": "`buf.fill(value[, offset[, end]][, encoding])`", "name": "`buf.fill(value[,_offset[,_end]][,_encoding])`", "meta": { "added": [ "v0.5.0" ], "changes": [ { "version": "v11.0.0", "pr-url": "https://github.com/nodejs/node/pull/22969", "description": "Throws `ERR_OUT_OF_RANGE` instead of `ERR_INDEX_OUT_OF_RANGE`." }, { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18790", "description": "Negative `end` values throw an `ERR_INDEX_OUT_OF_RANGE` error." }, { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18129", "description": "Attempting to fill a non-zero length buffer with a zero length buffer triggers a thrown exception." }, { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/17427", "description": "Specifying an invalid string for `value` triggers a thrown exception." }, { "version": "v5.7.0", "pr-url": "https://github.com/nodejs/node/pull/4935", "description": "The `encoding` parameter is supported now." } ] }, "desc": "\n

Fills buf with the specified value. If the offset and end are not given,\nthe entire buf will be filled:

\n
// Fill a `Buffer` with the ASCII character 'h'.\n\nconst b = Buffer.allocUnsafe(50).fill('h');\n\nconsole.log(b.toString());\n// Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n
\n

value is coerced to a uint32 value if it is not a string, Buffer, or\ninteger. If the resulting integer is greater than 255 (decimal), buf will be\nfilled with value & 255.

\n

If the final write of a fill() operation falls on a multi-byte character,\nthen only the bytes of that character that fit into buf are written:

\n
// Fill a `Buffer` with a two-byte character.\n\nconsole.log(Buffer.allocUnsafe(3).fill('\\u0222'));\n// Prints: <Buffer c8 a2 c8>\n
\n

If value contains invalid characters, it is truncated; if no valid\nfill data remains, an exception is thrown:

\n
const buf = Buffer.allocUnsafe(5);\n\nconsole.log(buf.fill('a'));\n// Prints: <Buffer 61 61 61 61 61>\nconsole.log(buf.fill('aazz', 'hex'));\n// Prints: <Buffer aa aa aa aa aa>\nconsole.log(buf.fill('zz', 'hex'));\n// Throws an exception.\n
", "type": "module", "displayName": "`buf.fill(value[, offset[, end]][, encoding])`" }, { "textRaw": "`buf.includes(value[, byteOffset][, encoding])`", "name": "`buf.includes(value[,_byteoffset][,_encoding])`", "meta": { "added": [ "v5.3.0" ], "changes": [] }, "desc": "\n

Equivalent to buf.indexOf() !== -1.

\n
const buf = Buffer.from('this is a buffer');\n\nconsole.log(buf.includes('this'));\n// Prints: true\nconsole.log(buf.includes('is'));\n// Prints: true\nconsole.log(buf.includes(Buffer.from('a buffer')));\n// Prints: true\nconsole.log(buf.includes(97));\n// Prints: true (97 is the decimal ASCII value for 'a')\nconsole.log(buf.includes(Buffer.from('a buffer example')));\n// Prints: false\nconsole.log(buf.includes(Buffer.from('a buffer example').slice(0, 8)));\n// Prints: true\nconsole.log(buf.includes('this', 4));\n// Prints: false\n
", "type": "module", "displayName": "`buf.includes(value[, byteOffset][, encoding])`" }, { "textRaw": "`buf.indexOf(value[, byteOffset][, encoding])`", "name": "`buf.indexof(value[,_byteoffset][,_encoding])`", "meta": { "added": [ "v1.5.0" ], "changes": [ { "version": "v8.0.0", "pr-url": "https://github.com/nodejs/node/pull/10236", "description": "The `value` can now be a `Uint8Array`." }, { "version": "v5.7.0, v4.4.0", "pr-url": "https://github.com/nodejs/node/pull/4803", "description": "When `encoding` is being passed, the `byteOffset` parameter is no longer required." } ] }, "desc": "\n

If value is:

\n\n
const buf = Buffer.from('this is a buffer');\n\nconsole.log(buf.indexOf('this'));\n// Prints: 0\nconsole.log(buf.indexOf('is'));\n// Prints: 2\nconsole.log(buf.indexOf(Buffer.from('a buffer')));\n// Prints: 8\nconsole.log(buf.indexOf(97));\n// Prints: 8 (97 is the decimal ASCII value for 'a')\nconsole.log(buf.indexOf(Buffer.from('a buffer example')));\n// Prints: -1\nconsole.log(buf.indexOf(Buffer.from('a buffer example').slice(0, 8)));\n// Prints: 8\n\nconst utf16Buffer = Buffer.from('\\u039a\\u0391\\u03a3\\u03a3\\u0395', 'utf16le');\n\nconsole.log(utf16Buffer.indexOf('\\u03a3', 0, 'utf16le'));\n// Prints: 4\nconsole.log(utf16Buffer.indexOf('\\u03a3', -4, 'utf16le'));\n// Prints: 6\n
\n

If value is not a string, number, or Buffer, this method will throw a\nTypeError. If value is a number, it will be coerced to a valid byte value,\nan integer between 0 and 255.

\n

If byteOffset is not a number, it will be coerced to a number. If the result\nof coercion is NaN or 0, then the entire buffer will be searched. This\nbehavior matches String#indexOf().

\n
const b = Buffer.from('abcdef');\n\n// Passing a value that's a number, but not a valid byte.\n// Prints: 2, equivalent to searching for 99 or 'c'.\nconsole.log(b.indexOf(99.9));\nconsole.log(b.indexOf(256 + 99));\n\n// Passing a byteOffset that coerces to NaN or 0.\n// Prints: 1, searching the whole buffer.\nconsole.log(b.indexOf('b', undefined));\nconsole.log(b.indexOf('b', {}));\nconsole.log(b.indexOf('b', null));\nconsole.log(b.indexOf('b', []));\n
\n

If value is an empty string or empty Buffer and byteOffset is less\nthan buf.length, byteOffset will be returned. If value is empty and\nbyteOffset is at least buf.length, buf.length will be returned.

", "type": "module", "displayName": "`buf.indexOf(value[, byteOffset][, encoding])`" }, { "textRaw": "`buf.keys()`", "name": "`buf.keys()`", "meta": { "added": [ "v1.1.0" ], "changes": [] }, "desc": "\n

Creates and returns an iterator of buf keys (indices).

\n
const buf = Buffer.from('buffer');\n\nfor (const key of buf.keys()) {\n  console.log(key);\n}\n// Prints:\n//   0\n//   1\n//   2\n//   3\n//   4\n//   5\n
", "type": "module", "displayName": "`buf.keys()`" }, { "textRaw": "`buf.lastIndexOf(value[, byteOffset][, encoding])`", "name": "`buf.lastindexof(value[,_byteoffset][,_encoding])`", "meta": { "added": [ "v6.0.0" ], "changes": [ { "version": "v8.0.0", "pr-url": "https://github.com/nodejs/node/pull/10236", "description": "The `value` can now be a `Uint8Array`." } ] }, "desc": "\n

Identical to buf.indexOf(), except the last occurrence of value is found\nrather than the first occurrence.

\n
const buf = Buffer.from('this buffer is a buffer');\n\nconsole.log(buf.lastIndexOf('this'));\n// Prints: 0\nconsole.log(buf.lastIndexOf('buffer'));\n// Prints: 17\nconsole.log(buf.lastIndexOf(Buffer.from('buffer')));\n// Prints: 17\nconsole.log(buf.lastIndexOf(97));\n// Prints: 15 (97 is the decimal ASCII value for 'a')\nconsole.log(buf.lastIndexOf(Buffer.from('yolo')));\n// Prints: -1\nconsole.log(buf.lastIndexOf('buffer', 5));\n// Prints: 5\nconsole.log(buf.lastIndexOf('buffer', 4));\n// Prints: -1\n\nconst utf16Buffer = Buffer.from('\\u039a\\u0391\\u03a3\\u03a3\\u0395', 'utf16le');\n\nconsole.log(utf16Buffer.lastIndexOf('\\u03a3', undefined, 'utf16le'));\n// Prints: 6\nconsole.log(utf16Buffer.lastIndexOf('\\u03a3', -5, 'utf16le'));\n// Prints: 4\n
\n

If value is not a string, number, or Buffer, this method will throw a\nTypeError. If value is a number, it will be coerced to a valid byte value,\nan integer between 0 and 255.

\n

If byteOffset is not a number, it will be coerced to a number. Any arguments\nthat coerce to NaN, like {} or undefined, will search the whole buffer.\nThis behavior matches String#lastIndexOf().

\n
const b = Buffer.from('abcdef');\n\n// Passing a value that's a number, but not a valid byte.\n// Prints: 2, equivalent to searching for 99 or 'c'.\nconsole.log(b.lastIndexOf(99.9));\nconsole.log(b.lastIndexOf(256 + 99));\n\n// Passing a byteOffset that coerces to NaN.\n// Prints: 1, searching the whole buffer.\nconsole.log(b.lastIndexOf('b', undefined));\nconsole.log(b.lastIndexOf('b', {}));\n\n// Passing a byteOffset that coerces to 0.\n// Prints: -1, equivalent to passing 0.\nconsole.log(b.lastIndexOf('b', null));\nconsole.log(b.lastIndexOf('b', []));\n
\n

If value is an empty string or empty Buffer, byteOffset will be returned.

", "type": "module", "displayName": "`buf.lastIndexOf(value[, byteOffset][, encoding])`" }, { "textRaw": "`buf.length`", "name": "`buf.length`", "meta": { "added": [ "v0.1.90" ], "changes": [] }, "desc": "\n

Returns the amount of memory allocated for buf in bytes. This\ndoes not necessarily reflect the amount of \"usable\" data within buf.

\n
// Create a `Buffer` and write a shorter ASCII string to it.\n\nconst buf = Buffer.alloc(1234);\n\nconsole.log(buf.length);\n// Prints: 1234\n\nbuf.write('some string', 0, 'ascii');\n\nconsole.log(buf.length);\n// Prints: 1234\n
\n

While the length property is not immutable, changing the value of length\ncan result in undefined and inconsistent behavior. Applications that wish to\nmodify the length of a Buffer should therefore treat length as read-only and\nuse buf.slice() to create a new Buffer.

\n
let buf = Buffer.allocUnsafe(10);\n\nbuf.write('abcdefghj', 0, 'ascii');\n\nconsole.log(buf.length);\n// Prints: 10\n\nbuf = buf.slice(0, 5);\n\nconsole.log(buf.length);\n// Prints: 5\n
", "type": "module", "displayName": "`buf.length`" }, { "textRaw": "`buf.parent`", "name": "`buf.parent`", "meta": { "deprecated": [ "v8.0.0" ], "changes": [] }, "stability": 0, "stabilityText": "Deprecated: Use [`buf.buffer`][] instead.", "desc": "

The buf.parent property is a deprecated alias for buf.buffer.

", "type": "module", "displayName": "`buf.parent`" }, { "textRaw": "`buf.readBigInt64BE([offset])`", "name": "`buf.readbigint64be([offset])`", "meta": { "added": [ "v12.0.0" ], "changes": [] }, "desc": "\n

Reads a signed 64-bit integer from buf at the specified offset with\nthe specified endian format (readBigInt64BE() returns big endian,\nreadBigInt64LE() returns little endian).

\n

Integers read from a Buffer are interpreted as two's complement signed values.

", "type": "module", "displayName": "`buf.readBigInt64BE([offset])`" }, { "textRaw": "`buf.readBigInt64LE([offset])`", "name": "`buf.readbigint64le([offset])`", "meta": { "added": [ "v12.0.0" ], "changes": [] }, "desc": "\n

Reads a signed 64-bit integer from buf at the specified offset with\nthe specified endian format (readBigInt64BE() returns big endian,\nreadBigInt64LE() returns little endian).

\n

Integers read from a Buffer are interpreted as two's complement signed values.

", "type": "module", "displayName": "`buf.readBigInt64LE([offset])`" }, { "textRaw": "`buf.readBigUInt64BE([offset])`", "name": "`buf.readbiguint64be([offset])`", "meta": { "added": [ "v12.0.0" ], "changes": [] }, "desc": "\n

Reads an unsigned 64-bit integer from buf at the specified offset with\nspecified endian format (readBigUInt64BE() returns big endian,\nreadBigUInt64LE() returns little endian).

\n
const buf = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);\n\nconsole.log(buf.readBigUInt64BE(0));\n// Prints: 4294967295n\n\nconsole.log(buf.readBigUInt64LE(0));\n// Prints: 18446744069414584320n\n
", "type": "module", "displayName": "`buf.readBigUInt64BE([offset])`" }, { "textRaw": "`buf.readBigUInt64LE([offset])`", "name": "`buf.readbiguint64le([offset])`", "meta": { "added": [ "v12.0.0" ], "changes": [] }, "desc": "\n

Reads an unsigned 64-bit integer from buf at the specified offset with\nspecified endian format (readBigUInt64BE() returns big endian,\nreadBigUInt64LE() returns little endian).

\n
const buf = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);\n\nconsole.log(buf.readBigUInt64BE(0));\n// Prints: 4294967295n\n\nconsole.log(buf.readBigUInt64LE(0));\n// Prints: 18446744069414584320n\n
", "type": "module", "displayName": "`buf.readBigUInt64LE([offset])`" }, { "textRaw": "`buf.readDoubleBE([offset])`", "name": "`buf.readdoublebe([offset])`", "meta": { "added": [ "v0.11.15" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Reads a 64-bit double from buf at the specified offset with specified\nendian format (readDoubleBE() returns big endian, readDoubleLE() returns\nlittle endian).

\n
const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);\n\nconsole.log(buf.readDoubleBE(0));\n// Prints: 8.20788039913184e-304\nconsole.log(buf.readDoubleLE(0));\n// Prints: 5.447603722011605e-270\nconsole.log(buf.readDoubleLE(1));\n// Throws ERR_OUT_OF_RANGE.\n
", "type": "module", "displayName": "`buf.readDoubleBE([offset])`" }, { "textRaw": "`buf.readDoubleLE([offset])`", "name": "`buf.readdoublele([offset])`", "meta": { "added": [ "v0.11.15" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Reads a 64-bit double from buf at the specified offset with specified\nendian format (readDoubleBE() returns big endian, readDoubleLE() returns\nlittle endian).

\n
const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);\n\nconsole.log(buf.readDoubleBE(0));\n// Prints: 8.20788039913184e-304\nconsole.log(buf.readDoubleLE(0));\n// Prints: 5.447603722011605e-270\nconsole.log(buf.readDoubleLE(1));\n// Throws ERR_OUT_OF_RANGE.\n
", "type": "module", "displayName": "`buf.readDoubleLE([offset])`" }, { "textRaw": "`buf.readFloatBE([offset])`", "name": "`buf.readfloatbe([offset])`", "meta": { "added": [ "v0.11.15" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Reads a 32-bit float from buf at the specified offset with specified\nendian format (readFloatBE() returns big endian, readFloatLE() returns\nlittle endian).

\n
const buf = Buffer.from([1, 2, 3, 4]);\n\nconsole.log(buf.readFloatBE(0));\n// Prints: 2.387939260590663e-38\nconsole.log(buf.readFloatLE(0));\n// Prints: 1.539989614439558e-36\nconsole.log(buf.readFloatLE(1));\n// Throws ERR_OUT_OF_RANGE.\n
", "type": "module", "displayName": "`buf.readFloatBE([offset])`" }, { "textRaw": "`buf.readFloatLE([offset])`", "name": "`buf.readfloatle([offset])`", "meta": { "added": [ "v0.11.15" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Reads a 32-bit float from buf at the specified offset with specified\nendian format (readFloatBE() returns big endian, readFloatLE() returns\nlittle endian).

\n
const buf = Buffer.from([1, 2, 3, 4]);\n\nconsole.log(buf.readFloatBE(0));\n// Prints: 2.387939260590663e-38\nconsole.log(buf.readFloatLE(0));\n// Prints: 1.539989614439558e-36\nconsole.log(buf.readFloatLE(1));\n// Throws ERR_OUT_OF_RANGE.\n
", "type": "module", "displayName": "`buf.readFloatLE([offset])`" }, { "textRaw": "`buf.readInt8([offset])`", "name": "`buf.readint8([offset])`", "meta": { "added": [ "v0.5.0" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Reads a signed 8-bit integer from buf at the specified offset.

\n

Integers read from a Buffer are interpreted as two's complement signed values.

\n
const buf = Buffer.from([-1, 5]);\n\nconsole.log(buf.readInt8(0));\n// Prints: -1\nconsole.log(buf.readInt8(1));\n// Prints: 5\nconsole.log(buf.readInt8(2));\n// Throws ERR_OUT_OF_RANGE.\n
", "type": "module", "displayName": "`buf.readInt8([offset])`" }, { "textRaw": "`buf.readInt16BE([offset])`", "name": "`buf.readint16be([offset])`", "meta": { "added": [ "v0.5.5" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Reads a signed 16-bit integer from buf at the specified offset with\nthe specified endian format (readInt16BE() returns big endian,\nreadInt16LE() returns little endian).

\n

Integers read from a Buffer are interpreted as two's complement signed values.

\n
const buf = Buffer.from([0, 5]);\n\nconsole.log(buf.readInt16BE(0));\n// Prints: 5\nconsole.log(buf.readInt16LE(0));\n// Prints: 1280\nconsole.log(buf.readInt16LE(1));\n// Throws ERR_OUT_OF_RANGE.\n
", "type": "module", "displayName": "`buf.readInt16BE([offset])`" }, { "textRaw": "`buf.readInt16LE([offset])`", "name": "`buf.readint16le([offset])`", "meta": { "added": [ "v0.5.5" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Reads a signed 16-bit integer from buf at the specified offset with\nthe specified endian format (readInt16BE() returns big endian,\nreadInt16LE() returns little endian).

\n

Integers read from a Buffer are interpreted as two's complement signed values.

\n
const buf = Buffer.from([0, 5]);\n\nconsole.log(buf.readInt16BE(0));\n// Prints: 5\nconsole.log(buf.readInt16LE(0));\n// Prints: 1280\nconsole.log(buf.readInt16LE(1));\n// Throws ERR_OUT_OF_RANGE.\n
", "type": "module", "displayName": "`buf.readInt16LE([offset])`" }, { "textRaw": "`buf.readInt32BE([offset])`", "name": "`buf.readint32be([offset])`", "meta": { "added": [ "v0.5.5" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Reads a signed 32-bit integer from buf at the specified offset with\nthe specified endian format (readInt32BE() returns big endian,\nreadInt32LE() returns little endian).

\n

Integers read from a Buffer are interpreted as two's complement signed values.

\n
const buf = Buffer.from([0, 0, 0, 5]);\n\nconsole.log(buf.readInt32BE(0));\n// Prints: 5\nconsole.log(buf.readInt32LE(0));\n// Prints: 83886080\nconsole.log(buf.readInt32LE(1));\n// Throws ERR_OUT_OF_RANGE.\n
", "type": "module", "displayName": "`buf.readInt32BE([offset])`" }, { "textRaw": "`buf.readInt32LE([offset])`", "name": "`buf.readint32le([offset])`", "meta": { "added": [ "v0.5.5" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Reads a signed 32-bit integer from buf at the specified offset with\nthe specified endian format (readInt32BE() returns big endian,\nreadInt32LE() returns little endian).

\n

Integers read from a Buffer are interpreted as two's complement signed values.

\n
const buf = Buffer.from([0, 0, 0, 5]);\n\nconsole.log(buf.readInt32BE(0));\n// Prints: 5\nconsole.log(buf.readInt32LE(0));\n// Prints: 83886080\nconsole.log(buf.readInt32LE(1));\n// Throws ERR_OUT_OF_RANGE.\n
", "type": "module", "displayName": "`buf.readInt32LE([offset])`" }, { "textRaw": "`buf.readIntBE(offset, byteLength)`", "name": "`buf.readintbe(offset,_bytelength)`", "meta": { "added": [ "v0.11.15" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset and `byteLength` to `uint32` anymore." } ] }, "desc": "\n

Reads byteLength number of bytes from buf at the specified offset\nand interprets the result as a two's complement signed value. Supports up to 48\nbits of accuracy.

\n
const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);\n\nconsole.log(buf.readIntLE(0, 6).toString(16));\n// Prints: -546f87a9cbee\nconsole.log(buf.readIntBE(0, 6).toString(16));\n// Prints: 1234567890ab\nconsole.log(buf.readIntBE(1, 6).toString(16));\n// Throws ERR_OUT_OF_RANGE.\nconsole.log(buf.readIntBE(1, 0).toString(16));\n// Throws ERR_OUT_OF_RANGE.\n
", "type": "module", "displayName": "`buf.readIntBE(offset, byteLength)`" }, { "textRaw": "`buf.readIntLE(offset, byteLength)`", "name": "`buf.readintle(offset,_bytelength)`", "meta": { "added": [ "v0.11.15" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset and `byteLength` to `uint32` anymore." } ] }, "desc": "\n

Reads byteLength number of bytes from buf at the specified offset\nand interprets the result as a two's complement signed value. Supports up to 48\nbits of accuracy.

\n
const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);\n\nconsole.log(buf.readIntLE(0, 6).toString(16));\n// Prints: -546f87a9cbee\nconsole.log(buf.readIntBE(0, 6).toString(16));\n// Prints: 1234567890ab\nconsole.log(buf.readIntBE(1, 6).toString(16));\n// Throws ERR_OUT_OF_RANGE.\nconsole.log(buf.readIntBE(1, 0).toString(16));\n// Throws ERR_OUT_OF_RANGE.\n
", "type": "module", "displayName": "`buf.readIntLE(offset, byteLength)`" }, { "textRaw": "`buf.readUInt8([offset])`", "name": "`buf.readuint8([offset])`", "meta": { "added": [ "v0.5.0" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Reads an unsigned 8-bit integer from buf at the specified offset.

\n
const buf = Buffer.from([1, -2]);\n\nconsole.log(buf.readUInt8(0));\n// Prints: 1\nconsole.log(buf.readUInt8(1));\n// Prints: 254\nconsole.log(buf.readUInt8(2));\n// Throws ERR_OUT_OF_RANGE.\n
", "type": "module", "displayName": "`buf.readUInt8([offset])`" }, { "textRaw": "`buf.readUInt16BE([offset])`", "name": "`buf.readuint16be([offset])`", "meta": { "added": [ "v0.5.5" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Reads an unsigned 16-bit integer from buf at the specified offset with\nspecified endian format (readUInt16BE() returns big endian, readUInt16LE()\nreturns little endian).

\n
const buf = Buffer.from([0x12, 0x34, 0x56]);\n\nconsole.log(buf.readUInt16BE(0).toString(16));\n// Prints: 1234\nconsole.log(buf.readUInt16LE(0).toString(16));\n// Prints: 3412\nconsole.log(buf.readUInt16BE(1).toString(16));\n// Prints: 3456\nconsole.log(buf.readUInt16LE(1).toString(16));\n// Prints: 5634\nconsole.log(buf.readUInt16LE(2).toString(16));\n// Throws ERR_OUT_OF_RANGE.\n
", "type": "module", "displayName": "`buf.readUInt16BE([offset])`" }, { "textRaw": "`buf.readUInt16LE([offset])`", "name": "`buf.readuint16le([offset])`", "meta": { "added": [ "v0.5.5" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Reads an unsigned 16-bit integer from buf at the specified offset with\nspecified endian format (readUInt16BE() returns big endian, readUInt16LE()\nreturns little endian).

\n
const buf = Buffer.from([0x12, 0x34, 0x56]);\n\nconsole.log(buf.readUInt16BE(0).toString(16));\n// Prints: 1234\nconsole.log(buf.readUInt16LE(0).toString(16));\n// Prints: 3412\nconsole.log(buf.readUInt16BE(1).toString(16));\n// Prints: 3456\nconsole.log(buf.readUInt16LE(1).toString(16));\n// Prints: 5634\nconsole.log(buf.readUInt16LE(2).toString(16));\n// Throws ERR_OUT_OF_RANGE.\n
", "type": "module", "displayName": "`buf.readUInt16LE([offset])`" }, { "textRaw": "`buf.readUInt32BE([offset])`", "name": "`buf.readuint32be([offset])`", "meta": { "added": [ "v0.5.5" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Reads an unsigned 32-bit integer from buf at the specified offset with\nspecified endian format (readUInt32BE() returns big endian,\nreadUInt32LE() returns little endian).

\n
const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);\n\nconsole.log(buf.readUInt32BE(0).toString(16));\n// Prints: 12345678\nconsole.log(buf.readUInt32LE(0).toString(16));\n// Prints: 78563412\nconsole.log(buf.readUInt32LE(1).toString(16));\n// Throws ERR_OUT_OF_RANGE.\n
", "type": "module", "displayName": "`buf.readUInt32BE([offset])`" }, { "textRaw": "`buf.readUInt32LE([offset])`", "name": "`buf.readuint32le([offset])`", "meta": { "added": [ "v0.5.5" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Reads an unsigned 32-bit integer from buf at the specified offset with\nspecified endian format (readUInt32BE() returns big endian,\nreadUInt32LE() returns little endian).

\n
const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);\n\nconsole.log(buf.readUInt32BE(0).toString(16));\n// Prints: 12345678\nconsole.log(buf.readUInt32LE(0).toString(16));\n// Prints: 78563412\nconsole.log(buf.readUInt32LE(1).toString(16));\n// Throws ERR_OUT_OF_RANGE.\n
", "type": "module", "displayName": "`buf.readUInt32LE([offset])`" }, { "textRaw": "`buf.readUIntBE(offset, byteLength)`", "name": "`buf.readuintbe(offset,_bytelength)`", "meta": { "added": [ "v0.11.15" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset and `byteLength` to `uint32` anymore." } ] }, "desc": "\n

Reads byteLength number of bytes from buf at the specified offset\nand interprets the result as an unsigned integer. Supports up to 48\nbits of accuracy.

\n
const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);\n\nconsole.log(buf.readUIntBE(0, 6).toString(16));\n// Prints: 1234567890ab\nconsole.log(buf.readUIntLE(0, 6).toString(16));\n// Prints: ab9078563412\nconsole.log(buf.readUIntBE(1, 6).toString(16));\n// Throws ERR_OUT_OF_RANGE.\n
", "type": "module", "displayName": "`buf.readUIntBE(offset, byteLength)`" }, { "textRaw": "`buf.readUIntLE(offset, byteLength)`", "name": "`buf.readuintle(offset,_bytelength)`", "meta": { "added": [ "v0.11.15" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset and `byteLength` to `uint32` anymore." } ] }, "desc": "\n

Reads byteLength number of bytes from buf at the specified offset\nand interprets the result as an unsigned integer. Supports up to 48\nbits of accuracy.

\n
const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);\n\nconsole.log(buf.readUIntBE(0, 6).toString(16));\n// Prints: 1234567890ab\nconsole.log(buf.readUIntLE(0, 6).toString(16));\n// Prints: ab9078563412\nconsole.log(buf.readUIntBE(1, 6).toString(16));\n// Throws ERR_OUT_OF_RANGE.\n
", "type": "module", "displayName": "`buf.readUIntLE(offset, byteLength)`" }, { "textRaw": "`buf.subarray([start[, end]])`", "name": "`buf.subarray([start[,_end]])`", "meta": { "added": [ "v3.0.0" ], "changes": [] }, "desc": "\n

Returns a new Buffer that references the same memory as the original, but\noffset and cropped by the start and end indices.

\n

Specifying end greater than buf.length will return the same result as\nthat of end equal to buf.length.

\n

Modifying the new Buffer slice will modify the memory in the original Buffer\nbecause the allocated memory of the two objects overlap.

\n
// Create a `Buffer` with the ASCII alphabet, take a slice, and modify one byte\n// from the original `Buffer`.\n\nconst buf1 = Buffer.allocUnsafe(26);\n\nfor (let i = 0; i < 26; i++) {\n  // 97 is the decimal ASCII value for 'a'.\n  buf1[i] = i + 97;\n}\n\nconst buf2 = buf1.subarray(0, 3);\n\nconsole.log(buf2.toString('ascii', 0, buf2.length));\n// Prints: abc\n\nbuf1[0] = 33;\n\nconsole.log(buf2.toString('ascii', 0, buf2.length));\n// Prints: !bc\n
\n

Specifying negative indexes causes the slice to be generated relative to the\nend of buf rather than the beginning.

\n
const buf = Buffer.from('buffer');\n\nconsole.log(buf.subarray(-6, -1).toString());\n// Prints: buffe\n// (Equivalent to buf.subarray(0, 5).)\n\nconsole.log(buf.subarray(-6, -2).toString());\n// Prints: buff\n// (Equivalent to buf.subarray(0, 4).)\n\nconsole.log(buf.subarray(-5, -2).toString());\n// Prints: uff\n// (Equivalent to buf.subarray(1, 4).)\n
", "type": "module", "displayName": "`buf.subarray([start[, end]])`" }, { "textRaw": "`buf.slice([start[, end]])`", "name": "`buf.slice([start[,_end]])`", "meta": { "added": [ "v0.3.0" ], "changes": [ { "version": "v7.1.0, v6.9.2", "pr-url": "https://github.com/nodejs/node/pull/9341", "description": "Coercing the offsets to integers now handles values outside the 32-bit integer range properly." }, { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/9101", "description": "All offsets are now coerced to integers before doing any calculations with them." } ] }, "desc": "\n

Returns a new Buffer that references the same memory as the original, but\noffset and cropped by the start and end indices.

\n

This is the same behavior as buf.subarray().

\n

This method is not compatible with the Uint8Array.prototype.slice(),\nwhich is a superclass of Buffer. To copy the slice, use\nUint8Array.prototype.slice().

\n
const buf = Buffer.from('buffer');\n\nconst copiedBuf = Uint8Array.prototype.slice.call(buf);\ncopiedBuf[0]++;\nconsole.log(copiedBuf.toString());\n// Prints: cuffer\n\nconsole.log(buf.toString());\n// Prints: buffer\n
", "type": "module", "displayName": "`buf.slice([start[, end]])`" }, { "textRaw": "`buf.swap16()`", "name": "`buf.swap16()`", "meta": { "added": [ "v5.10.0" ], "changes": [] }, "desc": "\n

Interprets buf as an array of unsigned 16-bit integers and swaps the\nbyte order in-place. Throws ERR_INVALID_BUFFER_SIZE if buf.length\nis not a multiple of 2.

\n
const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);\n\nconsole.log(buf1);\n// Prints: <Buffer 01 02 03 04 05 06 07 08>\n\nbuf1.swap16();\n\nconsole.log(buf1);\n// Prints: <Buffer 02 01 04 03 06 05 08 07>\n\nconst buf2 = Buffer.from([0x1, 0x2, 0x3]);\n\nbuf2.swap16();\n// Throws ERR_INVALID_BUFFER_SIZE.\n
\n

One convenient use of buf.swap16() is to perform a fast in-place conversion\nbetween UTF-16 little-endian and UTF-16 big-endian:

\n
const buf = Buffer.from('This is little-endian UTF-16', 'utf16le');\nbuf.swap16(); // Convert to big-endian UTF-16 text.\n
", "type": "module", "displayName": "`buf.swap16()`" }, { "textRaw": "`buf.swap32()`", "name": "`buf.swap32()`", "meta": { "added": [ "v5.10.0" ], "changes": [] }, "desc": "\n

Interprets buf as an array of unsigned 32-bit integers and swaps the\nbyte order in-place. Throws ERR_INVALID_BUFFER_SIZE if buf.length\nis not a multiple of 4.

\n
const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);\n\nconsole.log(buf1);\n// Prints: <Buffer 01 02 03 04 05 06 07 08>\n\nbuf1.swap32();\n\nconsole.log(buf1);\n// Prints: <Buffer 04 03 02 01 08 07 06 05>\n\nconst buf2 = Buffer.from([0x1, 0x2, 0x3]);\n\nbuf2.swap32();\n// Throws ERR_INVALID_BUFFER_SIZE.\n
", "type": "module", "displayName": "`buf.swap32()`" }, { "textRaw": "`buf.swap64()`", "name": "`buf.swap64()`", "meta": { "added": [ "v6.3.0" ], "changes": [] }, "desc": "\n

Interprets buf as an array of 64-bit numbers and swaps byte order in-place.\nThrows ERR_INVALID_BUFFER_SIZE if buf.length is not a multiple of 8.

\n
const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);\n\nconsole.log(buf1);\n// Prints: <Buffer 01 02 03 04 05 06 07 08>\n\nbuf1.swap64();\n\nconsole.log(buf1);\n// Prints: <Buffer 08 07 06 05 04 03 02 01>\n\nconst buf2 = Buffer.from([0x1, 0x2, 0x3]);\n\nbuf2.swap64();\n// Throws ERR_INVALID_BUFFER_SIZE.\n
\n

JavaScript cannot encode 64-bit integers. This method is intended\nfor working with 64-bit floats.

", "type": "module", "displayName": "`buf.swap64()`" }, { "textRaw": "`buf.toJSON()`", "name": "`buf.tojson()`", "meta": { "added": [ "v0.9.2" ], "changes": [] }, "desc": "\n

Returns a JSON representation of buf. JSON.stringify() implicitly calls\nthis function when stringifying a Buffer instance.

\n
const buf = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5]);\nconst json = JSON.stringify(buf);\n\nconsole.log(json);\n// Prints: {\"type\":\"Buffer\",\"data\":[1,2,3,4,5]}\n\nconst copy = JSON.parse(json, (key, value) => {\n  return value && value.type === 'Buffer' ?\n    Buffer.from(value.data) :\n    value;\n});\n\nconsole.log(copy);\n// Prints: <Buffer 01 02 03 04 05>\n
", "type": "module", "displayName": "`buf.toJSON()`" }, { "textRaw": "`buf.toString([encoding[, start[, end]]])`", "name": "`buf.tostring([encoding[,_start[,_end]]])`", "meta": { "added": [ "v0.1.90" ], "changes": [] }, "desc": "\n

Decodes buf to a string according to the specified character encoding in\nencoding. start and end may be passed to decode only a subset of buf.\nIf a byte sequence in the input is not valid in the given encoding then\nit is replaced with the replacement character U+FFFD.

\n

The maximum length of a string instance (in UTF-16 code units) is available\nas buffer.constants.MAX_STRING_LENGTH.

\n
const buf1 = Buffer.allocUnsafe(26);\n\nfor (let i = 0; i < 26; i++) {\n  // 97 is the decimal ASCII value for 'a'.\n  buf1[i] = i + 97;\n}\n\nconsole.log(buf1.toString('ascii'));\n// Prints: abcdefghijklmnopqrstuvwxyz\nconsole.log(buf1.toString('ascii', 0, 5));\n// Prints: abcde\n\nconst buf2 = Buffer.from('tést');\n\nconsole.log(buf2.toString('hex'));\n// Prints: 74c3a97374\nconsole.log(buf2.toString('utf8', 0, 3));\n// Prints: té\nconsole.log(buf2.toString(undefined, 0, 3));\n// Prints: té\n
", "type": "module", "displayName": "`buf.toString([encoding[, start[, end]]])`" }, { "textRaw": "`buf.values()`", "name": "`buf.values()`", "meta": { "added": [ "v1.1.0" ], "changes": [] }, "desc": "\n

Creates and returns an iterator for buf values (bytes). This function is\ncalled automatically when a Buffer is used in a for..of statement.

\n
const buf = Buffer.from('buffer');\n\nfor (const value of buf.values()) {\n  console.log(value);\n}\n// Prints:\n//   98\n//   117\n//   102\n//   102\n//   101\n//   114\n\nfor (const value of buf) {\n  console.log(value);\n}\n// Prints:\n//   98\n//   117\n//   102\n//   102\n//   101\n//   114\n
", "type": "module", "displayName": "`buf.values()`" }, { "textRaw": "`buf.write(string[, offset[, length]][, encoding])`", "name": "`buf.write(string[,_offset[,_length]][,_encoding])`", "meta": { "added": [ "v0.1.90" ], "changes": [] }, "desc": "\n

Writes string to buf at offset according to the character encoding in\nencoding. The length parameter is the number of bytes to write. If buf did\nnot contain enough space to fit the entire string, only part of string will be\nwritten. However, partially encoded characters will not be written.

\n
const buf = Buffer.alloc(256);\n\nconst len = buf.write('\\u00bd + \\u00bc = \\u00be', 0);\n\nconsole.log(`${len} bytes: ${buf.toString('utf8', 0, len)}`);\n// Prints: 12 bytes: ½ + ¼ = ¾\n
", "type": "module", "displayName": "`buf.write(string[, offset[, length]][, encoding])`" }, { "textRaw": "`buf.writeBigInt64BE(value[, offset])`", "name": "`buf.writebigint64be(value[,_offset])`", "meta": { "added": [ "v12.0.0" ], "changes": [] }, "desc": "\n

Writes value to buf at the specified offset with specified endian\nformat (writeBigInt64BE() writes big endian, writeBigInt64LE() writes little\nendian).

\n

value is interpreted and written as a two's complement signed integer.

\n
const buf = Buffer.allocUnsafe(8);\n\nbuf.writeBigInt64BE(0x0102030405060708n, 0);\n\nconsole.log(buf);\n// Prints: <Buffer 01 02 03 04 05 06 07 08>\n
", "type": "module", "displayName": "`buf.writeBigInt64BE(value[, offset])`" }, { "textRaw": "`buf.writeBigInt64LE(value[, offset])`", "name": "`buf.writebigint64le(value[,_offset])`", "meta": { "added": [ "v12.0.0" ], "changes": [] }, "desc": "\n

Writes value to buf at the specified offset with specified endian\nformat (writeBigInt64BE() writes big endian, writeBigInt64LE() writes little\nendian).

\n

value is interpreted and written as a two's complement signed integer.

\n
const buf = Buffer.allocUnsafe(8);\n\nbuf.writeBigInt64BE(0x0102030405060708n, 0);\n\nconsole.log(buf);\n// Prints: <Buffer 01 02 03 04 05 06 07 08>\n
", "type": "module", "displayName": "`buf.writeBigInt64LE(value[, offset])`" }, { "textRaw": "`buf.writeBigUInt64BE(value[, offset])`", "name": "`buf.writebiguint64be(value[,_offset])`", "meta": { "added": [ "v12.0.0" ], "changes": [] }, "desc": "\n

Writes value to buf at the specified offset with specified endian\nformat (writeBigUInt64BE() writes big endian, writeBigUInt64LE() writes\nlittle endian).

\n
const buf = Buffer.allocUnsafe(8);\n\nbuf.writeBigUInt64LE(0xdecafafecacefaden, 0);\n\nconsole.log(buf);\n// Prints: <Buffer de fa ce ca fe fa ca de>\n
", "type": "module", "displayName": "`buf.writeBigUInt64BE(value[, offset])`" }, { "textRaw": "`buf.writeBigUInt64LE(value[, offset])`", "name": "`buf.writebiguint64le(value[,_offset])`", "meta": { "added": [ "v12.0.0" ], "changes": [] }, "desc": "\n

Writes value to buf at the specified offset with specified endian\nformat (writeBigUInt64BE() writes big endian, writeBigUInt64LE() writes\nlittle endian).

\n
const buf = Buffer.allocUnsafe(8);\n\nbuf.writeBigUInt64LE(0xdecafafecacefaden, 0);\n\nconsole.log(buf);\n// Prints: <Buffer de fa ce ca fe fa ca de>\n
", "type": "module", "displayName": "`buf.writeBigUInt64LE(value[, offset])`" }, { "textRaw": "`buf.writeDoubleBE(value[, offset])`", "name": "`buf.writedoublebe(value[,_offset])`", "meta": { "added": [ "v0.11.15" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Writes value to buf at the specified offset with specified endian\nformat (writeDoubleBE() writes big endian, writeDoubleLE() writes little\nendian). value should be a valid 64-bit double. Behavior is undefined when\nvalue is anything other than a 64-bit double.

\n
const buf = Buffer.allocUnsafe(8);\n\nbuf.writeDoubleBE(123.456, 0);\n\nconsole.log(buf);\n// Prints: <Buffer 40 5e dd 2f 1a 9f be 77>\n\nbuf.writeDoubleLE(123.456, 0);\n\nconsole.log(buf);\n// Prints: <Buffer 77 be 9f 1a 2f dd 5e 40>\n
", "type": "module", "displayName": "`buf.writeDoubleBE(value[, offset])`" }, { "textRaw": "`buf.writeDoubleLE(value[, offset])`", "name": "`buf.writedoublele(value[,_offset])`", "meta": { "added": [ "v0.11.15" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Writes value to buf at the specified offset with specified endian\nformat (writeDoubleBE() writes big endian, writeDoubleLE() writes little\nendian). value should be a valid 64-bit double. Behavior is undefined when\nvalue is anything other than a 64-bit double.

\n
const buf = Buffer.allocUnsafe(8);\n\nbuf.writeDoubleBE(123.456, 0);\n\nconsole.log(buf);\n// Prints: <Buffer 40 5e dd 2f 1a 9f be 77>\n\nbuf.writeDoubleLE(123.456, 0);\n\nconsole.log(buf);\n// Prints: <Buffer 77 be 9f 1a 2f dd 5e 40>\n
", "type": "module", "displayName": "`buf.writeDoubleLE(value[, offset])`" }, { "textRaw": "`buf.writeFloatBE(value[, offset])`", "name": "`buf.writefloatbe(value[,_offset])`", "meta": { "added": [ "v0.11.15" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Writes value to buf at the specified offset with specified endian\nformat (writeFloatBE() writes big endian, writeFloatLE() writes little\nendian). value should be a valid 32-bit float. Behavior is undefined when\nvalue is anything other than a 32-bit float.

\n
const buf = Buffer.allocUnsafe(4);\n\nbuf.writeFloatBE(0xcafebabe, 0);\n\nconsole.log(buf);\n// Prints: <Buffer 4f 4a fe bb>\n\nbuf.writeFloatLE(0xcafebabe, 0);\n\nconsole.log(buf);\n// Prints: <Buffer bb fe 4a 4f>\n
", "type": "module", "displayName": "`buf.writeFloatBE(value[, offset])`" }, { "textRaw": "`buf.writeFloatLE(value[, offset])`", "name": "`buf.writefloatle(value[,_offset])`", "meta": { "added": [ "v0.11.15" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Writes value to buf at the specified offset with specified endian\nformat (writeFloatBE() writes big endian, writeFloatLE() writes little\nendian). value should be a valid 32-bit float. Behavior is undefined when\nvalue is anything other than a 32-bit float.

\n
const buf = Buffer.allocUnsafe(4);\n\nbuf.writeFloatBE(0xcafebabe, 0);\n\nconsole.log(buf);\n// Prints: <Buffer 4f 4a fe bb>\n\nbuf.writeFloatLE(0xcafebabe, 0);\n\nconsole.log(buf);\n// Prints: <Buffer bb fe 4a 4f>\n
", "type": "module", "displayName": "`buf.writeFloatLE(value[, offset])`" }, { "textRaw": "`buf.writeInt8(value[, offset])`", "name": "`buf.writeint8(value[,_offset])`", "meta": { "added": [ "v0.5.0" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Writes value to buf at the specified offset. value should be a valid\nsigned 8-bit integer. Behavior is undefined when value is anything other than\na signed 8-bit integer.

\n

value is interpreted and written as a two's complement signed integer.

\n
const buf = Buffer.allocUnsafe(2);\n\nbuf.writeInt8(2, 0);\nbuf.writeInt8(-2, 1);\n\nconsole.log(buf);\n// Prints: <Buffer 02 fe>\n
", "type": "module", "displayName": "`buf.writeInt8(value[, offset])`" }, { "textRaw": "`buf.writeInt16BE(value[, offset])`", "name": "`buf.writeint16be(value[,_offset])`", "meta": { "added": [ "v0.5.5" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Writes value to buf at the specified offset with specified endian\nformat (writeInt16BE() writes big endian, writeInt16LE() writes little\nendian). value should be a valid signed 16-bit integer. Behavior is\nundefined when value is anything other than a signed 16-bit integer.

\n

value is interpreted and written as a two's complement signed integer.

\n
const buf = Buffer.allocUnsafe(4);\n\nbuf.writeInt16BE(0x0102, 0);\nbuf.writeInt16LE(0x0304, 2);\n\nconsole.log(buf);\n// Prints: <Buffer 01 02 04 03>\n
", "type": "module", "displayName": "`buf.writeInt16BE(value[, offset])`" }, { "textRaw": "`buf.writeInt16LE(value[, offset])`", "name": "`buf.writeint16le(value[,_offset])`", "meta": { "added": [ "v0.5.5" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Writes value to buf at the specified offset with specified endian\nformat (writeInt16BE() writes big endian, writeInt16LE() writes little\nendian). value should be a valid signed 16-bit integer. Behavior is\nundefined when value is anything other than a signed 16-bit integer.

\n

value is interpreted and written as a two's complement signed integer.

\n
const buf = Buffer.allocUnsafe(4);\n\nbuf.writeInt16BE(0x0102, 0);\nbuf.writeInt16LE(0x0304, 2);\n\nconsole.log(buf);\n// Prints: <Buffer 01 02 04 03>\n
", "type": "module", "displayName": "`buf.writeInt16LE(value[, offset])`" }, { "textRaw": "`buf.writeInt32BE(value[, offset])`", "name": "`buf.writeint32be(value[,_offset])`", "meta": { "added": [ "v0.5.5" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Writes value to buf at the specified offset with specified endian\nformat (writeInt32BE() writes big endian, writeInt32LE() writes little\nendian). value should be a valid signed 32-bit integer. Behavior is\nundefined when value is anything other than a signed 32-bit integer.

\n

value is interpreted and written as a two's complement signed integer.

\n
const buf = Buffer.allocUnsafe(8);\n\nbuf.writeInt32BE(0x01020304, 0);\nbuf.writeInt32LE(0x05060708, 4);\n\nconsole.log(buf);\n// Prints: <Buffer 01 02 03 04 08 07 06 05>\n
", "type": "module", "displayName": "`buf.writeInt32BE(value[, offset])`" }, { "textRaw": "`buf.writeInt32LE(value[, offset])`", "name": "`buf.writeint32le(value[,_offset])`", "meta": { "added": [ "v0.5.5" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Writes value to buf at the specified offset with specified endian\nformat (writeInt32BE() writes big endian, writeInt32LE() writes little\nendian). value should be a valid signed 32-bit integer. Behavior is\nundefined when value is anything other than a signed 32-bit integer.

\n

value is interpreted and written as a two's complement signed integer.

\n
const buf = Buffer.allocUnsafe(8);\n\nbuf.writeInt32BE(0x01020304, 0);\nbuf.writeInt32LE(0x05060708, 4);\n\nconsole.log(buf);\n// Prints: <Buffer 01 02 03 04 08 07 06 05>\n
", "type": "module", "displayName": "`buf.writeInt32LE(value[, offset])`" }, { "textRaw": "`buf.writeIntBE(value, offset, byteLength)`", "name": "`buf.writeintbe(value,_offset,_bytelength)`", "meta": { "added": [ "v0.11.15" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset and `byteLength` to `uint32` anymore." } ] }, "desc": "\n

Writes byteLength bytes of value to buf at the specified offset.\nSupports up to 48 bits of accuracy. Behavior is undefined when value is\nanything other than a signed integer.

\n
const buf = Buffer.allocUnsafe(6);\n\nbuf.writeIntBE(0x1234567890ab, 0, 6);\n\nconsole.log(buf);\n// Prints: <Buffer 12 34 56 78 90 ab>\n\nbuf.writeIntLE(0x1234567890ab, 0, 6);\n\nconsole.log(buf);\n// Prints: <Buffer ab 90 78 56 34 12>\n
", "type": "module", "displayName": "`buf.writeIntBE(value, offset, byteLength)`" }, { "textRaw": "`buf.writeIntLE(value, offset, byteLength)`", "name": "`buf.writeintle(value,_offset,_bytelength)`", "meta": { "added": [ "v0.11.15" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset and `byteLength` to `uint32` anymore." } ] }, "desc": "\n

Writes byteLength bytes of value to buf at the specified offset.\nSupports up to 48 bits of accuracy. Behavior is undefined when value is\nanything other than a signed integer.

\n
const buf = Buffer.allocUnsafe(6);\n\nbuf.writeIntBE(0x1234567890ab, 0, 6);\n\nconsole.log(buf);\n// Prints: <Buffer 12 34 56 78 90 ab>\n\nbuf.writeIntLE(0x1234567890ab, 0, 6);\n\nconsole.log(buf);\n// Prints: <Buffer ab 90 78 56 34 12>\n
", "type": "module", "displayName": "`buf.writeIntLE(value, offset, byteLength)`" }, { "textRaw": "`buf.writeUInt8(value[, offset])`", "name": "`buf.writeuint8(value[,_offset])`", "meta": { "added": [ "v0.5.0" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Writes value to buf at the specified offset. value should be a\nvalid unsigned 8-bit integer. Behavior is undefined when value is anything\nother than an unsigned 8-bit integer.

\n
const buf = Buffer.allocUnsafe(4);\n\nbuf.writeUInt8(0x3, 0);\nbuf.writeUInt8(0x4, 1);\nbuf.writeUInt8(0x23, 2);\nbuf.writeUInt8(0x42, 3);\n\nconsole.log(buf);\n// Prints: <Buffer 03 04 23 42>\n
", "type": "module", "displayName": "`buf.writeUInt8(value[, offset])`" }, { "textRaw": "`buf.writeUInt16BE(value[, offset])`", "name": "`buf.writeuint16be(value[,_offset])`", "meta": { "added": [ "v0.5.5" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Writes value to buf at the specified offset with specified endian\nformat (writeUInt16BE() writes big endian, writeUInt16LE() writes little\nendian). value should be a valid unsigned 16-bit integer. Behavior is\nundefined when value is anything other than an unsigned 16-bit integer.

\n
const buf = Buffer.allocUnsafe(4);\n\nbuf.writeUInt16BE(0xdead, 0);\nbuf.writeUInt16BE(0xbeef, 2);\n\nconsole.log(buf);\n// Prints: <Buffer de ad be ef>\n\nbuf.writeUInt16LE(0xdead, 0);\nbuf.writeUInt16LE(0xbeef, 2);\n\nconsole.log(buf);\n// Prints: <Buffer ad de ef be>\n
", "type": "module", "displayName": "`buf.writeUInt16BE(value[, offset])`" }, { "textRaw": "`buf.writeUInt16LE(value[, offset])`", "name": "`buf.writeuint16le(value[,_offset])`", "meta": { "added": [ "v0.5.5" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Writes value to buf at the specified offset with specified endian\nformat (writeUInt16BE() writes big endian, writeUInt16LE() writes little\nendian). value should be a valid unsigned 16-bit integer. Behavior is\nundefined when value is anything other than an unsigned 16-bit integer.

\n
const buf = Buffer.allocUnsafe(4);\n\nbuf.writeUInt16BE(0xdead, 0);\nbuf.writeUInt16BE(0xbeef, 2);\n\nconsole.log(buf);\n// Prints: <Buffer de ad be ef>\n\nbuf.writeUInt16LE(0xdead, 0);\nbuf.writeUInt16LE(0xbeef, 2);\n\nconsole.log(buf);\n// Prints: <Buffer ad de ef be>\n
", "type": "module", "displayName": "`buf.writeUInt16LE(value[, offset])`" }, { "textRaw": "`buf.writeUInt32BE(value[, offset])`", "name": "`buf.writeuint32be(value[,_offset])`", "meta": { "added": [ "v0.5.5" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Writes value to buf at the specified offset with specified endian\nformat (writeUInt32BE() writes big endian, writeUInt32LE() writes little\nendian). value should be a valid unsigned 32-bit integer. Behavior is\nundefined when value is anything other than an unsigned 32-bit integer.

\n
const buf = Buffer.allocUnsafe(4);\n\nbuf.writeUInt32BE(0xfeedface, 0);\n\nconsole.log(buf);\n// Prints: <Buffer fe ed fa ce>\n\nbuf.writeUInt32LE(0xfeedface, 0);\n\nconsole.log(buf);\n// Prints: <Buffer ce fa ed fe>\n
", "type": "module", "displayName": "`buf.writeUInt32BE(value[, offset])`" }, { "textRaw": "`buf.writeUInt32LE(value[, offset])`", "name": "`buf.writeuint32le(value[,_offset])`", "meta": { "added": [ "v0.5.5" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore." } ] }, "desc": "\n

Writes value to buf at the specified offset with specified endian\nformat (writeUInt32BE() writes big endian, writeUInt32LE() writes little\nendian). value should be a valid unsigned 32-bit integer. Behavior is\nundefined when value is anything other than an unsigned 32-bit integer.

\n
const buf = Buffer.allocUnsafe(4);\n\nbuf.writeUInt32BE(0xfeedface, 0);\n\nconsole.log(buf);\n// Prints: <Buffer fe ed fa ce>\n\nbuf.writeUInt32LE(0xfeedface, 0);\n\nconsole.log(buf);\n// Prints: <Buffer ce fa ed fe>\n
", "type": "module", "displayName": "`buf.writeUInt32LE(value[, offset])`" }, { "textRaw": "`buf.writeUIntBE(value, offset, byteLength)`", "name": "`buf.writeuintbe(value,_offset,_bytelength)`", "meta": { "added": [ "v0.5.5" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset and `byteLength` to `uint32` anymore." } ] }, "desc": "\n

Writes byteLength bytes of value to buf at the specified offset.\nSupports up to 48 bits of accuracy. Behavior is undefined when value is\nanything other than an unsigned integer.

\n
const buf = Buffer.allocUnsafe(6);\n\nbuf.writeUIntBE(0x1234567890ab, 0, 6);\n\nconsole.log(buf);\n// Prints: <Buffer 12 34 56 78 90 ab>\n\nbuf.writeUIntLE(0x1234567890ab, 0, 6);\n\nconsole.log(buf);\n// Prints: <Buffer ab 90 78 56 34 12>\n
", "type": "module", "displayName": "`buf.writeUIntBE(value, offset, byteLength)`" }, { "textRaw": "`buf.writeUIntLE(value, offset, byteLength)`", "name": "`buf.writeuintle(value,_offset,_bytelength)`", "meta": { "added": [ "v0.5.5" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/18395", "description": "Removed `noAssert` and no implicit coercion of the offset and `byteLength` to `uint32` anymore." } ] }, "desc": "\n

Writes byteLength bytes of value to buf at the specified offset.\nSupports up to 48 bits of accuracy. Behavior is undefined when value is\nanything other than an unsigned integer.

\n
const buf = Buffer.allocUnsafe(6);\n\nbuf.writeUIntBE(0x1234567890ab, 0, 6);\n\nconsole.log(buf);\n// Prints: <Buffer 12 34 56 78 90 ab>\n\nbuf.writeUIntLE(0x1234567890ab, 0, 6);\n\nconsole.log(buf);\n// Prints: <Buffer ab 90 78 56 34 12>\n
", "type": "module", "displayName": "`buf.writeUIntLE(value, offset, byteLength)`" } ], "type": "module", "displayName": "Class: `Buffer`" }, { "textRaw": "`buffer.INSPECT_MAX_BYTES`", "name": "`buffer.inspect_max_bytes`", "meta": { "added": [ "v0.5.4" ], "changes": [] }, "desc": "\n

Returns the maximum number of bytes that will be returned when\nbuf.inspect() is called. This can be overridden by user modules. See\nutil.inspect() for more details on buf.inspect() behavior.

\n

This is a property on the buffer module returned by\nrequire('buffer'), not on the Buffer global or a Buffer instance.

", "type": "module", "displayName": "`buffer.INSPECT_MAX_BYTES`" }, { "textRaw": "`buffer.kMaxLength`", "name": "`buffer.kmaxlength`", "meta": { "added": [ "v3.0.0" ], "changes": [] }, "desc": "\n

An alias for buffer.constants.MAX_LENGTH.

\n

This is a property on the buffer module returned by\nrequire('buffer'), not on the Buffer global or a Buffer instance.

", "type": "module", "displayName": "`buffer.kMaxLength`" }, { "textRaw": "`buffer.transcode(source, fromEnc, toEnc)`", "name": "`buffer.transcode(source,_fromenc,_toenc)`", "meta": { "added": [ "v7.1.0" ], "changes": [ { "version": "v8.0.0", "pr-url": "https://github.com/nodejs/node/pull/10236", "description": "The `source` parameter can now be a `Uint8Array`." } ] }, "desc": "\n

Re-encodes the given Buffer or Uint8Array instance from one character\nencoding to another. Returns a new Buffer instance.

\n

Throws if the fromEnc or toEnc specify invalid character encodings or if\nconversion from fromEnc to toEnc is not permitted.

\n

Encodings supported by buffer.transcode() are: 'ascii', 'utf8',\n'utf16le', 'ucs2', 'latin1', and 'binary'.

\n

The transcoding process will use substitution characters if a given byte\nsequence cannot be adequately represented in the target encoding. For instance:

\n
const buffer = require('buffer');\n\nconst newBuf = buffer.transcode(Buffer.from('€'), 'utf8', 'ascii');\nconsole.log(newBuf.toString('ascii'));\n// Prints: '?'\n
\n

Because the Euro () sign is not representable in US-ASCII, it is replaced\nwith ? in the transcoded Buffer.

\n

This is a property on the buffer module returned by\nrequire('buffer'), not on the Buffer global or a Buffer instance.

", "type": "module", "displayName": "`buffer.transcode(source, fromEnc, toEnc)`" }, { "textRaw": "Class: `SlowBuffer`", "name": "class:_`slowbuffer`", "meta": { "deprecated": [ "v6.0.0" ], "changes": [] }, "stability": 0, "stabilityText": "Deprecated: Use [`Buffer.allocUnsafeSlow()`][] instead.", "desc": "

Returns an un-pooled Buffer.

\n

In order to avoid the garbage collection overhead of creating many individually\nallocated Buffer instances, by default allocations under 4KB are sliced from a\nsingle larger allocated object.

\n

In the case where a developer may need to retain a small chunk of memory from a\npool for an indeterminate amount of time, it may be appropriate to create an\nun-pooled Buffer instance using SlowBuffer then copy out the relevant bits.

\n
// Need to keep around a few small chunks of memory.\nconst store = [];\n\nsocket.on('readable', () => {\n  let data;\n  while (null !== (data = readable.read())) {\n    // Allocate for retained data.\n    const sb = SlowBuffer(10);\n\n    // Copy the data into the new allocation.\n    data.copy(sb, 0, 0, 10);\n\n    store.push(sb);\n  }\n});\n
\n

Use of SlowBuffer should be used only as a last resort after a developer\nhas observed undue memory retention in their applications.

", "modules": [ { "textRaw": "`new SlowBuffer(size)`", "name": "`new_slowbuffer(size)`", "meta": { "deprecated": [ "v6.0.0" ], "changes": [] }, "stability": 0, "stabilityText": "Deprecated: Use [`Buffer.allocUnsafeSlow()`][] instead.", "desc": "\n

Allocates a new Buffer of size bytes. If size is larger than\nbuffer.constants.MAX_LENGTH or smaller than 0, ERR_INVALID_OPT_VALUE\nis thrown. A zero-length Buffer is created if size is 0.

\n

The underlying memory for SlowBuffer instances is not initialized. The\ncontents of a newly created SlowBuffer are unknown and may contain sensitive\ndata. Use buf.fill(0) to initialize a SlowBuffer with\nzeroes.

\n
const { SlowBuffer } = require('buffer');\n\nconst buf = new SlowBuffer(5);\n\nconsole.log(buf);\n// Prints: (contents may vary): <Buffer 78 e0 82 02 01>\n\nbuf.fill(0);\n\nconsole.log(buf);\n// Prints: <Buffer 00 00 00 00 00>\n
", "type": "module", "displayName": "`new SlowBuffer(size)`" } ], "type": "module", "displayName": "Class: `SlowBuffer`" }, { "textRaw": "Buffer Constants", "name": "buffer_constants", "meta": { "added": [ "v8.2.0" ], "changes": [] }, "desc": "

buffer.constants is a property on the buffer module returned by\nrequire('buffer'), not on the Buffer global or a Buffer instance.

", "modules": [ { "textRaw": "`buffer.constants.MAX_LENGTH`", "name": "`buffer.constants.max_length`", "meta": { "added": [ "v8.2.0" ], "changes": [] }, "desc": "\n

On 32-bit architectures, this value is (2^30)-1 (~1GB).\nOn 64-bit architectures, this value is (2^31)-1 (~2GB).

\n

This value is also available as buffer.kMaxLength.

", "type": "module", "displayName": "`buffer.constants.MAX_LENGTH`" }, { "textRaw": "`buffer.constants.MAX_STRING_LENGTH`", "name": "`buffer.constants.max_string_length`", "meta": { "added": [ "v8.2.0" ], "changes": [] }, "desc": "\n

Represents the largest length that a string primitive can have, counted\nin UTF-16 code units.

\n

This value may depend on the JS engine that is being used.

", "type": "module", "displayName": "`buffer.constants.MAX_STRING_LENGTH`" } ], "type": "module", "displayName": "Buffer Constants" } ], "type": "module", "displayName": "Buffer" } ] }