{ "source": "doc/api/buffer.markdown", "modules": [ { "textRaw": "Buffer", "name": "buffer", "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\n

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

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

\n

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

\n
const buf1 = new Buffer(10);\n  // creates a buffer of length 10\n\nconst buf2 = new Buffer([1,2,3]);\n  // creates a buffer containing [01, 02, 03]\n\nconst buf3 = new Buffer('test');\n  // creates a buffer containing ASCII bytes [74, 65, 73, 74]\n\nconst buf4 = new Buffer('tést', 'utf8');\n  // creates a buffer containing UTF8 bytes [74, c3, a9, 73, 74]
\n", "modules": [ { "textRaw": "Buffers and Character Encodings", "name": "buffers_and_character_encodings", "desc": "

Buffers are commonly used to represent sequences of encoded characters\nsuch as UTF8, UCS2, Base64 or even Hex-encoded data. It is possible to\nconvert back and forth between Buffers and ordinary JavaScript string objects\nby using an explicit encoding method.\n\n

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

The character encodings currently supported by Node.js include:\n\n

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

Buffers are also Uint8Array TypedArray instances. However, there are subtle\nincompatibilities with the TypedArray specification in ECMAScript 2015. For\ninstance, while ArrayBuffer#slice() creates a copy of the slice,\nthe implementation of [Buffer#slice()][buf.slice()] creates a view over the\nexisting Buffer without copying, making Buffer#slice() far more efficient.\n\n

\n

It is also possible to create new TypedArray instances from a Buffer with the\nfollowing caveats:\n\n

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

    \n
  2. \n
  3. The Buffer's memory is interpreted as an array of distinct elements, and not\nas a byte array of the target type. That is,\nnew Uint32Array(new Buffer([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 objects .buffer property:\n\n

\n
const arr = new Uint16Array(2);\narr[0] = 5000;\narr[1] = 4000;\n\nconst buf1 = new Buffer(arr); // copies the buffer\nconst buf2 = new Buffer(arr.buffer); // shares the memory with arr;\n\nconsole.log(buf1);\n  // Prints: <Buffer 88 a0>, copied buffer has only two elements\nconsole.log(buf2);\n  // Prints: <Buffer 88 13 a0 0f>\n\narr[1] = 6000;\nconsole.log(buf1);\n  // Prints: <Buffer 88 a0>\nconsole.log(buf2);\n  // Prints: <Buffer 88 13 70 17>
\n

Note that when creating a Buffer using the TypeArray's .buffer, it is not\ncurrently possible to use only a portion of the underlying ArrayBuffer. To\ncreate a Buffer that uses only a part of the ArrayBuffer, use the\n[buf.slice()][] function after the Buffer is created:\n\n

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

Buffers can be iterated over using the ECMAScript 2015 (ES6) for..of syntax:\n\n

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

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

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

\n", "classMethods": [ { "textRaw": "Class Method: Buffer.byteLength(string[, encoding])", "type": "classMethod", "name": "byteLength", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`string` {String} ", "name": "string", "type": "String" }, { "textRaw": "`encoding` {String} Default: `'utf8'` ", "name": "encoding", "type": "String", "desc": "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\n[String.prototype.length][] since that returns the number of characters in\na string.\n\n

\n

Example:\n\n

\n
const str = '\\u00bd + \\u00bc = \\u00be';\n\nconsole.log(`${str}: ${str.length} characters, ` +\n            `${Buffer.byteLength(str, 'utf8')} bytes`);\n\n// ½ + ¼ = ¾: 9 characters, 12 bytes
\n" }, { "textRaw": "Class Method: Buffer.compare(buf1, buf2)", "type": "classMethod", "name": "compare", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "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\nBuffers. This is equivalent is calling [buf1.compare(buf2)][].\n\n

\n
const arr = [Buffer('1234'), Buffer('0123')];\narr.sort(Buffer.compare);
\n" }, { "textRaw": "Class Method: Buffer.concat(list[, totalLength])", "type": "classMethod", "name": "concat", "signatures": [ { "return": { "textRaw": "Return: {Buffer} ", "name": "return", "type": "Buffer" }, "params": [ { "textRaw": "`list` {Array} List of Buffer objects to concat ", "name": "list", "type": "Array", "desc": "List of Buffer objects to concat" }, { "textRaw": "`totalLength` {Number} Total length of the Buffers in the list when concatenated ", "name": "totalLength", "type": "Number", "desc": "Total length of the Buffers in the 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 Buffers in\nthe list together.\n\n

\n

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

\n

If totalLength is not provided, it is calculated from the Buffers in the\nlist. This, however, adds an additional loop to the function, so it is faster\nto provide the length explicitly.\n\n

\n

Example: build a single Buffer from a list of three Buffers:\n\n

\n
const buf1 = new Buffer(10).fill(0);\nconst buf2 = new Buffer(14).fill(0);\nconst buf3 = new Buffer(18).fill(0);\nconst totalLength = buf1.length + buf2.length + buf3.length;\n\nconsole.log(totalLength);\nconst bufA = Buffer.concat([buf1, buf2, buf3], totalLength);\nconsole.log(bufA);\nconsole.log(bufA.length);\n\n// 42\n// <Buffer 00 00 00 00 ...>\n// 42
\n" }, { "textRaw": "Class Method: Buffer.isBuffer(obj)", "type": "classMethod", "name": "isBuffer", "signatures": [ { "return": { "textRaw": "Return: {Boolean} ", "name": "return", "type": "Boolean" }, "params": [ { "textRaw": "`obj` {Object} ", "name": "obj", "type": "Object" } ] }, { "params": [ { "name": "obj" } ] } ], "desc": "

Returns 'true' if obj is a Buffer.\n\n

\n" }, { "textRaw": "Class Method: Buffer.isEncoding(encoding)", "type": "classMethod", "name": "isEncoding", "signatures": [ { "return": { "textRaw": "Return: {Boolean} ", "name": "return", "type": "Boolean" }, "params": [ { "textRaw": "`encoding` {String} The encoding string to test ", "name": "encoding", "type": "String", "desc": "The encoding string to test" } ] }, { "params": [ { "name": "encoding" } ] } ], "desc": "

Returns true if the encoding is a valid encoding argument, or false\notherwise.\n\n

\n" } ], "properties": [ { "textRaw": "buf[index]", "name": "[index]", "desc": "

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

\n

Example: copy an ASCII string into a Buffer, one byte at a time:\n\n

\n
const str = "Node.js";\nconst buf = new Buffer(str.length);\n\nfor (var i = 0; i < str.length ; i++) {\n  buf[i] = str.charCodeAt(i);\n}\n\nconsole.log(buf.toString('ascii'));\n  // Prints: Node.js
\n" }, { "textRaw": "`length` {Number} ", "type": "Number", "name": "length", "desc": "

Returns the amount of memory allocated for the Buffer in number of bytes. Note\nthat this does not necessarily reflect the amount of usable data within the\nBuffer. For instance, in the example below, a Buffer with 1234 bytes is\nallocated, but only 11 ASCII bytes are written.\n\n

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

\n
var buf = new Buffer(10);\nbuf.write('abcdefghj', 0, 'ascii');\nconsole.log(buf.length);\n  // Prints: 10\nbuf = buf.slice(0,5);\nconsole.log(buf.length);\n  // Prints: 5
\n" } ], "methods": [ { "textRaw": "buf.compare(otherBuffer)", "type": "method", "name": "compare", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`otherBuffer` {Buffer} ", "name": "otherBuffer", "type": "Buffer" } ] }, { "params": [ { "name": "otherBuffer" } ] } ], "desc": "

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

