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

Prior to the introduction of TypedArray in ECMAScript 2015 (ES6), the\nJavaScript language had no mechanism for reading or manipulating streams\nof binary data. The Buffer class was introduced as part of the Node.js\nAPI to make it possible to interact with octet streams in the context of things\nlike TCP streams and file system operations.

\n

Now that TypedArray has been added in ES6, the Buffer class implements the\nUint8Array API in a manner that is more optimized and suitable for Node.js'\nuse cases.

\n

Instances of the Buffer class are similar to arrays of integers 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\nresized.

\n

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

\n

Examples:

\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
\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 v6, 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() changes significantly based on the type\nof value passed as the first argument, applications that do not properly\nvalidate the input arguments passed to new Buffer(), or that fail to\nappropriately initialize newly allocated Buffer content, can inadvertently\nintroduce security and reliability issues into their code.

\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() never\nuse the shared internal memory pool.

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

Node.js can be started using the --zero-fill-buffers command line option to\nforce all newly allocated Buffer instances created using either\nnew Buffer(size), Buffer.allocUnsafe(), Buffer.allocUnsafeSlow() or\nnew SlowBuffer(size) to be automatically zero-filled upon creation. Use of\nthis flag changes the default behavior of these methods and can have a significant\nimpact on performance. Use of the --zero-fill-buffers option is recommended\nonly when necessary to enforce that newly allocated Buffer instances cannot\ncontain potentially sensitive data.

\n

Example:

\n
$ node --zero-fill-buffers\n> Buffer.allocUnsafe(5);\n<Buffer 00 00 00 00 00>\n
\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 memory\ncan allow this old data to be leaked when the Buffer memory is read.

\n

While there are clear performance advantages to using Buffer.allocUnsafe(),\nextra care must be taken in order to avoid introducing security\nvulnerabilities into an application.

\n", "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", "desc": "

Buffer instances are commonly used to represent sequences of encoded characters\nsuch as UTF-8, UCS2, Base64 or even Hex-encoded data. It is possible to\nconvert back and forth between Buffer instances and ordinary JavaScript strings\nby using an explicit character encoding.

\n

Example:

\n
const buf = Buffer.from('hello world', 'ascii');\n\n// Prints: 68656c6c6f20776f726c64\nconsole.log(buf.toString('hex'));\n\n// Prints: aGVsbG8gd29ybGQ=\nconsole.log(buf.toString('base64'));\n
\n

The character encodings currently supported by Node.js include:

\n\n

Note: Today's browsers follow the WHATWG spec which aliases both 'latin1' and\nISO-8859-1 to win-1252. This means that while doing something like http.get(),\nif the returned charset is one of those listed in the WHATWG spec it's possible\nthat the server actually returned win-1252-encoded data, and using 'latin1'\nencoding may incorrectly decode the characters.

\n", "type": "module", "displayName": "Buffers and Character Encodings" }, { "textRaw": "Buffers and TypedArray", "name": "buffers_and_typedarray", "desc": "

Buffer instances are also Uint8Array instances. However, there are subtle\nincompatibilities with the TypedArray specification in ECMAScript 2015.\nFor example, while ArrayBuffer#slice() creates a copy of the slice, the\nimplementation of Buffer#slice() creates a view over the\nexisting Buffer without copying, making Buffer#slice() far\nmore efficient.

\n

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

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

    \n
  2. \n
  3. 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 Uint32Array\nwith elements [1, 2, 3, 4], not a Uint32Array with a single element\n[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 TypeArray object's .buffer property.

\n

Example:

\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\n// Shares memory with `arr`\nconst buf2 = Buffer.from(arr.buffer);\n\n// Prints: <Buffer 88 a0>\nconsole.log(buf1);\n\n// Prints: <Buffer 88 13 a0 0f>\nconsole.log(buf2);\n\narr[1] = 6000;\n\n// Prints: <Buffer 88 a0>\nconsole.log(buf1);\n\n// Prints: <Buffer 88 13 70 17>\nconsole.log(buf2);\n
\n

Note that 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

Example:

\n
const arr = new Uint16Array(20);\nconst buf = Buffer.from(arr.buffer, 0, 16);\n\n// Prints: 16\nconsole.log(buf.length);\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\n", "type": "module", "displayName": "Buffers and TypedArray" }, { "textRaw": "Buffers and ES6 iteration", "name": "buffers_and_es6_iteration", "desc": "

Buffer instances can be iterated over using the ECMAScript 2015 (ES6) for..of\nsyntax.

\n

Example:

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

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

\n", "type": "module", "displayName": "Buffers and ES6 iteration" } ], "classes": [ { "textRaw": "Class: Buffer", "type": "class", "name": "Buffer", "desc": "

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

\n", "classMethods": [ { "textRaw": "Class Method: Buffer.alloc(size[, fill[, encoding]])", "type": "classMethod", "name": "alloc", "meta": { "added": [ "v5.10.0" ] }, "signatures": [ { "params": [ { "textRaw": "`size` {integer} The desired length of the new `Buffer`. ", "name": "size", "type": "integer", "desc": "The desired length of the new `Buffer`." }, { "textRaw": "`fill` {string|Buffer|integer} A value to pre-fill the new `Buffer` with. **Default:** `0` ", "name": "fill", "type": "string|Buffer|integer", "desc": "A value to pre-fill the new `Buffer` with. **Default:** `0`", "optional": true }, { "textRaw": "`encoding` {string} If `fill` is a string, this is its encoding. **Default:** `'utf8'` ", "name": "encoding", "type": "string", "desc": "If `fill` is a string, this is its encoding. **Default:** `'utf8'`", "optional": true } ] }, { "params": [ { "name": "size" }, { "name": "fill", "optional": true }, { "name": "encoding", "optional": true } ] } ], "desc": "

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

\n

Example:

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

The size must be less than or equal to the value of buffer.kMaxLength.\nOtherwise, a RangeError is thrown. A zero-length Buffer will be created if\nsize <= 0.

\n

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

\n

Example:

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

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

\n

Example:

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

\n" }, { "textRaw": "Class Method: Buffer.allocUnsafe(size)", "type": "classMethod", "name": "allocUnsafe", "meta": { "added": [ "v5.10.0" ] }, "signatures": [ { "params": [ { "textRaw": "`size` {integer} The desired length of the new `Buffer`. ", "name": "size", "type": "integer", "desc": "The desired length of the new `Buffer`." } ] }, { "params": [ { "name": "size" } ] } ], "desc": "

Allocates a new non-zero-filled Buffer of size bytes. The size must\nbe less than or equal to the value of buffer.kMaxLength. Otherwise, a\nRangeError is thrown. A zero-length Buffer will be created if size <= 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 to zeroes.

\n

Example:

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

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

\n

Note that 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.

\n" }, { "textRaw": "Class Method: Buffer.allocUnsafeSlow(size)", "type": "classMethod", "name": "allocUnsafeSlow", "meta": { "added": [ "v5.12.0" ] }, "signatures": [ { "params": [ { "textRaw": "`size` {integer} The desired length of the new `Buffer`. ", "name": "size", "type": "integer", "desc": "The desired length of the new `Buffer`." } ] }, { "params": [ { "name": "size" } ] } ], "desc": "

Allocates a new non-zero-filled and non-pooled Buffer of size bytes. The\nsize must be less than or equal to the value of buffer.kMaxLength.\nOtherwise, a RangeError is thrown. A zero-length Buffer will be created if\nsize <= 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 such\nBuffer instances to zeroes.

\n

When using Buffer.allocUnsafe() to allocate new Buffer instances,\nallocations under 4KB are, by default, sliced from a single pre-allocated\nBuffer. This allows applications to avoid the garbage collection overhead of\ncreating many individually allocated Buffer instances. This approach improves\nboth performance and memory usage by eliminating the need to track and cleanup 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() then\ncopy out the relevant bits.

\n

Example:

\n
// Need to keep around a few small chunks of memory\nconst store = [];\n\nsocket.on('readable', () => {\n  const data = socket.read();\n\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

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

\n

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

\n" }, { "textRaw": "Class Method: Buffer.byteLength(string[, encoding])", "type": "classMethod", "name": "byteLength", "meta": { "added": [ "v0.1.90" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} The number of bytes contained within `string`. ", "name": "return", "type": "integer", "desc": "The number of bytes contained within `string`." }, "params": [ { "textRaw": "`string` {string|Buffer|TypedArray|DataView|ArrayBuffer|SharedArrayBuffer} A value to calculate the length of. ", "name": "string", "type": "string|Buffer|TypedArray|DataView|ArrayBuffer|SharedArrayBuffer", "desc": "A value to calculate the length of." }, { "textRaw": "`encoding` {string} If `string` is a string, this is its encoding. **Default:** `'utf8'` ", "name": "encoding", "type": "string", "desc": "If `string` is a string, this is its encoding. **Default:** `'utf8'`", "optional": true } ] }, { "params": [ { "name": "string" }, { "name": "encoding", "optional": true } ] } ], "desc": "

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

Note that for 'base64' and 'hex', this function assumes valid input. For\nstrings that contain non-Base64/Hex-encoded data (e.g. whitespace), the return\nvalue might be greater than the length of a Buffer created from the string.

\n

Example:

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

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

\n

Otherwise, converts to String and returns the byte length of string.

\n" }, { "textRaw": "Class Method: Buffer.compare(buf1, buf2)", "type": "classMethod", "name": "compare", "meta": { "added": [ "v0.11.13" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} ", "name": "return", "type": "integer" }, "params": [ { "textRaw": "`buf1` {Buffer} ", "name": "buf1", "type": "Buffer" }, { "textRaw": "`buf2` {Buffer} ", "name": "buf2", "type": "Buffer" } ] }, { "params": [ { "name": "buf1" }, { "name": "buf2" } ] } ], "desc": "

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

\n

Example:

\n
const buf1 = Buffer.from('1234');\nconst buf2 = Buffer.from('0123');\nconst arr = [buf1, buf2];\n\n// Prints: [ <Buffer 30 31 32 33>, <Buffer 31 32 33 34> ]\n// (This result is equal to: [buf2, buf1])\nconsole.log(arr.sort(Buffer.compare));\n
\n" }, { "textRaw": "Class Method: Buffer.concat(list[, totalLength])", "type": "classMethod", "name": "concat", "meta": { "added": [ "v0.7.11" ] }, "signatures": [ { "return": { "textRaw": "Returns: {Buffer} ", "name": "return", "type": "Buffer" }, "params": [ { "textRaw": "`list` {Array} List of `Buffer` instances to concat. ", "name": "list", "type": "Array", "desc": "List of `Buffer` instances to concat." }, { "textRaw": "`totalLength` {integer} Total length of the `Buffer` instances in `list` when concatenated. ", "name": "totalLength", "type": "integer", "desc": "Total length of the `Buffer` instances in `list` when concatenated.", "optional": true } ] }, { "params": [ { "name": "list" }, { "name": "totalLength", "optional": true } ] } ], "desc": "

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

Example: Create a single Buffer from a list of three Buffer instances