\n\n
const buf1 = new Buffer('ABC');\nconst buf2 = new Buffer('BCD');\nconst buf3 = new Buffer('ABCD');\n\nconsole.log(buf1.compare(buf1));\n  // Prints: 0\nconsole.log(buf1.compare(buf2));\n  // Prints: -1\nconsole.log(buf1.compare(buf3));\n  // Prints: 1\nconsole.log(buf2.compare(buf1));\n  // Prints: 1\nconsole.log(buf2.compare(buf3));\n  // Prints: 1\n\n[buf1, buf2, buf3].sort(Buffer.compare);\n  // produces sort order [buf1, buf3, buf2]
\n" }, { "textRaw": "buf.copy(targetBuffer[, targetStart[, sourceStart[, sourceEnd]]])", "type": "method", "name": "copy", "signatures": [ { "return": { "textRaw": "Return: {Number} The number of bytes copied. ", "name": "return", "type": "Number", "desc": "The number of bytes copied." }, "params": [ { "textRaw": "`targetBuffer` {Buffer} Buffer to copy into ", "name": "targetBuffer", "type": "Buffer", "desc": "Buffer to copy into" }, { "textRaw": "`targetStart` {Number} Default: 0 ", "name": "targetStart", "type": "Number", "desc": "Default: 0" }, { "textRaw": "`sourceStart` {Number} Default: 0 ", "name": "sourceStart", "type": "Number", "desc": "Default: 0" }, { "textRaw": "`sourceEnd` {Number} Default: `buffer.length` ", "name": "sourceEnd", "type": "Number", "desc": "Default: `buffer.length`", "optional": true } ] }, { "params": [ { "name": "targetBuffer" }, { "name": "targetStart" }, { "name": "sourceStart" }, { "name": "sourceEnd", "optional": true } ] } ], "desc": "

Copies data from a region of this Buffer to a region in the target Buffer even\nif the target memory region overlaps with the source.\n\n

\n

Example: build two Buffers, then copy buf1 from byte 16 through byte 19\ninto buf2, starting at the 8th byte in buf2.\n\n

\n
const buf1 = new Buffer(26);\nconst buf2 = new Buffer(26).fill('!');\n\nfor (var i = 0 ; i < 26 ; i++) {\n  buf1[i] = i + 97; // 97 is ASCII a\n}\n\nbuf1.copy(buf2, 8, 16, 20);\nconsole.log(buf2.toString('ascii', 0, 25));\n  // Prints: !!!!!!!!qrst!!!!!!!!!!!!!
\n

Example: Build a single Buffer, then copy data from one region to an overlapping\nregion in the same Buffer\n\n

\n
const buf = new Buffer(26);\n\nfor (var i = 0 ; i < 26 ; i++) {\n  buf[i] = i + 97; // 97 is ASCII a\n}\n\nbuf.copy(buf, 0, 4, 10);\nconsole.log(buf.toString());\n\n// efghijghijklmnopqrstuvwxyz
\n" }, { "textRaw": "buf.entries()", "type": "method", "name": "entries", "signatures": [ { "return": { "textRaw": "Return: {Iterator} ", "name": "return", "type": "Iterator" }, "params": [] }, { "params": [] } ], "desc": "

Creates and returns an [iterator][] of [index, byte] pairs from the Buffer\ncontents.\n\n

\n
const buf = new Buffer('buffer');\nfor (var pair of buf.entries()) {\n  console.log(pair);\n}\n// prints:\n//   [0, 98]\n//   [1, 117]\n//   [2, 102]\n//   [3, 102]\n//   [4, 101]\n//   [5, 114]
\n" }, { "textRaw": "buf.equals(otherBuffer)", "type": "method", "name": "equals", "signatures": [ { "return": { "textRaw": "Return: {Boolean} ", "name": "return", "type": "Boolean" }, "params": [ { "textRaw": "`otherBuffer` {Buffer} ", "name": "otherBuffer", "type": "Buffer" } ] }, { "params": [ { "name": "otherBuffer" } ] } ], "desc": "

Returns a boolean indicating whether this and otherBuffer have exactly the\nsame bytes.\n\n

\n
const buf1 = new Buffer('ABC');\nconst buf2 = new Buffer('414243', 'hex');\nconst buf3 = new Buffer('ABCD');\n\nconsole.log(buf1.equals(buf2));\n  // Prints: true\nconsole.log(buf1.equals(buf3));\n  // Prints: false
\n" }, { "textRaw": "buf.fill(value[, offset[, end]][, encoding])", "type": "method", "name": "fill", "signatures": [ { "return": { "textRaw": "Return: {Buffer} ", "name": "return", "type": "Buffer" }, "params": [ { "textRaw": "`value` {String|Buffer|Number} ", "name": "value", "type": "String|Buffer|Number" }, { "textRaw": "`offset` {Number} Default: 0 ", "name": "offset", "type": "Number", "desc": "Default: 0" }, { "textRaw": "`end` {Number} Default: `buf.length` ", "name": "end", "type": "Number", "desc": "Default: `buf.length`", "optional": true }, { "textRaw": "`encoding` {String} Default: `'utf8'` ", "name": "encoding", "type": "String", "desc": "Default: `'utf8'`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "end", "optional": true }, { "name": "encoding", "optional": true } ] } ], "desc": "

Fills the Buffer with the specified value. If the offset (defaults to 0)\nand end (defaults to buf.length) are not given the entire buffer will be\nfilled. The method returns a reference to the Buffer, so calls can be chained.\nThis is meant as a small simplification to creating a Buffer. Allowing the\ncreation and fill of the Buffer to be done on a single line:\n\n

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

encoding is only relevant if value is a string. Otherwise it is ignored.\nvalue is coerced to a uint32 value if it is not a String or Number.\n\n

\n

The fill() operation writes bytes into the Buffer dumbly. If the final write\nfalls in between a multi-byte character then whatever bytes fit into the buffer\nare written.\n\n