\n
const buf1 = Buffer.alloc(10);\nconst buf2 = Buffer.alloc(14);\nconst buf3 = Buffer.alloc(18);\nconst totalLength = buf1.length + buf2.length + buf3.length;\n\n// Prints: 42\nconsole.log(totalLength);\n\nconst bufA = Buffer.concat([buf1, buf2, buf3], totalLength);\n\n// Prints: <Buffer 00 00 00 00 ...>\nconsole.log(bufA);\n\n// Prints: 42\nconsole.log(bufA.length);\n
\n" }, { "textRaw": "Class Method: Buffer.from(array)", "type": "classMethod", "name": "from", "meta": { "added": [ "v5.10.0" ] }, "signatures": [ { "params": [ { "textRaw": "`array` {Array} ", "name": "array", "type": "Array" } ] }, { "params": [ { "name": "array" } ] } ], "desc": "

Allocates a new Buffer using an array of octets.

\n

Example:

\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.

\n" }, { "textRaw": "Class Method: Buffer.from(arrayBuffer[, byteOffset[, length]])", "type": "classMethod", "name": "from", "meta": { "added": [ "v5.10.0" ] }, "signatures": [ { "params": [ { "textRaw": "`arrayBuffer` {ArrayBuffer|SharedArrayBuffer} An [`ArrayBuffer`], [`SharedArrayBuffer`], or the `.buffer` property of a [`TypedArray`]. ", "name": "arrayBuffer", "type": "ArrayBuffer|SharedArrayBuffer", "desc": "An [`ArrayBuffer`], [`SharedArrayBuffer`], or the `.buffer` property of a [`TypedArray`]." }, { "textRaw": "`byteOffset` {integer} Index of first byte to expose. **Default:** `0` ", "name": "byteOffset", "type": "integer", "desc": "Index of first byte to expose. **Default:** `0`", "optional": true }, { "textRaw": "`length` {integer} Number of bytes to expose. **Default:** `arrayBuffer.length - byteOffset` ", "name": "length", "type": "integer", "desc": "Number of bytes to expose. **Default:** `arrayBuffer.length - byteOffset`", "optional": true } ] }, { "params": [ { "name": "arrayBuffer" }, { "name": "byteOffset", "optional": true }, { "name": "length", "optional": true } ] } ], "desc": "

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

Example:

\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\n// Prints: <Buffer 88 13 a0 0f>\nconsole.log(buf);\n\n// Changing the original Uint16Array changes the Buffer also\narr[1] = 6000;\n\n// Prints: <Buffer 88 13 70 17>\nconsole.log(buf);\n
\n

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

\n

Example:

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

A TypeError will be thrown if arrayBuffer is not an ArrayBuffer or a\nSharedArrayBuffer.

\n" }, { "textRaw": "Class Method: Buffer.from(buffer)", "type": "classMethod", "name": "from", "meta": { "added": [ "v5.10.0" ] }, "signatures": [ { "params": [ { "textRaw": "`buffer` {Buffer} An existing `Buffer` to copy data from. ", "name": "buffer", "type": "Buffer", "desc": "An existing `Buffer` to copy data from." } ] }, { "params": [ { "name": "buffer" } ] } ], "desc": "

Copies the passed buffer data onto a new Buffer instance.

\n

Example:

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

A TypeError will be thrown if buffer is not a Buffer.

\n" }, { "textRaw": "Class Method: Buffer.from(string[, encoding])", "type": "classMethod", "name": "from", "meta": { "added": [ "v5.10.0" ] }, "signatures": [ { "params": [ { "textRaw": "`string` {string} A string to encode. ", "name": "string", "type": "string", "desc": "A string to encode." }, { "textRaw": "`encoding` {string} The encoding of `string`. **Default:** `'utf8'` ", "name": "encoding", "type": "string", "desc": "The encoding of `string`. **Default:** `'utf8'`", "optional": true } ] }, { "params": [ { "name": "string" }, { "name": "encoding", "optional": true } ] } ], "desc": "

Creates a new Buffer containing the given JavaScript string string. If\nprovided, the encoding parameter identifies the character encoding of string.

\n

Examples:

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

A TypeError will be thrown if string is not a string.

\n" }, { "textRaw": "Class Method: Buffer.isBuffer(obj)", "type": "classMethod", "name": "isBuffer", "meta": { "added": [ "v0.1.101" ] }, "signatures": [ { "return": { "textRaw": "Returns: {boolean} ", "name": "return", "type": "boolean" }, "params": [ { "textRaw": "`obj` {Object} ", "name": "obj", "type": "Object" } ] }, { "params": [ { "name": "obj" } ] } ], "desc": "

Returns true if obj is a Buffer, false otherwise.

\n" }, { "textRaw": "Class Method: Buffer.isEncoding(encoding)", "type": "classMethod", "name": "isEncoding", "meta": { "added": [ "v0.9.1" ] }, "signatures": [ { "return": { "textRaw": "Returns: {boolean} ", "name": "return", "type": "boolean" }, "params": [ { "textRaw": "`encoding` {string} A character encoding name to check. ", "name": "encoding", "type": "string", "desc": "A character encoding name to check." } ] }, { "params": [ { "name": "encoding" } ] } ], "desc": "

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

\n" } ], "properties": [ { "textRaw": "`poolSize` {integer} **Default:** `8192` ", "type": "integer", "name": "poolSize", "meta": { "added": [ "v0.11.3" ] }, "desc": "

This is the number of bytes used to determine the size of pre-allocated, internal\nBuffer instances used for pooling. This value may be modified.

\n", "shortDesc": "**Default:** `8192`" }, { "textRaw": "buf[index]", "name": "[index]", "meta": { "type": "property", "name": [ "index" ] }, "desc": "

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 - that is, getting returns undefined and\nsetting does nothing.

\n

Example: Copy an ASCII string into a Buffer, one byte at a time

\n
const 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\n// Prints: Node.js\nconsole.log(buf.toString('ascii'));\n
\n" }, { "textRaw": "`length` {integer} ", "type": "integer", "name": "length", "meta": { "added": [ "v0.1.90" ] }, "desc": "

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

\n

Example: Create a Buffer and write a shorter ASCII string to it

\n
const buf = Buffer.alloc(1234);\n\n// Prints: 1234\nconsole.log(buf.length);\n\nbuf.write('some string', 0, 'ascii');\n\n// Prints: 1234\nconsole.log(buf.length);\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

Examples:

\n
let buf = Buffer.allocUnsafe(10);\n\nbuf.write('abcdefghj', 0, 'ascii');\n\n// Prints: 10\nconsole.log(buf.length);\n\nbuf = buf.slice(0, 5);\n\n// Prints: 5\nconsole.log(buf.length);\n
\n" } ], "methods": [ { "textRaw": "buf.compare(target[, targetStart[, targetEnd[, sourceStart[, sourceEnd]]]])", "type": "method", "name": "compare", "meta": { "added": [ "v0.11.13" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} ", "name": "return", "type": "integer" }, "params": [ { "textRaw": "`target` {Buffer} A `Buffer` to compare to. ", "name": "target", "type": "Buffer", "desc": "A `Buffer` to compare to." }, { "textRaw": "`targetStart` {integer} The offset within `target` at which to begin comparison. **Default:** `0` ", "name": "targetStart", "type": "integer", "desc": "The offset within `target` at which to begin comparison. **Default:** `0`", "optional": true }, { "textRaw": "`targetEnd` {integer} The offset with `target` at which to end comparison (not inclusive). **Default:** `target.length` ", "name": "targetEnd", "type": "integer", "desc": "The offset with `target` at which to end comparison (not inclusive). **Default:** `target.length`", "optional": true }, { "textRaw": "`sourceStart` {integer} The offset within `buf` at which to begin comparison. **Default:** `0` ", "name": "sourceStart", "type": "integer", "desc": "The offset within `buf` at which to begin comparison. **Default:** `0`", "optional": true }, { "textRaw": "`sourceEnd` {integer} The offset within `buf` at which to end comparison (not inclusive). **Default:** [`buf.length`] ", "name": "sourceEnd", "type": "integer", "desc": "The offset within `buf` at which to end comparison (not inclusive). **Default:** [`buf.length`]", "optional": true } ] }, { "params": [ { "name": "target" }, { "name": "targetStart", "optional": true }, { "name": "targetEnd", "optional": true }, { "name": "sourceStart", "optional": true }, { "name": "sourceEnd", "optional": true } ] } ], "desc": "

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

Examples:

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

Examples:

\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\n// Prints: 0\nconsole.log(buf1.compare(buf2, 5, 9, 0, 4));\n\n// Prints: -1\nconsole.log(buf1.compare(buf2, 0, 6, 4));\n\n// Prints: 1\nconsole.log(buf1.compare(buf2, 5, 6, 5));\n
\n

A RangeError will be thrown if: targetStart < 0, sourceStart < 0,\ntargetEnd > target.byteLength or sourceEnd > source.byteLength.

\n" }, { "textRaw": "buf.copy(target[, targetStart[, sourceStart[, sourceEnd]]])", "type": "method", "name": "copy", "meta": { "added": [ "v0.1.90" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} The number of bytes copied. ", "name": "return", "type": "integer", "desc": "The number of bytes copied." }, "params": [ { "textRaw": "`target` {Buffer|Uint8Array} A `Buffer` or [`Uint8Array`] to copy into. ", "name": "target", "type": "Buffer|Uint8Array", "desc": "A `Buffer` or [`Uint8Array`] to copy into." }, { "textRaw": "`targetStart` {integer} The offset within `target` at which to begin copying to. **Default:** `0` ", "name": "targetStart", "type": "integer", "desc": "The offset within `target` at which to begin copying to. **Default:** `0`", "optional": true }, { "textRaw": "`sourceStart` {integer} The offset within `buf` at which to begin copying from. **Default:** `0` ", "name": "sourceStart", "type": "integer", "desc": "The offset within `buf` at which to begin copying from. **Default:** `0`", "optional": true }, { "textRaw": "`sourceEnd` {integer} The offset within `buf` at which to stop copying (not inclusive). **Default:** [`buf.length`] ", "name": "sourceEnd", "type": "integer", "desc": "The offset within `buf` at which to stop copying (not inclusive). **Default:** [`buf.length`]", "optional": true } ] }, { "params": [ { "name": "target" }, { "name": "targetStart", "optional": true }, { "name": "sourceStart", "optional": true }, { "name": "sourceEnd", "optional": true } ] } ], "desc": "

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

\n

Example: Create two Buffer instances, buf1 and buf2, and copy buf1 from\nbyte 16 through byte 19 into buf2, starting at the 8th byte in buf2

\n
const 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\nbuf1.copy(buf2, 8, 16, 20);\n\n// Prints: !!!!!!!!qrst!!!!!!!!!!!!!\nconsole.log(buf2.toString('ascii', 0, 25));\n
\n

Example: Create a single Buffer and copy data from one region to an\noverlapping region within the same Buffer

\n
const 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\n// Prints: efghijghijklmnopqrstuvwxyz\nconsole.log(buf.toString());\n
\n" }, { "textRaw": "buf.entries()", "type": "method", "name": "entries", "meta": { "added": [ "v1.1.0" ] }, "signatures": [ { "return": { "textRaw": "Returns: {Iterator} ", "name": "return", "type": "Iterator" }, "params": [] }, { "params": [] } ], "desc": "

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

\n

Example: Log the entire contents of a Buffer