\n
Buffer(3).fill('\\u0222');\n  // Prints: <Buffer c8 a2 c8>
\n" }, { "textRaw": "buf.indexOf(value[, byteOffset][, encoding])", "type": "method", "name": "indexOf", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`value` {String|Buffer|Number} ", "name": "value", "type": "String|Buffer|Number" }, { "textRaw": "`byteOffset` {Number} Default: 0 ", "name": "byteOffset", "type": "Number", "desc": "Default: 0", "optional": true }, { "textRaw": "`encoding` {String} Default: `'utf8'` ", "name": "encoding", "type": "String", "desc": "Default: `'utf8'`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "byteOffset", "optional": true }, { "name": "encoding", "optional": true } ] } ], "desc": "

Operates similar to [Array#indexOf()][] in that it returns either the\nstarting index position of value in Buffer or -1 if the Buffer does not\ncontain value. The value can be a String, Buffer or Number. Strings are by\ndefault interpreted as UTF8. Buffers will use the entire Buffer (to compare a\npartial Buffer use [buf.slice()][]). Numbers can range from 0 to 255.\n\n

\n
const buf = new Buffer('this is a buffer');\n\nbuf.indexOf('this');\n  // returns 0\nbuf.indexOf('is');\n  // returns 2\nbuf.indexOf(new Buffer('a buffer'));\n  // returns 8\nbuf.indexOf(97); // ascii for 'a'\n  // returns 8\nbuf.indexOf(new Buffer('a buffer example'));\n  // returns -1\nbuf.indexOf(new Buffer('a buffer example').slice(0,8));\n  // returns 8\n\nconst utf16Buffer = new Buffer('\\u039a\\u0391\\u03a3\\u03a3\\u0395', 'ucs2');\n\nutf16Buffer.indexOf('\\u03a3',  0, 'ucs2');\n  // returns 4\nutf16Buffer.indexOf('\\u03a3', -4, 'ucs2');\n  // returns 6
\n" }, { "textRaw": "buf.includes(value[, byteOffset][, encoding])", "type": "method", "name": "includes", "signatures": [ { "return": { "textRaw": "Return: {Boolean} ", "name": "return", "type": "Boolean" }, "params": [ { "textRaw": "`value` {String|Buffer|Number} ", "name": "value", "type": "String|Buffer|Number" }, { "textRaw": "`byteOffset` {Number} Default: 0 ", "name": "byteOffset", "type": "Number", "desc": "Default: 0", "optional": true }, { "textRaw": "`encoding` {String} Default: `'utf8'` ", "name": "encoding", "type": "String", "desc": "Default: `'utf8'`", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "byteOffset", "optional": true }, { "name": "encoding", "optional": true } ] } ], "desc": "

Operates similar to [Array#includes()][]. The value can be a String, Buffer\nor Number. Strings are interpreted as UTF8 unless overridden with the\nencoding argument. Buffers will use the entire Buffer (to compare a partial\nBuffer use [buf.slice()][]). Numbers can range from 0 to 255.\n\n

\n

The byteOffset indicates the index in buf where searching begins.\n\n

\n
const buf = new Buffer('this is a buffer');\n\nbuf.includes('this');\n  // returns true\nbuf.includes('is');\n  // returns true\nbuf.includes(new Buffer('a buffer'));\n  // returns true\nbuf.includes(97); // ascii for 'a'\n  // returns true\nbuf.includes(new Buffer('a buffer example'));\n  // returns false\nbuf.includes(new Buffer('a buffer example').slice(0,8));\n  // returns true\nbuf.includes('this', 4);\n  // returns false
\n" }, { "textRaw": "buf.keys()", "type": "method", "name": "keys", "signatures": [ { "return": { "textRaw": "Return: {Iterator} ", "name": "return", "type": "Iterator" }, "params": [] }, { "params": [] } ], "desc": "

Creates and returns an [iterator][] of Buffer keys (indices).\n\n

\n
const buf = new Buffer('buffer');\nfor (var key of buf.keys()) {\n  console.log(key);\n}\n// prints:\n//   0\n//   1\n//   2\n//   3\n//   4\n//   5
\n" }, { "textRaw": "buf.readDoubleBE(offset[, noAssert])", "type": "method", "name": "readDoubleBE", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 8` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 8`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "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 the Buffer at the specified offset with specified\nendian format (readDoubleBE() returns big endian, readDoubleLE() returns\nlittle endian).\n\n

\n

Setting noAssert to true skips validation of the offset. This allows the\noffset to be beyond the end of the Buffer.\n\n

\n
const buf = new Buffer([1,2,3,4,5,6,7,8]);\n\nbuf.readDoubleBE();\n  // Returns: 8.20788039913184e-304\nbuf.readDoubleLE();\n  // Returns: 5.447603722011605e-270\nbuf.readDoubleLE(1);\n  // throws RangeError: Index out of range\n\nbuf.readDoubleLE(1, true); // Warning: reads passed end of buffer!\n  // Segmentation fault! don't do this!
\n" }, { "textRaw": "buf.readDoubleLE(offset[, noAssert])", "type": "method", "name": "readDoubleLE", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 8` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 8`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

\n

Setting noAssert to true skips validation of the offset. This allows the\noffset to be beyond the end of the Buffer.\n\n

\n
const buf = new Buffer([1,2,3,4,5,6,7,8]);\n\nbuf.readDoubleBE();\n  // Returns: 8.20788039913184e-304\nbuf.readDoubleLE();\n  // Returns: 5.447603722011605e-270\nbuf.readDoubleLE(1);\n  // throws RangeError: Index out of range\n\nbuf.readDoubleLE(1, true); // Warning: reads passed end of buffer!\n  // Segmentation fault! don't do this!
\n" }, { "textRaw": "buf.readFloatBE(offset[, noAssert])", "type": "method", "name": "readFloatBE", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 4` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 4`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "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 the Buffer at the specified offset with specified\nendian format (readFloatBE() returns big endian, readFloatLE() returns\nlittle endian).\n\n

\n

Setting noAssert to true skips validation of the offset. This allows the\noffset to be beyond the end of the Buffer.\n\n

\n
const buf = new Buffer([1,2,3,4]);\n\nbuf.readFloatBE();\n  // Returns: 2.387939260590663e-38\nbuf.readFloatLE();\n  // Returns: 1.539989614439558e-36\nbuf.readFloatLE(1);\n  // throws RangeError: Index out of range\n\nbuf.readFloatLE(1, true); // Warning: reads passed end of buffer!\n  // Segmentation fault! don't do this!
\n" }, { "textRaw": "buf.readFloatLE(offset[, noAssert])", "type": "method", "name": "readFloatLE", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 4` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 4`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

\n

Setting noAssert to true skips validation of the offset. This allows the\noffset to be beyond the end of the Buffer.\n\n

\n
const buf = new Buffer([1,2,3,4]);\n\nbuf.readFloatBE();\n  // Returns: 2.387939260590663e-38\nbuf.readFloatLE();\n  // Returns: 1.539989614439558e-36\nbuf.readFloatLE(1);\n  // throws RangeError: Index out of range\n\nbuf.readFloatLE(1, true); // Warning: reads passed end of buffer!\n  // Segmentation fault! don't do this!
\n" }, { "textRaw": "buf.readInt8(offset[, noAssert])", "type": "method", "name": "readInt8", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 1` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 1`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

Reads a signed 8-bit integer from the Buffer at the specified offset.\n\n

\n

Setting noAssert to true skips validation of the offset. This allows the\noffset to be beyond the end of the Buffer.\n\n

\n

Integers read from the Buffer are interpreted as two's complement signed values.\n\n

\n
const buf = new Buffer([1,-2,3,4]);\n\nbuf.readInt8(0);\n  // returns 1\nbuf.readInt8(1);\n  // returns -2
\n" }, { "textRaw": "buf.readInt16BE(offset[, noAssert])", "type": "method", "name": "readInt16BE", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 2` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 2`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "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 the Buffer at the specified offset with\nthe specified endian format (readInt16BE() returns big endian,\nreadInt16LE() returns little endian).\n\n

\n

Setting noAssert to true skips validation of the offset. This allows the\noffset to be beyond the end of the Buffer.\n\n

\n

Integers read from the Buffer are interpreted as two's complement signed values.\n\n

\n
const buf = new Buffer([1,-2,3,4]);\n\nbuf.readInt16BE();\n  // returns 510\nbuf.readInt16LE(1);\n  // returns 1022
\n" }, { "textRaw": "buf.readInt16LE(offset[, noAssert])", "type": "method", "name": "readInt16LE", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 2` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 2`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

\n

Setting noAssert to true skips validation of the offset. This allows the\noffset to be beyond the end of the Buffer.\n\n

\n

Integers read from the Buffer are interpreted as two's complement signed values.\n\n

\n
const buf = new Buffer([1,-2,3,4]);\n\nbuf.readInt16BE();\n  // returns 510\nbuf.readInt16LE(1);\n  // returns 1022
\n" }, { "textRaw": "buf.readInt32BE(offset[, noAssert])", "type": "method", "name": "readInt32BE", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 4` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 4`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "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 the Buffer at the specified offset with\nthe specified endian format (readInt32BE() returns big endian,\nreadInt32LE() returns little endian).\n\n

\n

Setting noAssert to true skips validation of the offset. This allows the\noffset to be beyond the end of the Buffer.\n\n

\n

Integers read from the Buffer are interpreted as two's complement signed values.\n\n

\n
const buf = new Buffer([1,-2,3,4]);\n\nbuf.readInt32BE();\n  // returns 33424132\nbuf.readInt32LE(1);\n  // returns 67370497
\n" }, { "textRaw": "buf.readInt32LE(offset[, noAssert])", "type": "method", "name": "readInt32LE", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 4` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 4`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

\n

Setting noAssert to true skips validation of the offset. This allows the\noffset to be beyond the end of the Buffer.\n\n

\n

Integers read from the Buffer are interpreted as two's complement signed values.\n\n

\n
const buf = new Buffer([1,-2,3,4]);\n\nbuf.readInt32BE();\n  // returns 33424132\nbuf.readInt32LE(1);\n  // returns 67370497
\n" }, { "textRaw": "buf.readIntBE(offset, byteLength[, noAssert])", "type": "method", "name": "readIntBE", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - byteLength` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - byteLength`" }, { "textRaw": "`byteLength` {Number} `0 < byteLength <= 6` ", "name": "byteLength", "type": "Number", "desc": "`0 < byteLength <= 6`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "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 the Buffer at the specified offset\nand interprets the result as a two's complement signed value. Supports up to 48\nbits of accuracy. For example:\n\n

\n
const buf = new Buffer(6);\nbuf.writeUInt16LE(0x90ab, 0);\nbuf.writeUInt32LE(0x12345678, 2);\nbuf.readIntLE(0, 6).toString(16);  // Specify 6 bytes (48 bits)\n// Returns: '1234567890ab'\n\nbuf.readIntBE(0, 6).toString(16);\n// Returns: -546f87a9cbee
\n

Setting noAssert to true skips validation of the offset. This allows the\noffset to be beyond the end of the Buffer.\n\n

\n" }, { "textRaw": "buf.readIntLE(offset, byteLength[, noAssert])", "type": "method", "name": "readIntLE", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - byteLength` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - byteLength`" }, { "textRaw": "`byteLength` {Number} `0 < byteLength <= 6` ", "name": "byteLength", "type": "Number", "desc": "`0 < byteLength <= 6`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "byteLength" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

\n
const buf = new Buffer(6);\nbuf.writeUInt16LE(0x90ab, 0);\nbuf.writeUInt32LE(0x12345678, 2);\nbuf.readIntLE(0, 6).toString(16);  // Specify 6 bytes (48 bits)\n// Returns: '1234567890ab'\n\nbuf.readIntBE(0, 6).toString(16);\n// Returns: -546f87a9cbee
\n

Setting noAssert to true skips validation of the offset. This allows the\noffset to be beyond the end of the Buffer.\n\n

\n" }, { "textRaw": "buf.readUInt8(offset[, noAssert])", "type": "method", "name": "readUInt8", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 1` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 1`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

Reads an unsigned 8-bit integer from the Buffer at the specified offset.\n\n

\n

Setting noAssert to true skips validation of the offset. This allows the\noffset to be beyond the end of the Buffer.\n\n

\n
const buf = new Buffer([1,-2,3,4]);\n\nbuf.readUInt8(0);\n  // returns 1\nbuf.readUInt8(1);\n  // returns 254
\n" }, { "textRaw": "buf.readUInt16BE(offset[, noAssert])", "type": "method", "name": "readUInt16BE", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 2` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 2`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "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 the Buffer at the specified offset with\nspecified endian format (readInt32BE() returns big endian,\nreadInt32LE() returns little endian).\n\n

\n

Setting noAssert to true skips validation of the offset. This allows the\noffset to be beyond the end of the Buffer.\n\n

\n

Example:\n\n

\n
const buf = new Buffer([0x3, 0x4, 0x23, 0x42]);\n\nbuf.readUInt16BE(0);\n  // Returns: 0x0304\nbuf.readUInt16LE(0);\n  // Returns: 0x0403\nbuf.readUInt16BE(1);\n  // Returns: 0x0423\nbuf.readUInt16LE(1);\n  // Returns: 0x2304\nbuf.readUInt16BE(2);\n  // Returns: 0x2342\nbuf.readUInt16LE(2);\n  // Returns: 0x4223
\n" }, { "textRaw": "buf.readUInt16LE(offset[, noAssert])", "type": "method", "name": "readUInt16LE", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 2` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 2`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

Reads an unsigned 16-bit integer from the Buffer at the specified offset with\nspecified endian format (readInt32BE() returns big endian,\nreadInt32LE() returns little endian).\n\n

\n

Setting noAssert to true skips validation of the offset. This allows the\noffset to be beyond the end of the Buffer.\n\n

\n

Example:\n\n

\n
const buf = new Buffer([0x3, 0x4, 0x23, 0x42]);\n\nbuf.readUInt16BE(0);\n  // Returns: 0x0304\nbuf.readUInt16LE(0);\n  // Returns: 0x0403\nbuf.readUInt16BE(1);\n  // Returns: 0x0423\nbuf.readUInt16LE(1);\n  // Returns: 0x2304\nbuf.readUInt16BE(2);\n  // Returns: 0x2342\nbuf.readUInt16LE(2);\n  // Returns: 0x4223
\n" }, { "textRaw": "buf.readUInt32BE(offset[, noAssert])", "type": "method", "name": "readUInt32BE", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 4` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 4`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "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 the Buffer at the specified offset with\nspecified endian format (readInt32BE() returns big endian,\nreadInt32LE() returns little endian).\n\n

\n

Setting noAssert to true skips validation of the offset. This allows the\noffset to be beyond the end of the Buffer.\n\n

\n

Example:\n\n

\n
const buf = new Buffer([0x3, 0x4, 0x23, 0x42]);\n\nbuf.readUInt32BE(0);\n  // Returns: 0x03042342\nconsole.log(buf.readUInt32LE(0));\n  // Returns: 0x42230403
\n" }, { "textRaw": "buf.readUInt32LE(offset[, noAssert])", "type": "method", "name": "readUInt32LE", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 4` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 4`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

Reads an unsigned 32-bit integer from the Buffer at the specified offset with\nspecified endian format (readInt32BE() returns big endian,\nreadInt32LE() returns little endian).\n\n

\n

Setting noAssert to true skips validation of the offset. This allows the\noffset to be beyond the end of the Buffer.\n\n

\n

Example:\n\n

\n
const buf = new Buffer([0x3, 0x4, 0x23, 0x42]);\n\nbuf.readUInt32BE(0);\n  // Returns: 0x03042342\nconsole.log(buf.readUInt32LE(0));\n  // Returns: 0x42230403
\n" }, { "textRaw": "buf.readUIntBE(offset, byteLength[, noAssert])", "type": "method", "name": "readUIntBE", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - byteLength` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - byteLength`" }, { "textRaw": "`byteLength` {Number} `0 < byteLength <= 6` ", "name": "byteLength", "type": "Number", "desc": "`0 < byteLength <= 6`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "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 the Buffer at the specified offset\nand interprets the result as an unsigned integer. Supports up to 48\nbits of accuracy. For example:\n\n

\n
const buf = new Buffer(6);\nbuf.writeUInt16LE(0x90ab, 0);\nbuf.writeUInt32LE(0x12345678, 2);\nbuf.readUIntLE(0, 6).toString(16);  // Specify 6 bytes (48 bits)\n// Returns: '1234567890ab'\n\nbuf.readUIntBE(0, 6).toString(16);\n// Returns: ab9078563412
\n

Setting noAssert to true skips validation of the offset. This allows the\noffset to be beyond the end of the Buffer.\n\n

\n" }, { "textRaw": "buf.readUIntLE(offset, byteLength[, noAssert])", "type": "method", "name": "readUIntLE", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "params": [ { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - byteLength` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - byteLength`" }, { "textRaw": "`byteLength` {Number} `0 < byteLength <= 6` ", "name": "byteLength", "type": "Number", "desc": "`0 < byteLength <= 6`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "offset" }, { "name": "byteLength" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

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

\n
const buf = new Buffer(6);\nbuf.writeUInt16LE(0x90ab, 0);\nbuf.writeUInt32LE(0x12345678, 2);\nbuf.readUIntLE(0, 6).toString(16);  // Specify 6 bytes (48 bits)\n// Returns: '1234567890ab'\n\nbuf.readUIntBE(0, 6).toString(16);\n// Returns: ab9078563412
\n

Setting noAssert to true skips validation of the offset. This allows the\noffset to be beyond the end of the Buffer.\n\n

\n" }, { "textRaw": "buf.slice([start[, end]])", "type": "method", "name": "slice", "signatures": [ { "return": { "textRaw": "Return: {Buffer} ", "name": "return", "type": "Buffer" }, "params": [ { "textRaw": "`start` {Number} Default: 0 ", "name": "start", "type": "Number", "desc": "Default: 0" }, { "textRaw": "`end` {Number} Default: `buffer.length` ", "name": "end", "type": "Number", "desc": "Default: `buffer.length`", "optional": true } ] }, { "params": [ { "name": "start" }, { "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\n

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

\n

Example: build a Buffer with the ASCII alphabet, take a slice, then modify one\nbyte from the original Buffer.\n\n

\n
const buf1 = new Buffer(26);\n\nfor (var i = 0 ; i < 26 ; i++) {\n  buf1[i] = i + 97; // 97 is ASCII a\n}\n\nconst buf2 = buf1.slice(0, 3);\nbuf2.toString('ascii', 0, buf2.length);\n  // Returns: 'abc'\nbuf1[0] = 33;\nbuf2.toString('ascii', 0, buf2.length);\n  // Returns : '!bc'
\n

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

\n
const buf = new Buffer('buffer');\n\nbuf.slice(-6, -1).toString();\n  // Returns 'buffe', equivalent to buf.slice(0, 5)\nbuf.slice(-6, -2).toString();\n  // Returns 'buff', equivalent to buf.slice(0, 4)\nbuf.slice(-5, -2).toString();\n  // Returns 'uff', equivalent to buf.slice(1, 4)
\n" }, { "textRaw": "buf.toString([encoding[, start[, end]]])", "type": "method", "name": "toString", "signatures": [ { "return": { "textRaw": "Return: {String} ", "name": "return", "type": "String" }, "params": [ { "textRaw": "`encoding` {String} Default: `'utf8'` ", "name": "encoding", "type": "String", "desc": "Default: `'utf8'`" }, { "textRaw": "`start` {Number} Default: 0 ", "name": "start", "type": "Number", "desc": "Default: 0" }, { "textRaw": "`end` {Number} Default: `buffer.length` ", "name": "end", "type": "Number", "desc": "Default: `buffer.length`", "optional": true } ] }, { "params": [ { "name": "encoding" }, { "name": "start" }, { "name": "end", "optional": true } ] } ], "desc": "

Decodes and returns a string from the Buffer data using the specified\ncharacter set encoding.\n\n

\n
const buf = new Buffer(26);\nfor (var i = 0 ; i < 26 ; i++) {\n  buf[i] = i + 97; // 97 is ASCII a\n}\nbuf.toString('ascii');\n  // Returns: 'abcdefghijklmnopqrstuvwxyz'\nbuf.toString('ascii',0,5);\n  // Returns: 'abcde'\nbuf.toString('utf8',0,5);\n  // Returns: 'abcde'\nbuf.toString(undefined,0,5);\n  // Returns: 'abcde', encoding defaults to 'utf8'
\n" }, { "textRaw": "buf.toJSON()", "type": "method", "name": "toJSON", "signatures": [ { "return": { "textRaw": "Return: {Object} ", "name": "return", "type": "Object" }, "params": [] }, { "params": [] } ], "desc": "

Returns a JSON representation of the Buffer instance. [JSON.stringify()][]\nimplicitly calls this function when stringifying a Buffer instance.\n\n

\n

Example:\n\n

\n
const buf = new Buffer('test');\nconst json = JSON.stringify(buf);\n\nconsole.log(json);\n// Prints: '{"type":"Buffer","data":[116,101,115,116]}'\n\nconst copy = JSON.parse(json, (key, value) => {\n    return value && value.type === 'Buffer'\n      ? new Buffer(value.data)\n      : value;\n  });\n\nconsole.log(copy.toString());\n// Prints: 'test'
\n" }, { "textRaw": "buf.values()", "type": "method", "name": "values", "signatures": [ { "return": { "textRaw": "Return: {Iterator} ", "name": "return", "type": "Iterator" }, "params": [] }, { "params": [] } ], "desc": "

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

\n
const buf = new Buffer('buffer');\nfor (var value of buf.values()) {\n  console.log(value);\n}\n// prints:\n//   98\n//   117\n//   102\n//   102\n//   101\n//   114\n\nfor (var value of buf) {\n  console.log(value);\n}\n// prints:\n//   98\n//   117\n//   102\n//   102\n//   101\n//   114
\n" }, { "textRaw": "buf.write(string[, offset[, length]][, encoding])", "type": "method", "name": "write", "signatures": [ { "return": { "textRaw": "Return: {Number} Numbers of bytes written ", "name": "return", "type": "Number", "desc": "Numbers of bytes written" }, "params": [ { "textRaw": "`string` {String} Bytes to be written to buffer ", "name": "string", "type": "String", "desc": "Bytes to be written to buffer" }, { "textRaw": "`offset` {Number} Default: 0 ", "name": "offset", "type": "Number", "desc": "Default: 0" }, { "textRaw": "`length` {Number} Default: `buffer.length - offset` ", "name": "length", "type": "Number", "desc": "Default: `buffer.length - offset`", "optional": true }, { "textRaw": "`encoding` {String} Default: `'utf8'` ", "name": "encoding", "type": "String", "desc": "Default: `'utf8'`", "optional": true } ] }, { "params": [ { "name": "string" }, { "name": "offset" }, { "name": "length", "optional": true }, { "name": "encoding", "optional": true } ] } ], "desc": "

Writes string to the Buffer at offset using the given encoding.\nThe length parameter is the number of bytes to write. If the Buffer did not\ncontain enough space to fit the entire string, only a partial amount of the\nstring will be written however, it will not write only partially encoded\ncharacters.\n\n

\n
const buf = new Buffer(256);\nconst len = buf.write('\\u00bd + \\u00bc = \\u00be', 0);\nconsole.log(`${len} bytes: ${buf.toString('utf8', 0, len)}`);\n  // Prints: 12 bytes: ½ + ¼ = ¾
\n" }, { "textRaw": "buf.writeDoubleBE(value, offset[, noAssert])", "type": "method", "name": "writeDoubleBE", "signatures": [ { "return": { "textRaw": "Return: {Number} Numbers of bytes written ", "name": "return", "type": "Number", "desc": "Numbers of bytes written" }, "params": [ { "textRaw": "`value` {Number} Bytes to be written to Buffer ", "name": "value", "type": "Number", "desc": "Bytes to be written to Buffer" }, { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 8` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 8`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "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 the Buffer at the specified offset with specified endian\nformat (writeDoubleBE() writes big endian, writeDoubleLE() writes little\nendian). The value argument must be a valid 64-bit double.\n\n

\n

Set noAssert to true to skip validation of value and offset. This means\nthat value may be too large for the specific function and offset may be\nbeyond the end of the Buffer leading to the values being silently dropped. This\nshould not be used unless you are certain of correctness.\n\n

\n

Example:\n\n

\n
const buf = new Buffer(8);\nbuf.writeDoubleBE(0xdeadbeefcafebabe, 0);\n\nconsole.log(buf);\n  // Prints: <Buffer 43 eb d5 b7 dd f9 5f d7>\n\nbuf.writeDoubleLE(0xdeadbeefcafebabe, 0);\n\nconsole.log(buf);\n  // Prints: <Buffer d7 5f f9 dd b7 d5 eb 43>
\n" }, { "textRaw": "buf.writeDoubleLE(value, offset[, noAssert])", "type": "method", "name": "writeDoubleLE", "signatures": [ { "return": { "textRaw": "Return: {Number} Numbers of bytes written ", "name": "return", "type": "Number", "desc": "Numbers of bytes written" }, "params": [ { "textRaw": "`value` {Number} Bytes to be written to Buffer ", "name": "value", "type": "Number", "desc": "Bytes to be written to Buffer" }, { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 8` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 8`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

Writes value to the Buffer at the specified offset with specified endian\nformat (writeDoubleBE() writes big endian, writeDoubleLE() writes little\nendian). The value argument must be a valid 64-bit double.\n\n

\n

Set noAssert to true to skip validation of value and offset. This means\nthat value may be too large for the specific function and offset may be\nbeyond the end of the Buffer leading to the values being silently dropped. This\nshould not be used unless you are certain of correctness.\n\n

\n

Example:\n\n

\n
const buf = new Buffer(8);\nbuf.writeDoubleBE(0xdeadbeefcafebabe, 0);\n\nconsole.log(buf);\n  // Prints: <Buffer 43 eb d5 b7 dd f9 5f d7>\n\nbuf.writeDoubleLE(0xdeadbeefcafebabe, 0);\n\nconsole.log(buf);\n  // Prints: <Buffer d7 5f f9 dd b7 d5 eb 43>
\n" }, { "textRaw": "buf.writeFloatBE(value, offset[, noAssert])", "type": "method", "name": "writeFloatBE", "signatures": [ { "return": { "textRaw": "Return: {Number} Numbers of bytes written ", "name": "return", "type": "Number", "desc": "Numbers of bytes written" }, "params": [ { "textRaw": "`value` {Number} Bytes to be written to Buffer ", "name": "value", "type": "Number", "desc": "Bytes to be written to Buffer" }, { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 4` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 4`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "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 the Buffer at the specified offset with specified endian\nformat (writeFloatBE() writes big endian, writeFloatLE() writes little\nendian). Behavior is unspecified if value is anything other than a 32-bit\nfloat.\n\n

\n

Set noAssert to true to skip validation of value and offset. This means\nthat value may be too large for the specific function and offset may be\nbeyond the end of the Buffer leading to the values being silently dropped. This\nshould not be used unless you are certain of correctness.\n\n

\n

Example:\n\n

\n
const buf = new Buffer(4);\nbuf.writeFloatBE(0xcafebabe, 0);\n\nconsole.log(buf);\n  // Prints: <Buffer 4f 4a fe bb>\n\nbuf.writeFloatLE(0xcafebabe, 0);\n\nconsole.log(buf);\n  // Prints: <Buffer bb fe 4a 4f>
\n" }, { "textRaw": "buf.writeFloatLE(value, offset[, noAssert])", "type": "method", "name": "writeFloatLE", "signatures": [ { "return": { "textRaw": "Return: {Number} Numbers of bytes written ", "name": "return", "type": "Number", "desc": "Numbers of bytes written" }, "params": [ { "textRaw": "`value` {Number} Bytes to be written to Buffer ", "name": "value", "type": "Number", "desc": "Bytes to be written to Buffer" }, { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 4` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 4`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

Writes value to the Buffer at the specified offset with specified endian\nformat (writeFloatBE() writes big endian, writeFloatLE() writes little\nendian). Behavior is unspecified if value is anything other than a 32-bit\nfloat.\n\n

\n

Set noAssert to true to skip validation of value and offset. This means\nthat value may be too large for the specific function and offset may be\nbeyond the end of the Buffer leading to the values being silently dropped. This\nshould not be used unless you are certain of correctness.\n\n

\n

Example:\n\n

\n
const buf = new Buffer(4);\nbuf.writeFloatBE(0xcafebabe, 0);\n\nconsole.log(buf);\n  // Prints: <Buffer 4f 4a fe bb>\n\nbuf.writeFloatLE(0xcafebabe, 0);\n\nconsole.log(buf);\n  // Prints: <Buffer bb fe 4a 4f>
\n" }, { "textRaw": "buf.writeInt8(value, offset[, noAssert])", "type": "method", "name": "writeInt8", "signatures": [ { "return": { "textRaw": "Return: {Number} Numbers of bytes written ", "name": "return", "type": "Number", "desc": "Numbers of bytes written" }, "params": [ { "textRaw": "`value` {Number} Bytes to be written to Buffer ", "name": "value", "type": "Number", "desc": "Bytes to be written to Buffer" }, { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 1` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 1`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

Writes value to the Buffer at the specified offset. The value must be a\nvalid signed 8-bit integer.\n\n

\n

Set noAssert to true to skip validation of value and offset. This means\nthat value may be too large for the specific function and offset may be\nbeyond the end of the Buffer leading to the values being silently dropped. This\nshould not be used unless you are certain of correctness.\n\n

\n

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

\n
const buf = new Buffer(2);\nbuf.writeInt8(2, 0);\nbuf.writeInt8(-2, 1);\nconsole.log(buf);\n  // Prints: <Buffer 02 fe>
\n" }, { "textRaw": "buf.writeInt16BE(value, offset[, noAssert])", "type": "method", "name": "writeInt16BE", "signatures": [ { "return": { "textRaw": "Return: {Number} Numbers of bytes written ", "name": "return", "type": "Number", "desc": "Numbers of bytes written" }, "params": [ { "textRaw": "`value` {Number} Bytes to be written to Buffer ", "name": "value", "type": "Number", "desc": "Bytes to be written to Buffer" }, { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 2` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 2`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "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 the Buffer at the specified offset with specified endian\nformat (writeInt16BE() writes big endian, writeInt16LE() writes little\nendian). The value must be a valid signed 16-bit integer.\n\n

\n

Set noAssert to true to skip validation of value and offset. This means\nthat value may be too large for the specific function and offset may be\nbeyond the end of the Buffer leading to the values being silently dropped. This\nshould not be used unless you are certain of correctness.\n\n

\n

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

\n
const buf = new Buffer(4);\nbuf.writeInt16BE(0x0102,0);\nbuf.writeInt16LE(0x0304,2);\nconsole.log(buf);\n  // Prints: <Buffer 01 02 04 03>
\n" }, { "textRaw": "buf.writeInt16LE(value, offset[, noAssert])", "type": "method", "name": "writeInt16LE", "signatures": [ { "return": { "textRaw": "Return: {Number} Numbers of bytes written ", "name": "return", "type": "Number", "desc": "Numbers of bytes written" }, "params": [ { "textRaw": "`value` {Number} Bytes to be written to Buffer ", "name": "value", "type": "Number", "desc": "Bytes to be written to Buffer" }, { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 2` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 2`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

Writes value to the Buffer at the specified offset with specified endian\nformat (writeInt16BE() writes big endian, writeInt16LE() writes little\nendian). The value must be a valid signed 16-bit integer.\n\n

\n

Set noAssert to true to skip validation of value and offset. This means\nthat value may be too large for the specific function and offset may be\nbeyond the end of the Buffer leading to the values being silently dropped. This\nshould not be used unless you are certain of correctness.\n\n

\n

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

\n
const buf = new Buffer(4);\nbuf.writeInt16BE(0x0102,0);\nbuf.writeInt16LE(0x0304,2);\nconsole.log(buf);\n  // Prints: <Buffer 01 02 04 03>
\n" }, { "textRaw": "buf.writeInt32BE(value, offset[, noAssert])", "type": "method", "name": "writeInt32BE", "signatures": [ { "return": { "textRaw": "Return: {Number} Numbers of bytes written ", "name": "return", "type": "Number", "desc": "Numbers of bytes written" }, "params": [ { "textRaw": "`value` {Number} Bytes to be written to Buffer ", "name": "value", "type": "Number", "desc": "Bytes to be written to Buffer" }, { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 4` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 4`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "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 the Buffer at the specified offset with specified endian\nformat (writeInt32BE() writes big endian, writeInt32LE() writes little\nendian). The value must be a valid signed 32-bit integer.\n\n

\n

Set noAssert to true to skip validation of value and offset. This means\nthat value may be too large for the specific function and offset may be\nbeyond the end of the Buffer leading to the values being silently dropped. This\nshould not be used unless you are certain of correctness.\n\n

\n

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

\n
const buf = new Buffer(8);\nbuf.writeInt32BE(0x01020304,0);\nbuf.writeInt32LE(0x05060708,4);\nconsole.log(buf);\n  // Prints: <Buffer 01 02 03 04 08 07 06 05>
\n" }, { "textRaw": "buf.writeInt32LE(value, offset[, noAssert])", "type": "method", "name": "writeInt32LE", "signatures": [ { "return": { "textRaw": "Return: {Number} Numbers of bytes written ", "name": "return", "type": "Number", "desc": "Numbers of bytes written" }, "params": [ { "textRaw": "`value` {Number} Bytes to be written to Buffer ", "name": "value", "type": "Number", "desc": "Bytes to be written to Buffer" }, { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 4` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 4`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

Writes value to the Buffer at the specified offset with specified endian\nformat (writeInt32BE() writes big endian, writeInt32LE() writes little\nendian). The value must be a valid signed 32-bit integer.\n\n

\n

Set noAssert to true to skip validation of value and offset. This means\nthat value may be too large for the specific function and offset may be\nbeyond the end of the Buffer leading to the values being silently dropped. This\nshould not be used unless you are certain of correctness.\n\n

\n

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

\n
const buf = new Buffer(8);\nbuf.writeInt32BE(0x01020304,0);\nbuf.writeInt32LE(0x05060708,4);\nconsole.log(buf);\n  // Prints: <Buffer 01 02 03 04 08 07 06 05>
\n" }, { "textRaw": "buf.writeIntBE(value, offset, byteLength[, noAssert])", "type": "method", "name": "writeIntBE", "signatures": [ { "return": { "textRaw": "Return: {Number} Numbers of bytes written ", "name": "return", "type": "Number", "desc": "Numbers of bytes written" }, "params": [ { "textRaw": "`value` {Number} Bytes to be written to Buffer ", "name": "value", "type": "Number", "desc": "Bytes to be written to Buffer" }, { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - byteLength` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - byteLength`" }, { "textRaw": "`byteLength` {Number} `0 < byteLength <= 6` ", "name": "byteLength", "type": "Number", "desc": "`0 < byteLength <= 6`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "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 value to the Buffer at the specified offset and byteLength.\nSupports up to 48 bits of accuracy. For example:\n\n

\n
const buf1 = new Buffer(6);\nbuf1.writeUIntBE(0x1234567890ab, 0, 6);\nconsole.log(buf1);\n  // Prints: <Buffer 12 34 56 78 90 ab>\n\nconst buf2 = new Buffer(6);\nbuf2.writeUIntLE(0x1234567890ab, 0, 6);\nconsole.log(buf2);\n  // Prints: <Buffer ab 90 78 56 34 12>
\n

Set noAssert to true to skip validation of value and offset. This means\nthat value may be too large for the specific function and offset may be\nbeyond the end of the Buffer leading to the values being silently dropped. This\nshould not be used unless you are certain of correctness.\n\n

\n" }, { "textRaw": "buf.writeIntLE(value, offset, byteLength[, noAssert])", "type": "method", "name": "writeIntLE", "signatures": [ { "return": { "textRaw": "Return: {Number} Numbers of bytes written ", "name": "return", "type": "Number", "desc": "Numbers of bytes written" }, "params": [ { "textRaw": "`value` {Number} Bytes to be written to Buffer ", "name": "value", "type": "Number", "desc": "Bytes to be written to Buffer" }, { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - byteLength` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - byteLength`" }, { "textRaw": "`byteLength` {Number} `0 < byteLength <= 6` ", "name": "byteLength", "type": "Number", "desc": "`0 < byteLength <= 6`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "byteLength" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

Writes value to the Buffer at the specified offset and byteLength.\nSupports up to 48 bits of accuracy. For example:\n\n

\n
const buf1 = new Buffer(6);\nbuf1.writeUIntBE(0x1234567890ab, 0, 6);\nconsole.log(buf1);\n  // Prints: <Buffer 12 34 56 78 90 ab>\n\nconst buf2 = new Buffer(6);\nbuf2.writeUIntLE(0x1234567890ab, 0, 6);\nconsole.log(buf2);\n  // Prints: <Buffer ab 90 78 56 34 12>
\n

Set noAssert to true to skip validation of value and offset. This means\nthat value may be too large for the specific function and offset may be\nbeyond the end of the Buffer leading to the values being silently dropped. This\nshould not be used unless you are certain of correctness.\n\n

\n" }, { "textRaw": "buf.writeUInt8(value, offset[, noAssert])", "type": "method", "name": "writeUInt8", "signatures": [ { "return": { "textRaw": "Return: {Number} Numbers of bytes written ", "name": "return", "type": "Number", "desc": "Numbers of bytes written" }, "params": [ { "textRaw": "`value` {Number} Bytes to be written to Buffer ", "name": "value", "type": "Number", "desc": "Bytes to be written to Buffer" }, { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 1` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 1`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

Writes value to the Buffer at the specified offset. The value must be a\nvalid unsigned 8-bit integer.\n\n

\n

Set noAssert to true to skip validation of value and offset. This means\nthat value may be too large for the specific function and offset may be\nbeyond the end of the Buffer leading to the values being silently dropped. This\nshould not be used unless you are certain of correctness.\n\n

\n

Example:\n\n

\n
const buf = new Buffer(4);\nbuf.writeUInt8(0x3, 0);\nbuf.writeUInt8(0x4, 1);\nbuf.writeUInt8(0x23, 2);\nbuf.writeUInt8(0x42, 3);\n\nconsole.log(buf);\n  // Prints: <Buffer 03 04 23 42>
\n" }, { "textRaw": "buf.writeUInt16BE(value, offset[, noAssert])", "type": "method", "name": "writeUInt16BE", "signatures": [ { "return": { "textRaw": "Return: {Number} Numbers of bytes written ", "name": "return", "type": "Number", "desc": "Numbers of bytes written" }, "params": [ { "textRaw": "`value` {Number} Bytes to be written to Buffer ", "name": "value", "type": "Number", "desc": "Bytes to be written to Buffer" }, { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 2` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 2`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "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 the Buffer at the specified offset with specified endian\nformat (writeUInt16BE() writes big endian, writeUInt16LE() writes little\nendian). The value must be a valid unsigned 16-bit integer.\n\n

\n

Set noAssert to true to skip validation of value and offset. This means\nthat value may be too large for the specific function and offset may be\nbeyond the end of the Buffer leading to the values being silently dropped. This\nshould not be used unless you are certain of correctness.\n\n

\n

Example:\n\n

\n
const buf = new Buffer(4);\nbuf.writeUInt16BE(0xdead, 0);\nbuf.writeUInt16BE(0xbeef, 2);\n\nconsole.log(buf);\n  // Prints: <Buffer de ad be ef>\n\nbuf.writeUInt16LE(0xdead, 0);\nbuf.writeUInt16LE(0xbeef, 2);\n\nconsole.log(buf);\n  // Prints: <Buffer ad de ef be>
\n" }, { "textRaw": "buf.writeUInt16LE(value, offset[, noAssert])", "type": "method", "name": "writeUInt16LE", "signatures": [ { "return": { "textRaw": "Return: {Number} Numbers of bytes written ", "name": "return", "type": "Number", "desc": "Numbers of bytes written" }, "params": [ { "textRaw": "`value` {Number} Bytes to be written to Buffer ", "name": "value", "type": "Number", "desc": "Bytes to be written to Buffer" }, { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 2` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 2`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

Writes value to the Buffer at the specified offset with specified endian\nformat (writeUInt16BE() writes big endian, writeUInt16LE() writes little\nendian). The value must be a valid unsigned 16-bit integer.\n\n

\n

Set noAssert to true to skip validation of value and offset. This means\nthat value may be too large for the specific function and offset may be\nbeyond the end of the Buffer leading to the values being silently dropped. This\nshould not be used unless you are certain of correctness.\n\n

\n

Example:\n\n

\n
const buf = new Buffer(4);\nbuf.writeUInt16BE(0xdead, 0);\nbuf.writeUInt16BE(0xbeef, 2);\n\nconsole.log(buf);\n  // Prints: <Buffer de ad be ef>\n\nbuf.writeUInt16LE(0xdead, 0);\nbuf.writeUInt16LE(0xbeef, 2);\n\nconsole.log(buf);\n  // Prints: <Buffer ad de ef be>
\n" }, { "textRaw": "buf.writeUInt32BE(value, offset[, noAssert])", "type": "method", "name": "writeUInt32BE", "signatures": [ { "return": { "textRaw": "Return: {Number} Numbers of bytes written ", "name": "return", "type": "Number", "desc": "Numbers of bytes written" }, "params": [ { "textRaw": "`value` {Number} Bytes to be written to Buffer ", "name": "value", "type": "Number", "desc": "Bytes to be written to Buffer" }, { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 4` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 4`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "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 the Buffer at the specified offset with specified endian\nformat (writeUInt32BE() writes big endian, writeUInt32LE() writes little\nendian). The value must be a valid unsigned 32-bit integer.\n\n

\n

Set noAssert to true to skip validation of value and offset. This means\nthat value may be too large for the specific function and offset may be\nbeyond the end of the Buffer leading to the values being silently dropped. This\nshould not be used unless you are certain of correctness.\n\n

\n

Example:\n\n

\n
const buf = new Buffer(4);\nbuf.writeUInt32BE(0xfeedface, 0);\n\nconsole.log(buf);\n  // Prints: <Buffer fe ed fa ce>\n\nbuf.writeUInt32LE(0xfeedface, 0);\n\nconsole.log(buf);\n  // Prints: <Buffer ce fa ed fe>
\n" }, { "textRaw": "buf.writeUInt32LE(value, offset[, noAssert])", "type": "method", "name": "writeUInt32LE", "signatures": [ { "return": { "textRaw": "Return: {Number} Numbers of bytes written ", "name": "return", "type": "Number", "desc": "Numbers of bytes written" }, "params": [ { "textRaw": "`value` {Number} Bytes to be written to Buffer ", "name": "value", "type": "Number", "desc": "Bytes to be written to Buffer" }, { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - 4` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - 4`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

Writes value to the Buffer at the specified offset with specified endian\nformat (writeUInt32BE() writes big endian, writeUInt32LE() writes little\nendian). The value must be a valid unsigned 32-bit integer.\n\n

\n

Set noAssert to true to skip validation of value and offset. This means\nthat value may be too large for the specific function and offset may be\nbeyond the end of the Buffer leading to the values being silently dropped. This\nshould not be used unless you are certain of correctness.\n\n

\n

Example:\n\n

\n
const buf = new Buffer(4);\nbuf.writeUInt32BE(0xfeedface, 0);\n\nconsole.log(buf);\n  // Prints: <Buffer fe ed fa ce>\n\nbuf.writeUInt32LE(0xfeedface, 0);\n\nconsole.log(buf);\n  // Prints: <Buffer ce fa ed fe>
\n" }, { "textRaw": "buf.writeUIntBE(value, offset, byteLength[, noAssert])", "type": "method", "name": "writeUIntBE", "signatures": [ { "return": { "textRaw": "Return: {Number} Numbers of bytes written ", "name": "return", "type": "Number", "desc": "Numbers of bytes written" }, "params": [ { "textRaw": "`value` {Number} Bytes to be written to Buffer ", "name": "value", "type": "Number", "desc": "Bytes to be written to Buffer" }, { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - byteLength` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - byteLength`" }, { "textRaw": "`byteLength` {Number} `0 < byteLength <= 6` ", "name": "byteLength", "type": "Number", "desc": "`0 < byteLength <= 6`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "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 value to the Buffer at the specified offset and byteLength.\nSupports up to 48 bits of accuracy. For example:\n\n

\n
const buf = new Buffer(6);\nbuf.writeUIntBE(0x1234567890ab, 0, 6);\nconsole.log(buf);\n  // Prints: <Buffer 12 34 56 78 90 ab>
\n

Set noAssert to true to skip validation of value and offset. This means\nthat value may be too large for the specific function and offset may be\nbeyond the end of the Buffer leading to the values being silently dropped. This\nshould not be used unless you are certain of correctness.\n\n

\n" }, { "textRaw": "buf.writeUIntLE(value, offset, byteLength[, noAssert])", "type": "method", "name": "writeUIntLE", "signatures": [ { "return": { "textRaw": "Return: {Number} Numbers of bytes written ", "name": "return", "type": "Number", "desc": "Numbers of bytes written" }, "params": [ { "textRaw": "`value` {Number} Bytes to be written to Buffer ", "name": "value", "type": "Number", "desc": "Bytes to be written to Buffer" }, { "textRaw": "`offset` {Number} `0 <= offset <= buf.length - byteLength` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length - byteLength`" }, { "textRaw": "`byteLength` {Number} `0 < byteLength <= 6` ", "name": "byteLength", "type": "Number", "desc": "`0 < byteLength <= 6`" }, { "textRaw": "`noAssert` {Boolean} Default: false ", "name": "noAssert", "type": "Boolean", "desc": "Default: false", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "byteLength" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

Writes value to the Buffer at the specified offset and byteLength.\nSupports up to 48 bits of accuracy. For example:\n\n

\n
const buf = new Buffer(6);\nbuf.writeUIntBE(0x1234567890ab, 0, 6);\nconsole.log(buf);\n  // Prints: <Buffer 12 34 56 78 90 ab>
\n

Set noAssert to true to skip validation of value and offset. This means\nthat value may be too large for the specific function and offset may be\nbeyond the end of the Buffer leading to the values being silently dropped. This\nshould not be used unless you are certain of correctness.\n\n

\n" } ], "signatures": [ { "params": [ { "textRaw": "`array` {Array} ", "name": "array", "type": "Array" } ], "desc": "

Allocates a new Buffer using an array of octets.\n\n

\n
const buf = new Buffer([0x62,0x75,0x66,0x66,0x65,0x72]);\n  // creates a new Buffer containing ASCII bytes\n  // ['b','u','f','f','e','r']
\n" }, { "params": [ { "name": "array" } ], "desc": "

Allocates a new Buffer using an array of octets.\n\n

\n
const buf = new Buffer([0x62,0x75,0x66,0x66,0x65,0x72]);\n  // creates a new Buffer containing ASCII bytes\n  // ['b','u','f','f','e','r']
\n" }, { "params": [ { "textRaw": "`buffer` {Buffer} ", "name": "buffer", "type": "Buffer" } ], "desc": "

Copies the passed buffer data onto a new Buffer instance.\n\n

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

Copies the passed buffer data onto a new Buffer instance.\n\n

\n
const buf1 = new Buffer('buffer');\nconst buf2 = new Buffer(buf1);\n\nbuf1[0] = 0x61;\nconsole.log(buf1.toString());\n  // 'auffer'\nconsole.log(buf2.toString());\n  // 'buffer' (copy is not changed)
\n" }, { "params": [ { "textRaw": "`arrayBuffer` - The `.buffer` property of a `TypedArray` or a `new ArrayBuffer()` ", "name": "arrayBuffer", "desc": "The `.buffer` property of a `TypedArray` or a `new ArrayBuffer()`" } ], "desc": "

When passed a reference to the .buffer property of a TypedArray instance,\nthe newly created Buffer will share the same allocated memory as the\nTypedArray.\n\n

\n
const arr = new Uint16Array(2);\narr[0] = 5000;\narr[1] = 4000;\n\nconst buf = new Buffer(arr.buffer); // shares the memory with arr;\n\nconsole.log(buf);\n  // Prints: <Buffer 88 13 a0 0f>\n\n// changing the TypdArray changes the Buffer also\narr[1] = 6000;\n\nconsole.log(buf);\n  // Prints: <Buffer 88 13 70 17>
\n" }, { "params": [ { "name": "arrayBuffer" } ], "desc": "

When passed a reference to the .buffer property of a TypedArray instance,\nthe newly created Buffer will share the same allocated memory as the\nTypedArray.\n\n

\n
const arr = new Uint16Array(2);\narr[0] = 5000;\narr[1] = 4000;\n\nconst buf = new Buffer(arr.buffer); // shares the memory with arr;\n\nconsole.log(buf);\n  // Prints: <Buffer 88 13 a0 0f>\n\n// changing the TypdArray changes the Buffer also\narr[1] = 6000;\n\nconsole.log(buf);\n  // Prints: <Buffer 88 13 70 17>
\n" }, { "params": [ { "textRaw": "`size` {Number} ", "name": "size", "type": "Number" } ], "desc": "

Allocates a new Buffer of size bytes. The size must be less than\nor equal to the value of require('buffer').kMaxLength (on 64-bit\narchitectures, kMaxLength is (2^31)-1). Otherwise, a [RangeError][] is\nthrown. If a size less than 0 is specified, a zero-length Buffer will be\ncreated.\n\n

\n

Unlike ArrayBuffers, the underlying memory for Buffer instances created in\nthis way is not initialized. The contents of a newly created Buffer are\nunknown and could contain sensitive data. Use [buf.fill(0)][] to initialize a\nBuffer to zeroes.\n\n

\n
const buf = new Buffer(5);\nconsole.log(buf);\n  // <Buffer 78 e0 82 02 01>\n  // (octets will be different, every time)\nbuf.fill(0);\nconsole.log(buf);\n  // <Buffer 00 00 00 00 00>
\n" }, { "params": [ { "name": "size" } ], "desc": "

Allocates a new Buffer of size bytes. The size must be less than\nor equal to the value of require('buffer').kMaxLength (on 64-bit\narchitectures, kMaxLength is (2^31)-1). Otherwise, a [RangeError][] is\nthrown. If a size less than 0 is specified, a zero-length Buffer will be\ncreated.\n\n

\n

Unlike ArrayBuffers, the underlying memory for Buffer instances created in\nthis way is not initialized. The contents of a newly created Buffer are\nunknown and could contain sensitive data. Use [buf.fill(0)][] to initialize a\nBuffer to zeroes.\n\n

\n
const buf = new Buffer(5);\nconsole.log(buf);\n  // <Buffer 78 e0 82 02 01>\n  // (octets will be different, every time)\nbuf.fill(0);\nconsole.log(buf);\n  // <Buffer 00 00 00 00 00>
\n" }, { "params": [ { "textRaw": "`str` {String} String to encode. ", "name": "str", "type": "String", "desc": "String to encode." }, { "textRaw": "`encoding` {String} Default: `'utf8'` ", "name": "encoding", "type": "String", "desc": "Default: `'utf8'`", "optional": true } ], "desc": "

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

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

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

\n
const buf1 = new Buffer('this is a tést');\nconsole.log(buf1.toString());\n  // prints: this is a tést\nconsole.log(buf1.toString('ascii'));\n  // prints: this is a tC)st\n\nconst buf2 = new Buffer('7468697320697320612074c3a97374', 'hex');\nconsole.log(buf2.toString());\n  // prints: this is a tést
\n" } ] }, { "textRaw": "Class: SlowBuffer", "type": "class", "name": "SlowBuffer", "desc": "

Returns an un-pooled Buffer.\n\n

\n

In order to avoid the garbage collection overhead of creating many individually\nallocated Buffers, by default allocations under 4KB are sliced from a single\nlarger allocated object. This approach improves both performance and memory\nusage since v8 does not need to track and cleanup as many Persistent objects.\n\n

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

\n
// need to keep around a few small chunks of memory\nconst store = [];\n\nsocket.on('readable', () => {\n  var data = socket.read();\n  // allocate for retained data\n  var sb = new SlowBuffer(10);\n  // copy the data into the new allocation\n  data.copy(sb, 0, 0, 10);\n  store.push(sb);\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\n

\n" } ], "properties": [ { "textRaw": "`INSPECT_MAX_BYTES` {Number} Default: 50 ", "type": "Number", "name": "INSPECT_MAX_BYTES", "desc": "

Returns the maximum number of bytes that will be returned when\nbuffer.inspect() is called. This can be overridden by user modules. See\n[util.inspect()][] for more details on buffer.inspect() behavior.\n\n

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

\n", "shortDesc": "Default: 50" } ], "type": "module", "displayName": "Buffer" } ] }