\n
const buf = Buffer.from('buffer');\n\n// Prints:\n//   [0, 98]\n//   [1, 117]\n//   [2, 102]\n//   [3, 102]\n//   [4, 101]\n//   [5, 114]\nfor (const pair of buf.entries()) {\n  console.log(pair);\n}\n
\n" }, { "textRaw": "buf.equals(otherBuffer)", "type": "method", "name": "equals", "meta": { "added": [ "v0.11.13" ] }, "signatures": [ { "return": { "textRaw": "Returns: {boolean} ", "name": "return", "type": "boolean" }, "params": [ { "textRaw": "`otherBuffer` {Buffer} A `Buffer` to compare to. ", "name": "otherBuffer", "type": "Buffer", "desc": "A `Buffer` to compare to." } ] }, { "params": [ { "name": "otherBuffer" } ] } ], "desc": "

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

\n

Examples:

\n
const buf1 = Buffer.from('ABC');\nconst buf2 = Buffer.from('414243', 'hex');\nconst buf3 = Buffer.from('ABCD');\n\n// Prints: true\nconsole.log(buf1.equals(buf2));\n\n// Prints: false\nconsole.log(buf1.equals(buf3));\n
\n" }, { "textRaw": "buf.fill(value[, offset[, end]][, encoding])", "type": "method", "name": "fill", "meta": { "added": [ "v0.5.0" ] }, "signatures": [ { "return": { "textRaw": "Returns: {Buffer} A reference to `buf`. ", "name": "return", "type": "Buffer", "desc": "A reference to `buf`." }, "params": [ { "textRaw": "`value` {string|Buffer|integer} The value to fill `buf` with. ", "name": "value", "type": "string|Buffer|integer", "desc": "The value to fill `buf` with." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to fill `buf`. **Default:** `0` ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to fill `buf`. **Default:** `0`", "optional": true }, { "textRaw": "`end` {integer} Where to stop filling `buf` (not inclusive). **Default:** [`buf.length`] ", "name": "end", "type": "integer", "desc": "Where to stop filling `buf` (not inclusive). **Default:** [`buf.length`]", "optional": true }, { "textRaw": "`encoding` {string} If `value` is a string, this is its encoding. **Default:** `'utf8'` ", "name": "encoding", "type": "string", "desc": "If `value` is a string, this is its encoding. **Default:** `'utf8'`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset", "optional": true }, { "name": "end", "optional": true }, { "name": "encoding", "optional": true } ] } ], "desc": "

Fills buf with the specified value. If the offset and end are not given,\nthe entire buf will be filled. This is meant to be a small simplification to\nallow the creation and filling of a Buffer to be done on a single line.

\n

Example: Fill a Buffer with the ASCII character 'h'

\n
const b = Buffer.allocUnsafe(50).fill('h');\n\n// Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\nconsole.log(b.toString());\n
\n

value is coerced to a uint32 value if it is not a String or Integer.

\n

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

\n

Example: Fill a Buffer with a two-byte character

\n
// Prints: <Buffer c8 a2 c8>\nconsole.log(Buffer.allocUnsafe(3).fill('\\u0222'));\n
\n" }, { "textRaw": "buf.includes(value[, byteOffset][, encoding])", "type": "method", "name": "includes", "meta": { "added": [ "v5.3.0" ] }, "signatures": [ { "return": { "textRaw": "Returns: {boolean} `true` if `value` was found in `buf`, `false` otherwise. ", "name": "return", "type": "boolean", "desc": "`true` if `value` was found in `buf`, `false` otherwise." }, "params": [ { "textRaw": "`value` {string|Buffer|integer} What to search for. ", "name": "value", "type": "string|Buffer|integer", "desc": "What to search for." }, { "textRaw": "`byteOffset` {integer} Where to begin searching in `buf`. **Default:** `0` ", "name": "byteOffset", "type": "integer", "desc": "Where to begin searching in `buf`. **Default:** `0`", "optional": true }, { "textRaw": "`encoding` {string} If `value` is a string, this is its encoding. **Default:** `'utf8'` ", "name": "encoding", "type": "string", "desc": "If `value` is a string, this is its encoding. **Default:** `'utf8'`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "byteOffset", "optional": true }, { "name": "encoding", "optional": true } ] } ], "desc": "

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

\n

Examples:

\n
const buf = Buffer.from('this is a buffer');\n\n// Prints: true\nconsole.log(buf.includes('this'));\n\n// Prints: true\nconsole.log(buf.includes('is'));\n\n// Prints: true\nconsole.log(buf.includes(Buffer.from('a buffer')));\n\n// Prints: true\n// (97 is the decimal ASCII value for 'a')\nconsole.log(buf.includes(97));\n\n// Prints: false\nconsole.log(buf.includes(Buffer.from('a buffer example')));\n\n// Prints: true\nconsole.log(buf.includes(Buffer.from('a buffer example').slice(0, 8)));\n\n// Prints: false\nconsole.log(buf.includes('this', 4));\n
\n" }, { "textRaw": "buf.indexOf(value[, byteOffset][, encoding])", "type": "method", "name": "indexOf", "meta": { "added": [ "v1.5.0" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} The index of the first occurrence of `value` in `buf` or `-1` if `buf` does not contain `value`. ", "name": "return", "type": "integer", "desc": "The index of the first occurrence of `value` in `buf` or `-1` if `buf` does not contain `value`." }, "params": [ { "textRaw": "`value` {string|Buffer|integer} What to search for. ", "name": "value", "type": "string|Buffer|integer", "desc": "What to search for." }, { "textRaw": "`byteOffset` {integer} Where to begin searching in `buf`. **Default:** `0` ", "name": "byteOffset", "type": "integer", "desc": "Where to begin searching in `buf`. **Default:** `0`", "optional": true }, { "textRaw": "`encoding` {string} If `value` is a string, this is its encoding. **Default:** `'utf8'` ", "name": "encoding", "type": "string", "desc": "If `value` is a string, this is its encoding. **Default:** `'utf8'`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "byteOffset", "optional": true }, { "name": "encoding", "optional": true } ] } ], "desc": "

If value is:

\n\n

Examples:

\n
const buf = Buffer.from('this is a buffer');\n\n// Prints: 0\nconsole.log(buf.indexOf('this'));\n\n// Prints: 2\nconsole.log(buf.indexOf('is'));\n\n// Prints: 8\nconsole.log(buf.indexOf(Buffer.from('a buffer')));\n\n// Prints: 8\n// (97 is the decimal ASCII value for 'a')\nconsole.log(buf.indexOf(97));\n\n// Prints: -1\nconsole.log(buf.indexOf(Buffer.from('a buffer example')));\n\n// Prints: 8\nconsole.log(buf.indexOf(Buffer.from('a buffer example').slice(0, 8)));\n\n\nconst utf16Buffer = Buffer.from('\\u039a\\u0391\\u03a3\\u03a3\\u0395', 'ucs2');\n\n// Prints: 4\nconsole.log(utf16Buffer.indexOf('\\u03a3', 0, 'ucs2'));\n\n// Prints: 6\nconsole.log(utf16Buffer.indexOf('\\u03a3', -4, 'ucs2'));\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 or 0, like {}, [], null or undefined, will search\nthe whole buffer. This behavior 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" }, { "textRaw": "buf.includes(value[, byteOffset][, encoding])", "type": "method", "name": "includes", "meta": { "added": [ "v5.3.0" ] }, "signatures": [ { "return": { "textRaw": "Returns: {Boolean} `true` if `value` was found in `buf`, `false` otherwise ", "name": "return", "type": "Boolean", "desc": "`true` if `value` was found in `buf`, `false` otherwise" }, "params": [ { "textRaw": "`value` {String|Buffer|Integer} What to search for. ", "name": "value", "type": "String|Buffer|Integer", "desc": "What to search for." }, { "textRaw": "`byteOffset` {Integer} Where to begin searching in `buf`. **Default:** `0` ", "name": "byteOffset", "type": "Integer", "desc": "Where to begin searching in `buf`. **Default:** `0`", "optional": true }, { "textRaw": "`encoding` {String} If `value` is a string, this is its encoding. **Default:** `'utf8'` ", "name": "encoding", "type": "String", "desc": "If `value` is a string, this is its encoding. **Default:** `'utf8'`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "byteOffset", "optional": true }, { "name": "encoding", "optional": true } ] } ], "desc": "

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

\n

Examples:

\n
const buf = Buffer.from('this is a buffer');\n\n// Prints: true\nconsole.log(buf.includes('this'));\n\n// Prints: true\nconsole.log(buf.includes('is'));\n\n// Prints: true\nconsole.log(buf.includes(Buffer.from('a buffer')));\n\n// Prints: true\n// (97 is the decimal ASCII value for 'a')\nconsole.log(buf.includes(97));\n\n// Prints: false\nconsole.log(buf.includes(Buffer.from('a buffer example')));\n\n// Prints: true\nconsole.log(buf.includes(Buffer.from('a buffer example').slice(0, 8)));\n\n// Prints: false\nconsole.log(buf.includes('this', 4));\n
\n" }, { "textRaw": "buf.keys()", "type": "method", "name": "keys", "meta": { "added": [ "v1.1.0" ] }, "signatures": [ { "return": { "textRaw": "Returns: {Iterator} ", "name": "return", "type": "Iterator" }, "params": [] }, { "params": [] } ], "desc": "

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

\n

Example:

\n
const buf = Buffer.from('buffer');\n\n// Prints:\n//   0\n//   1\n//   2\n//   3\n//   4\n//   5\nfor (const key of buf.keys()) {\n  console.log(key);\n}\n
\n" }, { "textRaw": "buf.lastIndexOf(value[, byteOffset][, encoding])", "type": "method", "name": "lastIndexOf", "meta": { "added": [ "v6.0.0" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} The index of the last occurrence of `value` in `buf` or `-1` if `buf` does not contain `value`. ", "name": "return", "type": "integer", "desc": "The index of the last occurrence of `value` in `buf` or `-1` if `buf` does not contain `value`." }, "params": [ { "textRaw": "`value` {string|Buffer|integer} What to search for. ", "name": "value", "type": "string|Buffer|integer", "desc": "What to search for." }, { "textRaw": "`byteOffset` {integer} Where to begin searching in `buf`. **Default:** [`buf.length`]` - 1` ", "name": "byteOffset", "type": "integer", "desc": "Where to begin searching in `buf`. **Default:** [`buf.length`]` - 1`", "optional": true }, { "textRaw": "`encoding` {string} If `value` is a string, this is its encoding. **Default:** `'utf8'` ", "name": "encoding", "type": "string", "desc": "If `value` is a string, this is its encoding. **Default:** `'utf8'`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "byteOffset", "optional": true }, { "name": "encoding", "optional": true } ] } ], "desc": "

Identical to buf.indexOf(), except buf is searched from back to front\ninstead of front to back.

\n

Examples:

\n
const buf = Buffer.from('this buffer is a buffer');\n\n// Prints: 0\nconsole.log(buf.lastIndexOf('this'));\n\n// Prints: 17\nconsole.log(buf.lastIndexOf('buffer'));\n\n// Prints: 17\nconsole.log(buf.lastIndexOf(Buffer.from('buffer')));\n\n// Prints: 15\n// (97 is the decimal ASCII value for 'a')\nconsole.log(buf.lastIndexOf(97));\n\n// Prints: -1\nconsole.log(buf.lastIndexOf(Buffer.from('yolo')));\n\n// Prints: 5\nconsole.log(buf.lastIndexOf('buffer', 5));\n\n// Prints: -1\nconsole.log(buf.lastIndexOf('buffer', 4));\n\n\nconst utf16Buffer = Buffer.from('\\u039a\\u0391\\u03a3\\u03a3\\u0395', 'ucs2');\n\n// Prints: 6\nconsole.log(utf16Buffer.lastIndexOf('\\u03a3', undefined, 'ucs2'));\n\n// Prints: 4\nconsole.log(utf16Buffer.lastIndexOf('\\u03a3', -5, 'ucs2'));\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" }, { "textRaw": "buf.readDoubleBE(offset[, noAssert])", "type": "method", "name": "readDoubleBE", "meta": { "added": [ "v0.11.15" ] }, "signatures": [ { "return": { "textRaw": "Returns: {number} ", "name": "return", "type": "number" }, "params": [ { "textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`." }, { "textRaw": "`noAssert` {boolean} Skip `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

\n

Setting noAssert to true allows offset to be beyond the end of buf, but\nthe resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);\n\n// Prints: 8.20788039913184e-304\nconsole.log(buf.readDoubleBE());\n\n// Prints: 5.447603722011605e-270\nconsole.log(buf.readDoubleLE());\n\n// Throws an exception: RangeError: Index out of range\nconsole.log(buf.readDoubleLE(1));\n\n// Warning: reads passed end of buffer!\n// This will result in a segmentation fault! Don't do this!\nconsole.log(buf.readDoubleLE(1, true));\n
\n" }, { "textRaw": "buf.readDoubleLE(offset[, noAssert])", "type": "method", "name": "readDoubleLE", "meta": { "added": [ "v0.11.15" ] }, "signatures": [ { "return": { "textRaw": "Returns: {number} ", "name": "return", "type": "number" }, "params": [ { "textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`." }, { "textRaw": "`noAssert` {boolean} Skip `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

\n

Setting noAssert to true allows offset to be beyond the end of buf, but\nthe resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);\n\n// Prints: 8.20788039913184e-304\nconsole.log(buf.readDoubleBE());\n\n// Prints: 5.447603722011605e-270\nconsole.log(buf.readDoubleLE());\n\n// Throws an exception: RangeError: Index out of range\nconsole.log(buf.readDoubleLE(1));\n\n// Warning: reads passed end of buffer!\n// This will result in a segmentation fault! Don't do this!\nconsole.log(buf.readDoubleLE(1, true));\n
\n" }, { "textRaw": "buf.readFloatBE(offset[, noAssert])", "type": "method", "name": "readFloatBE", "meta": { "added": [ "v0.11.15" ] }, "signatures": [ { "return": { "textRaw": "Returns: {number} ", "name": "return", "type": "number" }, "params": [ { "textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 4`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 4`." }, { "textRaw": "`noAssert` {boolean} Skip `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

\n

Setting noAssert to true allows offset to be beyond the end of buf, but\nthe resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.from([1, 2, 3, 4]);\n\n// Prints: 2.387939260590663e-38\nconsole.log(buf.readFloatBE());\n\n// Prints: 1.539989614439558e-36\nconsole.log(buf.readFloatLE());\n\n// Throws an exception: RangeError: Index out of range\nconsole.log(buf.readFloatLE(1));\n\n// Warning: reads passed end of buffer!\n// This will result in a segmentation fault! Don't do this!\nconsole.log(buf.readFloatLE(1, true));\n
\n" }, { "textRaw": "buf.readFloatLE(offset[, noAssert])", "type": "method", "name": "readFloatLE", "meta": { "added": [ "v0.11.15" ] }, "signatures": [ { "return": { "textRaw": "Returns: {number} ", "name": "return", "type": "number" }, "params": [ { "textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 4`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 4`." }, { "textRaw": "`noAssert` {boolean} Skip `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

\n

Setting noAssert to true allows offset to be beyond the end of buf, but\nthe resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.from([1, 2, 3, 4]);\n\n// Prints: 2.387939260590663e-38\nconsole.log(buf.readFloatBE());\n\n// Prints: 1.539989614439558e-36\nconsole.log(buf.readFloatLE());\n\n// Throws an exception: RangeError: Index out of range\nconsole.log(buf.readFloatLE(1));\n\n// Warning: reads passed end of buffer!\n// This will result in a segmentation fault! Don't do this!\nconsole.log(buf.readFloatLE(1, true));\n
\n" }, { "textRaw": "buf.readInt8(offset[, noAssert])", "type": "method", "name": "readInt8", "meta": { "added": [ "v0.5.0" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} ", "name": "return", "type": "integer" }, "params": [ { "textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 1`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 1`." }, { "textRaw": "`noAssert` {boolean} Skip `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

\n

Setting noAssert to true allows offset to be beyond the end of buf, but\nthe resulting behavior is undefined.

\n

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

\n

Examples:

\n
const buf = Buffer.from([-1, 5]);\n\n// Prints: -1\nconsole.log(buf.readInt8(0));\n\n// Prints: 5\nconsole.log(buf.readInt8(1));\n\n// Throws an exception: RangeError: Index out of range\nconsole.log(buf.readInt8(2));\n
\n" }, { "textRaw": "buf.readInt16BE(offset[, noAssert])", "type": "method", "name": "readInt16BE", "meta": { "added": [ "v0.5.5" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} ", "name": "return", "type": "integer" }, "params": [ { "textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 2`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 2`." }, { "textRaw": "`noAssert` {boolean} Skip `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows offset to be beyond the end of buf, but\nthe resulting behavior is undefined.

\n

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

\n

Examples:

\n
const buf = Buffer.from([0, 5]);\n\n// Prints: 5\nconsole.log(buf.readInt16BE());\n\n// Prints: 1280\nconsole.log(buf.readInt16LE());\n\n// Throws an exception: RangeError: Index out of range\nconsole.log(buf.readInt16LE(1));\n
\n" }, { "textRaw": "buf.readInt16LE(offset[, noAssert])", "type": "method", "name": "readInt16LE", "meta": { "added": [ "v0.5.5" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} ", "name": "return", "type": "integer" }, "params": [ { "textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 2`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 2`." }, { "textRaw": "`noAssert` {boolean} Skip `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows offset to be beyond the end of buf, but\nthe resulting behavior is undefined.

\n

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

\n

Examples:

\n
const buf = Buffer.from([0, 5]);\n\n// Prints: 5\nconsole.log(buf.readInt16BE());\n\n// Prints: 1280\nconsole.log(buf.readInt16LE());\n\n// Throws an exception: RangeError: Index out of range\nconsole.log(buf.readInt16LE(1));\n
\n" }, { "textRaw": "buf.readInt32BE(offset[, noAssert])", "type": "method", "name": "readInt32BE", "meta": { "added": [ "v0.5.5" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} ", "name": "return", "type": "integer" }, "params": [ { "textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 4`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 4`." }, { "textRaw": "`noAssert` {boolean} Skip `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows offset to be beyond the end of buf, but\nthe resulting behavior is undefined.

\n

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

\n

Examples:

\n
const buf = Buffer.from([0, 0, 0, 5]);\n\n// Prints: 5\nconsole.log(buf.readInt32BE());\n\n// Prints: 83886080\nconsole.log(buf.readInt32LE());\n\n// Throws an exception: RangeError: Index out of range\nconsole.log(buf.readInt32LE(1));\n
\n" }, { "textRaw": "buf.readInt32LE(offset[, noAssert])", "type": "method", "name": "readInt32LE", "meta": { "added": [ "v0.5.5" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} ", "name": "return", "type": "integer" }, "params": [ { "textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 4`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 4`." }, { "textRaw": "`noAssert` {boolean} Skip `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows offset to be beyond the end of buf, but\nthe resulting behavior is undefined.

\n

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

\n

Examples:

\n
const buf = Buffer.from([0, 0, 0, 5]);\n\n// Prints: 5\nconsole.log(buf.readInt32BE());\n\n// Prints: 83886080\nconsole.log(buf.readInt32LE());\n\n// Throws an exception: RangeError: Index out of range\nconsole.log(buf.readInt32LE(1));\n
\n" }, { "textRaw": "buf.readIntBE(offset, byteLength[, noAssert])", "type": "method", "name": "readIntBE", "meta": { "added": [ "v0.11.15" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} ", "name": "return", "type": "integer" }, "params": [ { "textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - byteLength`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - byteLength`." }, { "textRaw": "`byteLength` {integer} Number of bytes to read. Must satisfy: `0 < byteLength <= 6`. ", "name": "byteLength", "type": "integer", "desc": "Number of bytes to read. Must satisfy: `0 < byteLength <= 6`." }, { "textRaw": "`noAssert` {boolean} Skip `offset` and `byteLength` validation? **Default:** `false`. ", "name": "noAssert", "type": "boolean", "desc": "Skip `offset` and `byteLength` validation? **Default:** `false`.", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "byteLength" }, { "name": "noAssert", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "byteLength" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows offset to be beyond the end of buf, but\nthe resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);\n\n// Prints: -546f87a9cbee\nconsole.log(buf.readIntLE(0, 6).toString(16));\n\n// Prints: 1234567890ab\nconsole.log(buf.readIntBE(0, 6).toString(16));\n\n// Throws an exception: RangeError: Index out of range\nconsole.log(buf.readIntBE(1, 6).toString(16));\n
\n" }, { "textRaw": "buf.readIntLE(offset, byteLength[, noAssert])", "type": "method", "name": "readIntLE", "meta": { "added": [ "v0.11.15" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} ", "name": "return", "type": "integer" }, "params": [ { "textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - byteLength`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - byteLength`." }, { "textRaw": "`byteLength` {integer} Number of bytes to read. Must satisfy: `0 < byteLength <= 6`. ", "name": "byteLength", "type": "integer", "desc": "Number of bytes to read. Must satisfy: `0 < byteLength <= 6`." }, { "textRaw": "`noAssert` {boolean} Skip `offset` and `byteLength` validation? **Default:** `false`. ", "name": "noAssert", "type": "boolean", "desc": "Skip `offset` and `byteLength` validation? **Default:** `false`.", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "byteLength" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows offset to be beyond the end of buf, but\nthe resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);\n\n// Prints: -546f87a9cbee\nconsole.log(buf.readIntLE(0, 6).toString(16));\n\n// Prints: 1234567890ab\nconsole.log(buf.readIntBE(0, 6).toString(16));\n\n// Throws an exception: RangeError: Index out of range\nconsole.log(buf.readIntBE(1, 6).toString(16));\n
\n" }, { "textRaw": "buf.readUInt8(offset[, noAssert])", "type": "method", "name": "readUInt8", "meta": { "added": [ "v0.5.0" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} ", "name": "return", "type": "integer" }, "params": [ { "textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 1`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 1`." }, { "textRaw": "`noAssert` {boolean} Skip `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

\n

Setting noAssert to true allows offset to be beyond the end of buf, but\nthe resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.from([1, -2]);\n\n// Prints: 1\nconsole.log(buf.readUInt8(0));\n\n// Prints: 254\nconsole.log(buf.readUInt8(1));\n\n// Throws an exception: RangeError: Index out of range\nconsole.log(buf.readUInt8(2));\n
\n" }, { "textRaw": "buf.readUInt16BE(offset[, noAssert])", "type": "method", "name": "readUInt16BE", "meta": { "added": [ "v0.5.5" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} ", "name": "return", "type": "integer" }, "params": [ { "textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 2`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 2`." }, { "textRaw": "`noAssert` {boolean} Skip `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows offset to be beyond the end of buf, but\nthe resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.from([0x12, 0x34, 0x56]);\n\n// Prints: 1234\nconsole.log(buf.readUInt16BE(0).toString(16));\n\n// Prints: 3412\nconsole.log(buf.readUInt16LE(0).toString(16));\n\n// Prints: 3456\nconsole.log(buf.readUInt16BE(1).toString(16));\n\n// Prints: 5634\nconsole.log(buf.readUInt16LE(1).toString(16));\n\n// Throws an exception: RangeError: Index out of range\nconsole.log(buf.readUInt16LE(2).toString(16));\n
\n" }, { "textRaw": "buf.readUInt16LE(offset[, noAssert])", "type": "method", "name": "readUInt16LE", "meta": { "added": [ "v0.5.5" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} ", "name": "return", "type": "integer" }, "params": [ { "textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 2`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 2`." }, { "textRaw": "`noAssert` {boolean} Skip `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows offset to be beyond the end of buf, but\nthe resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.from([0x12, 0x34, 0x56]);\n\n// Prints: 1234\nconsole.log(buf.readUInt16BE(0).toString(16));\n\n// Prints: 3412\nconsole.log(buf.readUInt16LE(0).toString(16));\n\n// Prints: 3456\nconsole.log(buf.readUInt16BE(1).toString(16));\n\n// Prints: 5634\nconsole.log(buf.readUInt16LE(1).toString(16));\n\n// Throws an exception: RangeError: Index out of range\nconsole.log(buf.readUInt16LE(2).toString(16));\n
\n" }, { "textRaw": "buf.readUInt32BE(offset[, noAssert])", "type": "method", "name": "readUInt32BE", "meta": { "added": [ "v0.5.5" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} ", "name": "return", "type": "integer" }, "params": [ { "textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 4`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 4`." }, { "textRaw": "`noAssert` {boolean} Skip `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows offset to be beyond the end of buf, but\nthe resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);\n\n// Prints: 12345678\nconsole.log(buf.readUInt32BE(0).toString(16));\n\n// Prints: 78563412\nconsole.log(buf.readUInt32LE(0).toString(16));\n\n// Throws an exception: RangeError: Index out of range\nconsole.log(buf.readUInt32LE(1).toString(16));\n
\n" }, { "textRaw": "buf.readUInt32LE(offset[, noAssert])", "type": "method", "name": "readUInt32LE", "meta": { "added": [ "v0.5.5" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} ", "name": "return", "type": "integer" }, "params": [ { "textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 4`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 4`." }, { "textRaw": "`noAssert` {boolean} Skip `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows offset to be beyond the end of buf, but\nthe resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);\n\n// Prints: 12345678\nconsole.log(buf.readUInt32BE(0).toString(16));\n\n// Prints: 78563412\nconsole.log(buf.readUInt32LE(0).toString(16));\n\n// Throws an exception: RangeError: Index out of range\nconsole.log(buf.readUInt32LE(1).toString(16));\n
\n" }, { "textRaw": "buf.readUIntBE(offset, byteLength[, noAssert])", "type": "method", "name": "readUIntBE", "meta": { "added": [ "v0.11.15" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} ", "name": "return", "type": "integer" }, "params": [ { "textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - byteLength`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - byteLength`." }, { "textRaw": "`byteLength` {integer} Number of bytes to read. Must satisfy: `0 < byteLength <= 6`. ", "name": "byteLength", "type": "integer", "desc": "Number of bytes to read. Must satisfy: `0 < byteLength <= 6`." }, { "textRaw": "`noAssert` {boolean} Skip `offset` and `byteLength` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `offset` and `byteLength` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "byteLength" }, { "name": "noAssert", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "byteLength" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows offset to be beyond the end of buf, but\nthe resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);\n\n// Prints: 1234567890ab\nconsole.log(buf.readUIntBE(0, 6).toString(16));\n\n// Prints: ab9078563412\nconsole.log(buf.readUIntLE(0, 6).toString(16));\n\n// Throws an exception: RangeError: Index out of range\nconsole.log(buf.readUIntBE(1, 6).toString(16));\n
\n" }, { "textRaw": "buf.readUIntLE(offset, byteLength[, noAssert])", "type": "method", "name": "readUIntLE", "meta": { "added": [ "v0.11.15" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} ", "name": "return", "type": "integer" }, "params": [ { "textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - byteLength`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - byteLength`." }, { "textRaw": "`byteLength` {integer} Number of bytes to read. Must satisfy: `0 < byteLength <= 6`. ", "name": "byteLength", "type": "integer", "desc": "Number of bytes to read. Must satisfy: `0 < byteLength <= 6`." }, { "textRaw": "`noAssert` {boolean} Skip `offset` and `byteLength` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `offset` and `byteLength` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "byteLength" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows offset to be beyond the end of buf, but\nthe resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);\n\n// Prints: 1234567890ab\nconsole.log(buf.readUIntBE(0, 6).toString(16));\n\n// Prints: ab9078563412\nconsole.log(buf.readUIntLE(0, 6).toString(16));\n\n// Throws an exception: RangeError: Index out of range\nconsole.log(buf.readUIntBE(1, 6).toString(16));\n
\n" }, { "textRaw": "buf.slice([start[, end]])", "type": "method", "name": "slice", "meta": { "added": [ "v0.3.0" ] }, "signatures": [ { "return": { "textRaw": "Returns: {Buffer} ", "name": "return", "type": "Buffer" }, "params": [ { "textRaw": "`start` {integer} Where the new `Buffer` will start. **Default:** `0` ", "name": "start", "type": "integer", "desc": "Where the new `Buffer` will start. **Default:** `0`", "optional": true }, { "textRaw": "`end` {integer} Where the new `Buffer` will end (not inclusive). **Default:** [`buf.length`] ", "name": "end", "type": "integer", "desc": "Where the new `Buffer` will end (not inclusive). **Default:** [`buf.length`]", "optional": true } ] }, { "params": [ { "name": "start", "optional": true }, { "name": "end", "optional": true } ] } ], "desc": "

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

\n

Note that modifying the new Buffer slice will modify the memory in the\noriginal Buffer because the allocated memory of the two objects overlap.

\n

Example: Create a Buffer with the ASCII alphabet, take a slice, and then modify\none byte from the original Buffer

\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\nconst buf2 = buf1.slice(0, 3);\n\n// Prints: abc\nconsole.log(buf2.toString('ascii', 0, buf2.length));\n\nbuf1[0] = 33;\n\n// Prints: !bc\nconsole.log(buf2.toString('ascii', 0, buf2.length));\n
\n

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

\n

Examples:

\n
const buf = Buffer.from('buffer');\n\n// Prints: buffe\n// (Equivalent to buf.slice(0, 5))\nconsole.log(buf.slice(-6, -1).toString());\n\n// Prints: buff\n// (Equivalent to buf.slice(0, 4))\nconsole.log(buf.slice(-6, -2).toString());\n\n// Prints: uff\n// (Equivalent to buf.slice(1, 4))\nconsole.log(buf.slice(-5, -2).toString());\n
\n" }, { "textRaw": "buf.swap16()", "type": "method", "name": "swap16", "meta": { "added": [ "v5.10.0" ] }, "signatures": [ { "return": { "textRaw": "Returns: {Buffer} A reference to `buf`. ", "name": "return", "type": "Buffer", "desc": "A reference to `buf`." }, "params": [] }, { "params": [] } ], "desc": "

Interprets buf as an array of unsigned 16-bit integers and swaps the byte-order\nin-place. Throws a RangeError if buf.length is not a multiple of 2.

\n

Examples:

\n
const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);\n\n// Prints: <Buffer 01 02 03 04 05 06 07 08>\nconsole.log(buf1);\n\nbuf1.swap16();\n\n// Prints: <Buffer 02 01 04 03 06 05 08 07>\nconsole.log(buf1);\n\n\nconst buf2 = Buffer.from([0x1, 0x2, 0x3]);\n\n// Throws an exception: RangeError: Buffer size must be a multiple of 16-bits\nbuf2.swap16();\n
\n" }, { "textRaw": "buf.swap32()", "type": "method", "name": "swap32", "meta": { "added": [ "v5.10.0" ] }, "signatures": [ { "return": { "textRaw": "Returns: {Buffer} A reference to `buf`. ", "name": "return", "type": "Buffer", "desc": "A reference to `buf`." }, "params": [] }, { "params": [] } ], "desc": "

Interprets buf as an array of unsigned 32-bit integers and swaps the byte-order\nin-place. Throws a RangeError if buf.length is not a multiple of 4.

\n

Examples:

\n
const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);\n\n// Prints: <Buffer 01 02 03 04 05 06 07 08>\nconsole.log(buf1);\n\nbuf1.swap32();\n\n// Prints: <Buffer 04 03 02 01 08 07 06 05>\nconsole.log(buf1);\n\n\nconst buf2 = Buffer.from([0x1, 0x2, 0x3]);\n\n// Throws an exception: RangeError: Buffer size must be a multiple of 32-bits\nbuf2.swap32();\n
\n" }, { "textRaw": "buf.swap64()", "type": "method", "name": "swap64", "meta": { "added": [ "v6.3.0" ] }, "signatures": [ { "return": { "textRaw": "Returns: {Buffer} A reference to `buf`. ", "name": "return", "type": "Buffer", "desc": "A reference to `buf`." }, "params": [] }, { "params": [] } ], "desc": "

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

\n

Examples:

\n
const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);\n\n// Prints: <Buffer 01 02 03 04 05 06 07 08>\nconsole.log(buf1);\n\nbuf1.swap64();\n\n// Prints: <Buffer 08 07 06 05 04 03 02 01>\nconsole.log(buf1);\n\n\nconst buf2 = Buffer.from([0x1, 0x2, 0x3]);\n\n// Throws an exception: RangeError: Buffer size must be a multiple of 64-bits\nbuf2.swap64();\n
\n

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

\n" }, { "textRaw": "buf.toString([encoding[, start[, end]]])", "type": "method", "name": "toString", "meta": { "added": [ "v0.1.90" ] }, "signatures": [ { "return": { "textRaw": "Returns: {string} ", "name": "return", "type": "string" }, "params": [ { "textRaw": "`encoding` {string} The character encoding to decode to. **Default:** `'utf8'` ", "name": "encoding", "type": "string", "desc": "The character encoding to decode to. **Default:** `'utf8'`", "optional": true }, { "textRaw": "`start` {integer} The byte offset to start decoding at. **Default:** `0` ", "name": "start", "type": "integer", "desc": "The byte offset to start decoding at. **Default:** `0`", "optional": true }, { "textRaw": "`end` {integer} The byte offset to stop decoding at (not inclusive). **Default:** [`buf.length`] ", "name": "end", "type": "integer", "desc": "The byte offset to stop decoding at (not inclusive). **Default:** [`buf.length`]", "optional": true } ] }, { "params": [ { "name": "encoding", "optional": true }, { "name": "start", "optional": true }, { "name": "end", "optional": true } ] } ], "desc": "

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.

\n

Examples:

\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\n// Prints: abcdefghijklmnopqrstuvwxyz\nconsole.log(buf1.toString('ascii'));\n\n// Prints: abcde\nconsole.log(buf1.toString('ascii', 0, 5));\n\n\nconst buf2 = Buffer.from('tést');\n\n// Prints: 74c3a97374\nconsole.log(buf2.toString('hex'));\n\n// Prints: té\nconsole.log(buf2.toString('utf8', 0, 3));\n\n// Prints: té\nconsole.log(buf2.toString(undefined, 0, 3));\n
\n" }, { "textRaw": "buf.toJSON()", "type": "method", "name": "toJSON", "meta": { "added": [ "v0.9.2" ] }, "signatures": [ { "return": { "textRaw": "Returns: {Object} ", "name": "return", "type": "Object" }, "params": [] }, { "params": [] } ], "desc": "

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

\n

Example:

\n
const buf = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5]);\nconst json = JSON.stringify(buf);\n\n// Prints: {"type":"Buffer","data":[1,2,3,4,5]}\nconsole.log(json);\n\nconst copy = JSON.parse(json, (key, value) => {\n  return value && value.type === 'Buffer' ?\n    Buffer.from(value.data) :\n    value;\n});\n\n// Prints: <Buffer 01 02 03 04 05>\nconsole.log(copy);\n
\n" }, { "textRaw": "buf.values()", "type": "method", "name": "values", "meta": { "added": [ "v1.1.0" ] }, "signatures": [ { "return": { "textRaw": "Returns: {Iterator} ", "name": "return", "type": "Iterator" }, "params": [] }, { "params": [] } ], "desc": "

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

Examples:

\n
const buf = Buffer.from('buffer');\n\n// Prints:\n//   98\n//   117\n//   102\n//   102\n//   101\n//   114\nfor (const value of buf.values()) {\n  console.log(value);\n}\n\n// Prints:\n//   98\n//   117\n//   102\n//   102\n//   101\n//   114\nfor (const value of buf) {\n  console.log(value);\n}\n
\n" }, { "textRaw": "buf.write(string[, offset[, length]][, encoding])", "type": "method", "name": "write", "meta": { "added": [ "v0.1.90" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} Number of bytes written. ", "name": "return", "type": "integer", "desc": "Number of bytes written." }, "params": [ { "textRaw": "`string` {string} String to be written to `buf`. ", "name": "string", "type": "string", "desc": "String to be written to `buf`." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to write `string`. **Default:** `0` ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to write `string`. **Default:** `0`", "optional": true }, { "textRaw": "`length` {integer} Number of bytes to write. **Default:** `buf.length - offset` ", "name": "length", "type": "integer", "desc": "Number of bytes to write. **Default:** `buf.length - offset`", "optional": true }, { "textRaw": "`encoding` {string} The character encoding of `string`. **Default:** `'utf8'` ", "name": "encoding", "type": "string", "desc": "The character encoding of `string`. **Default:** `'utf8'`", "optional": true } ] }, { "params": [ { "name": "string" }, { "name": "offset", "optional": true }, { "name": "length", "optional": true }, { "name": "encoding", "optional": true } ] } ], "desc": "

Writes string to buf at offset according to the character encoding in encoding.\nThe length parameter is the number of bytes to write. If buf did not contain\nenough space to fit the entire string, only a partial amount of string will\nbe written. However, partially encoded characters will not be written.

\n

Example:

\n
const buf = Buffer.allocUnsafe(256);\n\nconst len = buf.write('\\u00bd + \\u00bc = \\u00be', 0);\n\n// Prints: 12 bytes: ½ + ¼ = ¾\nconsole.log(`${len} bytes: ${buf.toString('utf8', 0, len)}`);\n
\n" }, { "textRaw": "buf.writeDoubleBE(value, offset[, noAssert])", "type": "method", "name": "writeDoubleBE", "meta": { "added": [ "v0.11.15" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} `offset` plus the number of bytes written. ", "name": "return", "type": "integer", "desc": "`offset` plus the number of bytes written." }, "params": [ { "textRaw": "`value` {number} Number to be written to `buf`. ", "name": "value", "type": "number", "desc": "Number to be written to `buf`." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`." }, { "textRaw": "`noAssert` {boolean} Skip `value` and `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `value` and `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows the encoded form of value to extend beyond\nthe end of buf, but the resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.allocUnsafe(8);\n\nbuf.writeDoubleBE(0xdeadbeefcafebabe, 0);\n\n// Prints: <Buffer 43 eb d5 b7 dd f9 5f d7>\nconsole.log(buf);\n\nbuf.writeDoubleLE(0xdeadbeefcafebabe, 0);\n\n// Prints: <Buffer d7 5f f9 dd b7 d5 eb 43>\nconsole.log(buf);\n
\n" }, { "textRaw": "buf.writeDoubleLE(value, offset[, noAssert])", "type": "method", "name": "writeDoubleLE", "meta": { "added": [ "v0.11.15" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} `offset` plus the number of bytes written. ", "name": "return", "type": "integer", "desc": "`offset` plus the number of bytes written." }, "params": [ { "textRaw": "`value` {number} Number to be written to `buf`. ", "name": "value", "type": "number", "desc": "Number to be written to `buf`." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`." }, { "textRaw": "`noAssert` {boolean} Skip `value` and `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `value` and `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows the encoded form of value to extend beyond\nthe end of buf, but the resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.allocUnsafe(8);\n\nbuf.writeDoubleBE(0xdeadbeefcafebabe, 0);\n\n// Prints: <Buffer 43 eb d5 b7 dd f9 5f d7>\nconsole.log(buf);\n\nbuf.writeDoubleLE(0xdeadbeefcafebabe, 0);\n\n// Prints: <Buffer d7 5f f9 dd b7 d5 eb 43>\nconsole.log(buf);\n
\n" }, { "textRaw": "buf.writeFloatBE(value, offset[, noAssert])", "type": "method", "name": "writeFloatBE", "meta": { "added": [ "v0.11.15" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} `offset` plus the number of bytes written. ", "name": "return", "type": "integer", "desc": "`offset` plus the number of bytes written." }, "params": [ { "textRaw": "`value` {number} Number to be written to `buf`. ", "name": "value", "type": "number", "desc": "Number to be written to `buf`." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 4`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 4`." }, { "textRaw": "`noAssert` {boolean} Skip `value` and `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `value` and `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows the encoded form of value to extend beyond\nthe end of buf, but the resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.allocUnsafe(4);\n\nbuf.writeFloatBE(0xcafebabe, 0);\n\n// Prints: <Buffer 4f 4a fe bb>\nconsole.log(buf);\n\nbuf.writeFloatLE(0xcafebabe, 0);\n\n// Prints: <Buffer bb fe 4a 4f>\nconsole.log(buf);\n
\n" }, { "textRaw": "buf.writeFloatLE(value, offset[, noAssert])", "type": "method", "name": "writeFloatLE", "meta": { "added": [ "v0.11.15" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} `offset` plus the number of bytes written. ", "name": "return", "type": "integer", "desc": "`offset` plus the number of bytes written." }, "params": [ { "textRaw": "`value` {number} Number to be written to `buf`. ", "name": "value", "type": "number", "desc": "Number to be written to `buf`." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 4`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 4`." }, { "textRaw": "`noAssert` {boolean} Skip `value` and `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `value` and `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows the encoded form of value to extend beyond\nthe end of buf, but the resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.allocUnsafe(4);\n\nbuf.writeFloatBE(0xcafebabe, 0);\n\n// Prints: <Buffer 4f 4a fe bb>\nconsole.log(buf);\n\nbuf.writeFloatLE(0xcafebabe, 0);\n\n// Prints: <Buffer bb fe 4a 4f>\nconsole.log(buf);\n
\n" }, { "textRaw": "buf.writeInt8(value, offset[, noAssert])", "type": "method", "name": "writeInt8", "meta": { "added": [ "v0.5.0" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} `offset` plus the number of bytes written. ", "name": "return", "type": "integer", "desc": "`offset` plus the number of bytes written." }, "params": [ { "textRaw": "`value` {integer} Number to be written to `buf`. ", "name": "value", "type": "integer", "desc": "Number to be written to `buf`." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 1`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 1`." }, { "textRaw": "`noAssert` {boolean} Skip `value` and `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `value` and `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows the encoded form of value to extend beyond\nthe end of buf, but the resulting behavior is undefined.

\n

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

\n

Examples:

\n
const buf = Buffer.allocUnsafe(2);\n\nbuf.writeInt8(2, 0);\nbuf.writeInt8(-2, 1);\n\n// Prints: <Buffer 02 fe>\nconsole.log(buf);\n
\n" }, { "textRaw": "buf.writeInt16BE(value, offset[, noAssert])", "type": "method", "name": "writeInt16BE", "meta": { "added": [ "v0.5.5" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} `offset` plus the number of bytes written. ", "name": "return", "type": "integer", "desc": "`offset` plus the number of bytes written." }, "params": [ { "textRaw": "`value` {integer} Number to be written to `buf`. ", "name": "value", "type": "integer", "desc": "Number to be written to `buf`." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 2`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 2`." }, { "textRaw": "`noAssert` {boolean} Skip `value` and `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `value` and `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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 undefined\nwhen value is anything other than a signed 16-bit integer.

\n

Setting noAssert to true allows the encoded form of value to extend beyond\nthe end of buf, but the resulting behavior is undefined.

\n

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

\n

Examples:

\n
const buf = Buffer.allocUnsafe(4);\n\nbuf.writeInt16BE(0x0102, 0);\nbuf.writeInt16LE(0x0304, 2);\n\n// Prints: <Buffer 01 02 04 03>\nconsole.log(buf);\n
\n" }, { "textRaw": "buf.writeInt16LE(value, offset[, noAssert])", "type": "method", "name": "writeInt16LE", "meta": { "added": [ "v0.5.5" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} `offset` plus the number of bytes written. ", "name": "return", "type": "integer", "desc": "`offset` plus the number of bytes written." }, "params": [ { "textRaw": "`value` {integer} Number to be written to `buf`. ", "name": "value", "type": "integer", "desc": "Number to be written to `buf`." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 2`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 2`." }, { "textRaw": "`noAssert` {boolean} Skip `value` and `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `value` and `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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 undefined\nwhen value is anything other than a signed 16-bit integer.

\n

Setting noAssert to true allows the encoded form of value to extend beyond\nthe end of buf, but the resulting behavior is undefined.

\n

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

\n

Examples:

\n
const buf = Buffer.allocUnsafe(4);\n\nbuf.writeInt16BE(0x0102, 0);\nbuf.writeInt16LE(0x0304, 2);\n\n// Prints: <Buffer 01 02 04 03>\nconsole.log(buf);\n
\n" }, { "textRaw": "buf.writeInt32BE(value, offset[, noAssert])", "type": "method", "name": "writeInt32BE", "meta": { "added": [ "v0.5.5" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} `offset` plus the number of bytes written. ", "name": "return", "type": "integer", "desc": "`offset` plus the number of bytes written." }, "params": [ { "textRaw": "`value` {integer} Number to be written to `buf`. ", "name": "value", "type": "integer", "desc": "Number to be written to `buf`." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 4`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 4`." }, { "textRaw": "`noAssert` {boolean} Skip `value` and `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `value` and `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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 undefined\nwhen value is anything other than a signed 32-bit integer.

\n

Setting noAssert to true allows the encoded form of value to extend beyond\nthe end of buf, but the resulting behavior is undefined.

\n

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

\n

Examples:

\n
const buf = Buffer.allocUnsafe(8);\n\nbuf.writeInt32BE(0x01020304, 0);\nbuf.writeInt32LE(0x05060708, 4);\n\n// Prints: <Buffer 01 02 03 04 08 07 06 05>\nconsole.log(buf);\n
\n" }, { "textRaw": "buf.writeInt32LE(value, offset[, noAssert])", "type": "method", "name": "writeInt32LE", "meta": { "added": [ "v0.5.5" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} `offset` plus the number of bytes written. ", "name": "return", "type": "integer", "desc": "`offset` plus the number of bytes written." }, "params": [ { "textRaw": "`value` {integer} Number to be written to `buf`. ", "name": "value", "type": "integer", "desc": "Number to be written to `buf`." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 4`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 4`." }, { "textRaw": "`noAssert` {boolean} Skip `value` and `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `value` and `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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 undefined\nwhen value is anything other than a signed 32-bit integer.

\n

Setting noAssert to true allows the encoded form of value to extend beyond\nthe end of buf, but the resulting behavior is undefined.

\n

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

\n

Examples:

\n
const buf = Buffer.allocUnsafe(8);\n\nbuf.writeInt32BE(0x01020304, 0);\nbuf.writeInt32LE(0x05060708, 4);\n\n// Prints: <Buffer 01 02 03 04 08 07 06 05>\nconsole.log(buf);\n
\n" }, { "textRaw": "buf.writeIntBE(value, offset, byteLength[, noAssert])", "type": "method", "name": "writeIntBE", "meta": { "added": [ "v0.11.15" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} `offset` plus the number of bytes written. ", "name": "return", "type": "integer", "desc": "`offset` plus the number of bytes written." }, "params": [ { "textRaw": "`value` {integer} Number to be written to `buf`. ", "name": "value", "type": "integer", "desc": "Number to be written to `buf`." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - byteLength`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - byteLength`." }, { "textRaw": "`byteLength` {integer} Number of bytes to write. Must satisfy: `0 < byteLength <= 6`. ", "name": "byteLength", "type": "integer", "desc": "Number of bytes to write. Must satisfy: `0 < byteLength <= 6`." }, { "textRaw": "`noAssert` {boolean} Skip `value`, `offset`, and `byteLength` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `value`, `offset`, and `byteLength` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "byteLength" }, { "name": "noAssert", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "byteLength" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows the encoded form of value to extend beyond\nthe end of buf, but the resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.allocUnsafe(6);\n\nbuf.writeUIntBE(0x1234567890ab, 0, 6);\n\n// Prints: <Buffer 12 34 56 78 90 ab>\nconsole.log(buf);\n\nbuf.writeUIntLE(0x1234567890ab, 0, 6);\n\n// Prints: <Buffer ab 90 78 56 34 12>\nconsole.log(buf);\n
\n" }, { "textRaw": "buf.writeIntLE(value, offset, byteLength[, noAssert])", "type": "method", "name": "writeIntLE", "meta": { "added": [ "v0.11.15" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} `offset` plus the number of bytes written. ", "name": "return", "type": "integer", "desc": "`offset` plus the number of bytes written." }, "params": [ { "textRaw": "`value` {integer} Number to be written to `buf`. ", "name": "value", "type": "integer", "desc": "Number to be written to `buf`." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - byteLength`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - byteLength`." }, { "textRaw": "`byteLength` {integer} Number of bytes to write. Must satisfy: `0 < byteLength <= 6`. ", "name": "byteLength", "type": "integer", "desc": "Number of bytes to write. Must satisfy: `0 < byteLength <= 6`." }, { "textRaw": "`noAssert` {boolean} Skip `value`, `offset`, and `byteLength` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `value`, `offset`, and `byteLength` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "byteLength" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows the encoded form of value to extend beyond\nthe end of buf, but the resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.allocUnsafe(6);\n\nbuf.writeUIntBE(0x1234567890ab, 0, 6);\n\n// Prints: <Buffer 12 34 56 78 90 ab>\nconsole.log(buf);\n\nbuf.writeUIntLE(0x1234567890ab, 0, 6);\n\n// Prints: <Buffer ab 90 78 56 34 12>\nconsole.log(buf);\n
\n" }, { "textRaw": "buf.writeUInt8(value, offset[, noAssert])", "type": "method", "name": "writeUInt8", "meta": { "added": [ "v0.5.0" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} `offset` plus the number of bytes written. ", "name": "return", "type": "integer", "desc": "`offset` plus the number of bytes written." }, "params": [ { "textRaw": "`value` {integer} Number to be written to `buf`. ", "name": "value", "type": "integer", "desc": "Number to be written to `buf`." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 1`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 1`." }, { "textRaw": "`noAssert` {boolean} Skip `value` and `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `value` and `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows the encoded form of value to extend beyond\nthe end of buf, but the resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.allocUnsafe(4);\n\nbuf.writeUInt8(0x3, 0);\nbuf.writeUInt8(0x4, 1);\nbuf.writeUInt8(0x23, 2);\nbuf.writeUInt8(0x42, 3);\n\n// Prints: <Buffer 03 04 23 42>\nconsole.log(buf);\n
\n" }, { "textRaw": "buf.writeUInt16BE(value, offset[, noAssert])", "type": "method", "name": "writeUInt16BE", "meta": { "added": [ "v0.5.5" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} `offset` plus the number of bytes written. ", "name": "return", "type": "integer", "desc": "`offset` plus the number of bytes written." }, "params": [ { "textRaw": "`value` {integer} Number to be written to `buf`. ", "name": "value", "type": "integer", "desc": "Number to be written to `buf`." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 2`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 2`." }, { "textRaw": "`noAssert` {boolean} Skip `value` and `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `value` and `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows the encoded form of value to extend beyond\nthe end of buf, but the resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.allocUnsafe(4);\n\nbuf.writeUInt16BE(0xdead, 0);\nbuf.writeUInt16BE(0xbeef, 2);\n\n// Prints: <Buffer de ad be ef>\nconsole.log(buf);\n\nbuf.writeUInt16LE(0xdead, 0);\nbuf.writeUInt16LE(0xbeef, 2);\n\n// Prints: <Buffer ad de ef be>\nconsole.log(buf);\n
\n" }, { "textRaw": "buf.writeUInt16LE(value, offset[, noAssert])", "type": "method", "name": "writeUInt16LE", "meta": { "added": [ "v0.5.5" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} `offset` plus the number of bytes written. ", "name": "return", "type": "integer", "desc": "`offset` plus the number of bytes written." }, "params": [ { "textRaw": "`value` {integer} Number to be written to `buf`. ", "name": "value", "type": "integer", "desc": "Number to be written to `buf`." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 2`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 2`." }, { "textRaw": "`noAssert` {boolean} Skip `value` and `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `value` and `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows the encoded form of value to extend beyond\nthe end of buf, but the resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.allocUnsafe(4);\n\nbuf.writeUInt16BE(0xdead, 0);\nbuf.writeUInt16BE(0xbeef, 2);\n\n// Prints: <Buffer de ad be ef>\nconsole.log(buf);\n\nbuf.writeUInt16LE(0xdead, 0);\nbuf.writeUInt16LE(0xbeef, 2);\n\n// Prints: <Buffer ad de ef be>\nconsole.log(buf);\n
\n" }, { "textRaw": "buf.writeUInt32BE(value, offset[, noAssert])", "type": "method", "name": "writeUInt32BE", "meta": { "added": [ "v0.5.5" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} `offset` plus the number of bytes written. ", "name": "return", "type": "integer", "desc": "`offset` plus the number of bytes written." }, "params": [ { "textRaw": "`value` {integer} Number to be written to `buf`. ", "name": "value", "type": "integer", "desc": "Number to be written to `buf`." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 4`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 4`." }, { "textRaw": "`noAssert` {boolean} Skip `value` and `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `value` and `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows the encoded form of value to extend beyond\nthe end of buf, but the resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.allocUnsafe(4);\n\nbuf.writeUInt32BE(0xfeedface, 0);\n\n// Prints: <Buffer fe ed fa ce>\nconsole.log(buf);\n\nbuf.writeUInt32LE(0xfeedface, 0);\n\n// Prints: <Buffer ce fa ed fe>\nconsole.log(buf);\n
\n" }, { "textRaw": "buf.writeUInt32LE(value, offset[, noAssert])", "type": "method", "name": "writeUInt32LE", "meta": { "added": [ "v0.5.5" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} `offset` plus the number of bytes written. ", "name": "return", "type": "integer", "desc": "`offset` plus the number of bytes written." }, "params": [ { "textRaw": "`value` {integer} Number to be written to `buf`. ", "name": "value", "type": "integer", "desc": "Number to be written to `buf`." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 4`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 4`." }, { "textRaw": "`noAssert` {boolean} Skip `value` and `offset` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `value` and `offset` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows the encoded form of value to extend beyond\nthe end of buf, but the resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.allocUnsafe(4);\n\nbuf.writeUInt32BE(0xfeedface, 0);\n\n// Prints: <Buffer fe ed fa ce>\nconsole.log(buf);\n\nbuf.writeUInt32LE(0xfeedface, 0);\n\n// Prints: <Buffer ce fa ed fe>\nconsole.log(buf);\n
\n" }, { "textRaw": "buf.writeUIntBE(value, offset, byteLength[, noAssert])", "type": "method", "name": "writeUIntBE", "meta": { "added": [ "v0.5.5" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} `offset` plus the number of bytes written. ", "name": "return", "type": "integer", "desc": "`offset` plus the number of bytes written." }, "params": [ { "textRaw": "`value` {integer} Number to be written to `buf`. ", "name": "value", "type": "integer", "desc": "Number to be written to `buf`." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - byteLength`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - byteLength`." }, { "textRaw": "`byteLength` {integer} Number of bytes to write. Must satisfy: `0 < byteLength <= 6`. ", "name": "byteLength", "type": "integer", "desc": "Number of bytes to write. Must satisfy: `0 < byteLength <= 6`." }, { "textRaw": "`noAssert` {boolean} Skip `value`, `offset`, and `byteLength` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `value`, `offset`, and `byteLength` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "byteLength" }, { "name": "noAssert", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "byteLength" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows the encoded form of value to extend beyond\nthe end of buf, but the resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.allocUnsafe(6);\n\nbuf.writeIntBE(0x1234567890ab, 0, 6);\n\n// Prints: <Buffer 12 34 56 78 90 ab>\nconsole.log(buf);\n\nbuf.writeIntLE(0x1234567890ab, 0, 6);\n\n// Prints: <Buffer ab 90 78 56 34 12>\nconsole.log(buf);\n
\n" }, { "textRaw": "buf.writeUIntLE(value, offset, byteLength[, noAssert])", "type": "method", "name": "writeUIntLE", "meta": { "added": [ "v0.5.5" ] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} `offset` plus the number of bytes written. ", "name": "return", "type": "integer", "desc": "`offset` plus the number of bytes written." }, "params": [ { "textRaw": "`value` {integer} Number to be written to `buf`. ", "name": "value", "type": "integer", "desc": "Number to be written to `buf`." }, { "textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - byteLength`. ", "name": "offset", "type": "integer", "desc": "Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - byteLength`." }, { "textRaw": "`byteLength` {integer} Number of bytes to write. Must satisfy: `0 < byteLength <= 6`. ", "name": "byteLength", "type": "integer", "desc": "Number of bytes to write. Must satisfy: `0 < byteLength <= 6`." }, { "textRaw": "`noAssert` {boolean} Skip `value`, `offset`, and `byteLength` validation? **Default:** `false` ", "name": "noAssert", "type": "boolean", "desc": "Skip `value`, `offset`, and `byteLength` validation? **Default:** `false`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "byteLength" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

Setting noAssert to true allows the encoded form of value to extend beyond\nthe end of buf, but the resulting behavior is undefined.

\n

Examples:

\n
const buf = Buffer.allocUnsafe(6);\n\nbuf.writeIntBE(0x1234567890ab, 0, 6);\n\n// Prints: <Buffer 12 34 56 78 90 ab>\nconsole.log(buf);\n\nbuf.writeIntLE(0x1234567890ab, 0, 6);\n\n// Prints: <Buffer ab 90 78 56 34 12>\nconsole.log(buf);\n
\n" } ], "signatures": [ { "params": [ { "textRaw": "`array` {integer[]} An array of bytes to copy from. ", "name": "array", "type": "integer[]", "desc": "An array of bytes to copy from." } ], "desc": "

Allocates a new Buffer using an array of octets.

\n

Example:

\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
\n" }, { "params": [ { "name": "array" } ], "desc": "

Allocates a new Buffer using an array of octets.

\n

Example:

\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
\n" }, { "params": [ { "textRaw": "`buffer` {Buffer} An existing `Buffer` to copy data from. ", "name": "buffer", "type": "Buffer", "desc": "An existing `Buffer` to copy data from." } ], "desc": "

Copies the passed buffer data onto a new Buffer instance.

\n

Example:

\n
const buf1 = new Buffer('buffer');\nconst buf2 = new Buffer(buf1);\n\nbuf1[0] = 0x61;\n\n// Prints: auffer\nconsole.log(buf1.toString());\n\n// Prints: buffer\nconsole.log(buf2.toString());\n
\n" }, { "params": [ { "name": "buffer" } ], "desc": "

Copies the passed buffer data onto a new Buffer instance.

\n

Example:

\n
const buf1 = new Buffer('buffer');\nconst buf2 = new Buffer(buf1);\n\nbuf1[0] = 0x61;\n\n// Prints: auffer\nconsole.log(buf1.toString());\n\n// Prints: buffer\nconsole.log(buf2.toString());\n
\n" }, { "params": [ { "textRaw": "`arrayBuffer` {ArrayBuffer|SharedArrayBuffer} An [`ArrayBuffer`], [`SharedArrayBuffer`] or the `.buffer` property of a [`TypedArray`]. ", "name": "arrayBuffer", "type": "ArrayBuffer|SharedArrayBuffer", "desc": "An [`ArrayBuffer`], [`SharedArrayBuffer`] or the `.buffer` property of a [`TypedArray`]." }, { "textRaw": "`byteOffset` {integer} Index of first byte to expose. **Default:** `0` ", "name": "byteOffset", "type": "integer", "desc": "Index of first byte to expose. **Default:** `0`", "optional": true }, { "textRaw": "`length` {integer} Number of bytes to expose. **Default:** `arrayBuffer.length - byteOffset` ", "name": "length", "type": "integer", "desc": "Number of bytes to expose. **Default:** `arrayBuffer.length - byteOffset`", "optional": true } ], "desc": "

Stability: 0 - Deprecated: Use\nBuffer.from(arrayBuffer[, byteOffset [, length]])\ninstead.

\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 will\nshare 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

Example:

\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\n// Prints: <Buffer 88 13 a0 0f>\nconsole.log(buf);\n\n// Changing the original Uint16Array changes the Buffer also\narr[1] = 6000;\n\n// Prints: <Buffer 88 13 70 17>\nconsole.log(buf);\n
\n" }, { "params": [ { "name": "arrayBuffer" }, { "name": "byteOffset", "optional": true }, { "name": "length", "optional": true } ], "desc": "

Stability: 0 - Deprecated: Use\nBuffer.from(arrayBuffer[, byteOffset [, length]])\ninstead.

\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 will\nshare 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

Example:

\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\n// Prints: <Buffer 88 13 a0 0f>\nconsole.log(buf);\n\n// Changing the original Uint16Array changes the Buffer also\narr[1] = 6000;\n\n// Prints: <Buffer 88 13 70 17>\nconsole.log(buf);\n
\n" }, { "params": [ { "textRaw": "`size` {integer} The desired length of the new `Buffer`. ", "name": "size", "type": "integer", "desc": "The desired length of the new `Buffer`." } ], "desc": "

Stability: 0 - Deprecated: Use Buffer.alloc() instead (also see\nBuffer.allocUnsafe()).

\n

Allocates a new Buffer of size bytes. The size must be less than or equal\nto the value of buffer.kMaxLength. Otherwise, a RangeError is thrown.\nA zero-length Buffer will be created if size <= 0.

\n

Unlike ArrayBuffers, the underlying memory for Buffer instances\ncreated in this way is not initialized. The contents of a newly created Buffer\nare unknown and could contain sensitive data. Use\nBuffer.alloc(size) instead to initialize a Buffer to zeroes.

\n

Example:

\n
const buf = new Buffer(10);\n\n// Prints: (contents may vary): <Buffer 48 21 4b 00 00 00 00 00 30 dd>\nconsole.log(buf);\n\nbuf.fill(0);\n\n// Prints: <Buffer 00 00 00 00 00 00 00 00 00 00>\nconsole.log(buf);\n
\n" }, { "params": [ { "name": "size" } ], "desc": "

Stability: 0 - Deprecated: Use Buffer.alloc() instead (also see\nBuffer.allocUnsafe()).

\n

Allocates a new Buffer of size bytes. The size must be less than or equal\nto the value of buffer.kMaxLength. Otherwise, a RangeError is thrown.\nA zero-length Buffer will be created if size <= 0.

\n

Unlike ArrayBuffers, the underlying memory for Buffer instances\ncreated in this way is not initialized. The contents of a newly created Buffer\nare unknown and could contain sensitive data. Use\nBuffer.alloc(size) instead to initialize a Buffer to zeroes.

\n

Example:

\n
const buf = new Buffer(10);\n\n// Prints: (contents may vary): <Buffer 48 21 4b 00 00 00 00 00 30 dd>\nconsole.log(buf);\n\nbuf.fill(0);\n\n// Prints: <Buffer 00 00 00 00 00 00 00 00 00 00>\nconsole.log(buf);\n
\n" }, { "params": [ { "textRaw": "`string` {string} String to encode. ", "name": "string", "type": "string", "desc": "String to encode." }, { "textRaw": "`encoding` {string} The encoding of `string`. **Default:** `'utf8'` ", "name": "encoding", "type": "string", "desc": "The encoding of `string`. **Default:** `'utf8'`", "optional": true } ], "desc": "

Stability: 0 - Deprecated:\nUse Buffer.from(string[, encoding]) instead.

\n

Creates a new Buffer containing the given JavaScript string string. If\nprovided, the encoding parameter identifies the character encoding of string.

\n

Examples:

\n
const buf1 = new Buffer('this is a tést');\n\n// Prints: this is a tést\nconsole.log(buf1.toString());\n\n// Prints: this is a tC)st\nconsole.log(buf1.toString('ascii'));\n\n\nconst buf2 = new Buffer('7468697320697320612074c3a97374', 'hex');\n\n// Prints: this is a tést\nconsole.log(buf2.toString());\n
\n" }, { "params": [ { "name": "string" }, { "name": "encoding", "optional": true } ], "desc": "

Stability: 0 - Deprecated:\nUse Buffer.from(string[, encoding]) instead.

\n

Creates a new Buffer containing the given JavaScript string string. If\nprovided, the encoding parameter identifies the character encoding of string.

\n

Examples:

\n
const buf1 = new Buffer('this is a tést');\n\n// Prints: this is a tést\nconsole.log(buf1.toString());\n\n// Prints: this is a tC)st\nconsole.log(buf1.toString('ascii'));\n\n\nconst buf2 = new Buffer('7468697320697320612074c3a97374', 'hex');\n\n// Prints: this is a tést\nconsole.log(buf2.toString());\n
\n" } ] }, { "textRaw": "Class: SlowBuffer", "type": "class", "name": "SlowBuffer", "meta": { "deprecated": [ "v6.0.0" ] }, "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. This approach improves both performance and memory\nusage since v8 does not need to track and cleanup as many Persistent objects.

\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

Example:

\n
// Need to keep around a few small chunks of memory\nconst store = [];\n\nsocket.on('readable', () => {\n  const data = socket.read();\n\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

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

\n", "signatures": [ { "params": [ { "textRaw": "`size` {integer} The desired length of the new `SlowBuffer`. ", "name": "size", "type": "integer", "desc": "The desired length of the new `SlowBuffer`." } ], "desc": "

Allocates a new SlowBuffer of size bytes. The size must be less than\nor equal to the value of buffer.kMaxLength. Otherwise, a RangeError is\nthrown. A zero-length Buffer will be created if size <= 0.

\n

The underlying memory for SlowBuffer instances is not initialized. The\ncontents of a newly created SlowBuffer are unknown and could contain\nsensitive data. Use buf.fill(0) to initialize a SlowBuffer to zeroes.

\n

Example:

\n
const SlowBuffer = require('buffer').SlowBuffer;\n\nconst buf = new SlowBuffer(5);\n\n// Prints: (contents may vary): <Buffer 78 e0 82 02 01>\nconsole.log(buf);\n\nbuf.fill(0);\n\n// Prints: <Buffer 00 00 00 00 00>\nconsole.log(buf);\n
\n" }, { "params": [ { "name": "size" } ], "desc": "

Allocates a new SlowBuffer of size bytes. The size must be less than\nor equal to the value of buffer.kMaxLength. Otherwise, a RangeError is\nthrown. A zero-length Buffer will be created if size <= 0.

\n

The underlying memory for SlowBuffer instances is not initialized. The\ncontents of a newly created SlowBuffer are unknown and could contain\nsensitive data. Use buf.fill(0) to initialize a SlowBuffer to zeroes.

\n

Example:

\n
const SlowBuffer = require('buffer').SlowBuffer;\n\nconst buf = new SlowBuffer(5);\n\n// Prints: (contents may vary): <Buffer 78 e0 82 02 01>\nconsole.log(buf);\n\nbuf.fill(0);\n\n// Prints: <Buffer 00 00 00 00 00>\nconsole.log(buf);\n
\n" } ] } ], "properties": [ { "textRaw": "`INSPECT_MAX_BYTES` {integer} **Default:** `50` ", "type": "integer", "name": "INSPECT_MAX_BYTES", "meta": { "added": [ "v0.5.4" ] }, "desc": "

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

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

\n", "shortDesc": "**Default:** `50`" }, { "textRaw": "`kMaxLength` {integer} The largest size allowed for a single `Buffer` instance. ", "type": "integer", "name": "kMaxLength", "meta": { "added": [ "v3.0.0" ] }, "desc": "

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

\n", "shortDesc": "The largest size allowed for a single `Buffer` instance." } ], "type": "module", "displayName": "Buffer" } ] }