{ "source": "doc/api/buffer.markdown", "modules": [ { "textRaw": "Buffer", "name": "buffer", "stability": 3, "stabilityText": "Stable", "desc": "

Pure JavaScript is Unicode friendly but not nice to binary data. When\ndealing with TCP streams or the file system, it's necessary to handle octet\nstreams. Node has several strategies for manipulating, creating, and\nconsuming octet streams.\n\n

\n

Raw data is stored in instances of the Buffer class. A Buffer is similar\nto an array of integers but corresponds to a raw memory allocation outside\nthe V8 heap. A Buffer cannot be resized.\n\n

\n

The Buffer class is a global, making it very rare that one would need\nto ever require('buffer').\n\n

\n

Converting between Buffers and JavaScript string objects requires an explicit\nencoding method. Here are the different string encodings.\n\n

\n\n

Buffer can also be used with Typed Array Views and DataViews.\n\n

\n
var buff = new Buffer(4);\nvar ui16 = new Uint16Array(buff);\nvar view = new DataView(buff);\n\nui16[0] = 1;\nui16[1] = 2;\nconsole.log(buff);\n\nview.setInt16(0, 1);       // set big-endian int16 at byte offset 0\nview.setInt16(2, 2, true); // set little-endian int16 at byte offset 2\nconsole.log(buff);\n\n// <Buffer 01 00 02 00>\n// <Buffer 00 01 02 00>
\n", "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.isEncoding(encoding)", "type": "classMethod", "name": "isEncoding", "signatures": [ { "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" }, { "textRaw": "Class Method: Buffer.isBuffer(obj)", "type": "classMethod", "name": "isBuffer", "signatures": [ { "return": { "textRaw": "Return: Boolean ", "name": "return", "desc": "Boolean" }, "params": [ { "textRaw": "`obj` Object ", "name": "obj", "desc": "Object" } ] }, { "params": [ { "name": "obj" } ] } ], "desc": "

Tests if obj is a Buffer.\n\n

\n" }, { "textRaw": "Class Method: Buffer.byteLength(string, [encoding])", "type": "classMethod", "name": "byteLength", "signatures": [ { "return": { "textRaw": "Return: Number ", "name": "return", "desc": "Number" }, "params": [ { "textRaw": "`string` String ", "name": "string", "desc": "String" }, { "textRaw": "`encoding` String, Optional, Default: 'utf8' ", "name": "encoding", "desc": "String, Optional, Default: 'utf8'", "optional": true } ] }, { "params": [ { "name": "string" }, { "name": "encoding", "optional": true } ] } ], "desc": "

Gives the actual byte length of a string. encoding defaults to 'utf8'.\nThis is not the same as String.prototype.length since that returns the\nnumber of characters in a string.\n\n

\n

Example:\n\n

\n
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.concat(list, [totalLength])", "type": "classMethod", "name": "concat", "signatures": [ { "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 when concatenated ", "name": "totalLength", "type": "Number", "desc": "Total length of the buffers when concatenated", "optional": true } ] }, { "params": [ { "name": "list" }, { "name": "totalLength", "optional": true } ] } ], "desc": "

Returns a 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 it returns a\nzero-length buffer.\n\n

\n

If the list has exactly one item, then the first item of the list is\nreturned.\n\n

\n

If the list has more than one item, then a new Buffer is created.\n\n

\n

If totalLength is not provided, it is read from the buffers in the list.\nHowever, this adds an additional loop to the function, so it is faster\nto provide the length explicitly.\n\n

\n" } ], "methods": [ { "textRaw": "buf.write(string, [offset], [length], [encoding])", "type": "method", "name": "write", "signatures": [ { "params": [ { "textRaw": "`string` String - data to be written to buffer ", "name": "string", "desc": "String - data to be written to buffer" }, { "textRaw": "`offset` Number, Optional, Default: 0 ", "name": "offset", "desc": "Number, Optional, Default: 0", "optional": true }, { "textRaw": "`length` Number, Optional, Default: `buffer.length - offset` ", "name": "length", "desc": "Number, Optional, Default: `buffer.length - offset`", "optional": true }, { "textRaw": "`encoding` String, Optional, Default: 'utf8' ", "name": "encoding", "desc": "String, Optional, Default: 'utf8'", "optional": true } ] }, { "params": [ { "name": "string" }, { "name": "offset", "optional": true }, { "name": "length", "optional": true }, { "name": "encoding", "optional": true } ] } ], "desc": "

Writes string to the buffer at offset using the given encoding.\noffset defaults to 0, encoding defaults to 'utf8'. length is\nthe number of bytes to write. Returns number of octets written. If buffer did\nnot contain enough space to fit the entire string, it will write a partial\namount of the string. length defaults to buffer.length - offset.\nThe method will not write partial characters.\n\n

\n
buf = new Buffer(256);\nlen = buf.write('\\u00bd + \\u00bc = \\u00be', 0);\nconsole.log(len + " bytes: " + buf.toString('utf8', 0, len));
\n

The number of characters written (which may be different than the number of\nbytes written) is set in Buffer._charsWritten and will be overwritten the\nnext time buf.write() is called.\n\n\n

\n" }, { "textRaw": "buf.toString([encoding], [start], [end])", "type": "method", "name": "toString", "signatures": [ { "params": [ { "textRaw": "`encoding` String, Optional, Default: 'utf8' ", "name": "encoding", "desc": "String, Optional, Default: 'utf8'", "optional": true }, { "textRaw": "`start` Number, Optional, Default: 0 ", "name": "start", "desc": "Number, Optional, Default: 0", "optional": true }, { "textRaw": "`end` Number, Optional, Default: `buffer.length` ", "name": "end", "desc": "Number, Optional, Default: `buffer.length`", "optional": true } ] }, { "params": [ { "name": "encoding", "optional": true }, { "name": "start", "optional": true }, { "name": "end", "optional": true } ] } ], "desc": "

Decodes and returns a string from buffer data encoded with encoding\n(defaults to 'utf8') beginning at start (defaults to 0) and ending at\nend (defaults to buffer.length).\n\n

\n

See buffer.write() example, above.\n\n\n

\n" }, { "textRaw": "buf.toJSON()", "type": "method", "name": "toJSON", "desc": "

Returns a JSON-representation of the Buffer instance, which is identical to the\noutput for JSON Arrays. JSON.stringify implicitly calls this function when\nstringifying a Buffer instance.\n\n

\n

Example:\n\n

\n
var buf = new Buffer('test');\nvar json = JSON.stringify(buf);\n\nconsole.log(json);\n// '[116,101,115,116]'\n\nvar copy = new Buffer(JSON.parse(json));\n\nconsole.log(copy);\n// <Buffer 74 65 73 74>
\n", "signatures": [ { "params": [] } ] }, { "textRaw": "buf.copy(targetBuffer, [targetStart], [sourceStart], [sourceEnd])", "type": "method", "name": "copy", "signatures": [ { "params": [ { "textRaw": "`targetBuffer` Buffer object - Buffer to copy into ", "name": "targetBuffer", "desc": "Buffer object - Buffer to copy into" }, { "textRaw": "`targetStart` Number, Optional, Default: 0 ", "name": "targetStart", "desc": "Number, Optional, Default: 0", "optional": true }, { "textRaw": "`sourceStart` Number, Optional, Default: 0 ", "name": "sourceStart", "desc": "Number, Optional, Default: 0", "optional": true }, { "textRaw": "`sourceEnd` Number, Optional, Default: `buffer.length` ", "name": "sourceEnd", "desc": "Number, Optional, Default: `buffer.length`", "optional": true } ] }, { "params": [ { "name": "targetBuffer" }, { "name": "targetStart", "optional": true }, { "name": "sourceStart", "optional": true }, { "name": "sourceEnd", "optional": true } ] } ], "desc": "

Does copy between buffers. The source and target regions can be overlapped.\ntargetStart and sourceStart default to 0.\nsourceEnd defaults to buffer.length.\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
buf1 = new Buffer(26);\nbuf2 = new Buffer(26);\n\nfor (var i = 0 ; i < 26 ; i++) {\n  buf1[i] = i + 97; // 97 is ASCII a\n  buf2[i] = 33; // ASCII !\n}\n\nbuf1.copy(buf2, 8, 16, 20);\nconsole.log(buf2.toString('ascii', 0, 25));\n\n// !!!!!!!!qrst!!!!!!!!!!!!!
\n" }, { "textRaw": "buf.slice([start], [end])", "type": "method", "name": "slice", "signatures": [ { "params": [ { "textRaw": "`start` Number, Optional, Default: 0 ", "name": "start", "desc": "Number, Optional, Default: 0", "optional": true }, { "textRaw": "`end` Number, Optional, Default: `buffer.length` ", "name": "end", "desc": "Number, Optional, Default: `buffer.length`", "optional": true } ] }, { "params": [ { "name": "start", "optional": true }, { "name": "end", "optional": true } ] } ], "desc": "

Returns a new buffer which references the same memory as the old, but offset\nand cropped by the start (defaults to 0) and end (defaults to\nbuffer.length) indexes.\n\n

\n

Modifying the new buffer slice will modify memory in the original buffer!\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
var buf1 = new Buffer(26);\n\nfor (var i = 0 ; i < 26 ; i++) {\n  buf1[i] = i + 97; // 97 is ASCII a\n}\n\nvar buf2 = buf1.slice(0, 3);\nconsole.log(buf2.toString('ascii', 0, buf2.length));\nbuf1[0] = 33;\nconsole.log(buf2.toString('ascii', 0, buf2.length));\n\n// abc\n// !bc
\n" }, { "textRaw": "buf.readUInt8(offset, [noAssert])", "type": "method", "name": "readUInt8", "signatures": [ { "return": { "textRaw": "Return: Number ", "name": "return", "desc": "Number" }, "params": [ { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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

Set noAssert to true to skip validation of offset. This means that offset\nmay be beyond the end of the buffer. Defaults to false.\n\n

\n

Example:\n\n

\n
var buf = new Buffer(4);\n\nbuf[0] = 0x3;\nbuf[1] = 0x4;\nbuf[2] = 0x23;\nbuf[3] = 0x42;\n\nfor (ii = 0; ii < buf.length; ii++) {\n  console.log(buf.readUInt8(ii));\n}\n\n// 0x3\n// 0x4\n// 0x23\n// 0x42
\n" }, { "textRaw": "buf.readUInt16LE(offset, [noAssert])", "type": "method", "name": "readUInt16LE", "signatures": [ { "return": { "textRaw": "Return: Number ", "name": "return", "desc": "Number" }, "params": [ { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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.\n\n

\n

Set noAssert to true to skip validation of offset. This means that offset\nmay be beyond the end of the buffer. Defaults to false.\n\n

\n

Example:\n\n

\n
var buf = new Buffer(4);\n\nbuf[0] = 0x3;\nbuf[1] = 0x4;\nbuf[2] = 0x23;\nbuf[3] = 0x42;\n\nconsole.log(buf.readUInt16BE(0));\nconsole.log(buf.readUInt16LE(0));\nconsole.log(buf.readUInt16BE(1));\nconsole.log(buf.readUInt16LE(1));\nconsole.log(buf.readUInt16BE(2));\nconsole.log(buf.readUInt16LE(2));\n\n// 0x0304\n// 0x0403\n// 0x0423\n// 0x2304\n// 0x2342\n// 0x4223
\n" }, { "textRaw": "buf.readUInt16BE(offset, [noAssert])", "type": "method", "name": "readUInt16BE", "signatures": [ { "return": { "textRaw": "Return: Number ", "name": "return", "desc": "Number" }, "params": [ { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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.\n\n

\n

Set noAssert to true to skip validation of offset. This means that offset\nmay be beyond the end of the buffer. Defaults to false.\n\n

\n

Example:\n\n

\n
var buf = new Buffer(4);\n\nbuf[0] = 0x3;\nbuf[1] = 0x4;\nbuf[2] = 0x23;\nbuf[3] = 0x42;\n\nconsole.log(buf.readUInt16BE(0));\nconsole.log(buf.readUInt16LE(0));\nconsole.log(buf.readUInt16BE(1));\nconsole.log(buf.readUInt16LE(1));\nconsole.log(buf.readUInt16BE(2));\nconsole.log(buf.readUInt16LE(2));\n\n// 0x0304\n// 0x0403\n// 0x0423\n// 0x2304\n// 0x2342\n// 0x4223
\n" }, { "textRaw": "buf.readUInt32LE(offset, [noAssert])", "type": "method", "name": "readUInt32LE", "signatures": [ { "return": { "textRaw": "Return: Number ", "name": "return", "desc": "Number" }, "params": [ { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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.\n\n

\n

Set noAssert to true to skip validation of offset. This means that offset\nmay be beyond the end of the buffer. Defaults to false.\n\n

\n

Example:\n\n

\n
var buf = new Buffer(4);\n\nbuf[0] = 0x3;\nbuf[1] = 0x4;\nbuf[2] = 0x23;\nbuf[3] = 0x42;\n\nconsole.log(buf.readUInt32BE(0));\nconsole.log(buf.readUInt32LE(0));\n\n// 0x03042342\n// 0x42230403
\n" }, { "textRaw": "buf.readUInt32BE(offset, [noAssert])", "type": "method", "name": "readUInt32BE", "signatures": [ { "return": { "textRaw": "Return: Number ", "name": "return", "desc": "Number" }, "params": [ { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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.\n\n

\n

Set noAssert to true to skip validation of offset. This means that offset\nmay be beyond the end of the buffer. Defaults to false.\n\n

\n

Example:\n\n

\n
var buf = new Buffer(4);\n\nbuf[0] = 0x3;\nbuf[1] = 0x4;\nbuf[2] = 0x23;\nbuf[3] = 0x42;\n\nconsole.log(buf.readUInt32BE(0));\nconsole.log(buf.readUInt32LE(0));\n\n// 0x03042342\n// 0x42230403
\n" }, { "textRaw": "buf.readInt8(offset, [noAssert])", "type": "method", "name": "readInt8", "signatures": [ { "return": { "textRaw": "Return: Number ", "name": "return", "desc": "Number" }, "params": [ { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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

Set noAssert to true to skip validation of offset. This means that offset\nmay be beyond the end of the buffer. Defaults to false.\n\n

\n

Works as buffer.readUInt8, except buffer contents are treated as two's\ncomplement signed values.\n\n

\n" }, { "textRaw": "buf.readInt16LE(offset, [noAssert])", "type": "method", "name": "readInt16LE", "signatures": [ { "return": { "textRaw": "Return: Number ", "name": "return", "desc": "Number" }, "params": [ { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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\nspecified endian format.\n\n

\n

Set noAssert to true to skip validation of offset. This means that offset\nmay be beyond the end of the buffer. Defaults to false.\n\n

\n

Works as buffer.readUInt16*, except buffer contents are treated as two's\ncomplement signed values.\n\n

\n" }, { "textRaw": "buf.readInt16BE(offset, [noAssert])", "type": "method", "name": "readInt16BE", "signatures": [ { "return": { "textRaw": "Return: Number ", "name": "return", "desc": "Number" }, "params": [ { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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\nspecified endian format.\n\n

\n

Set noAssert to true to skip validation of offset. This means that offset\nmay be beyond the end of the buffer. Defaults to false.\n\n

\n

Works as buffer.readUInt16*, except buffer contents are treated as two's\ncomplement signed values.\n\n

\n" }, { "textRaw": "buf.readInt32LE(offset, [noAssert])", "type": "method", "name": "readInt32LE", "signatures": [ { "return": { "textRaw": "Return: Number ", "name": "return", "desc": "Number" }, "params": [ { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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\nspecified endian format.\n\n

\n

Set noAssert to true to skip validation of offset. This means that offset\nmay be beyond the end of the buffer. Defaults to false.\n\n

\n

Works as buffer.readUInt32*, except buffer contents are treated as two's\ncomplement signed values.\n\n

\n" }, { "textRaw": "buf.readInt32BE(offset, [noAssert])", "type": "method", "name": "readInt32BE", "signatures": [ { "return": { "textRaw": "Return: Number ", "name": "return", "desc": "Number" }, "params": [ { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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\nspecified endian format.\n\n

\n

Set noAssert to true to skip validation of offset. This means that offset\nmay be beyond the end of the buffer. Defaults to false.\n\n

\n

Works as buffer.readUInt32*, except buffer contents are treated as two's\ncomplement signed values.\n\n

\n" }, { "textRaw": "buf.readFloatLE(offset, [noAssert])", "type": "method", "name": "readFloatLE", "signatures": [ { "return": { "textRaw": "Return: Number ", "name": "return", "desc": "Number" }, "params": [ { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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.\n\n

\n

Set noAssert to true to skip validation of offset. This means that offset\nmay be beyond the end of the buffer. Defaults to false.\n\n

\n

Example:\n\n

\n
var buf = new Buffer(4);\n\nbuf[0] = 0x00;\nbuf[1] = 0x00;\nbuf[2] = 0x80;\nbuf[3] = 0x3f;\n\nconsole.log(buf.readFloatLE(0));\n\n// 0x01
\n" }, { "textRaw": "buf.readFloatBE(offset, [noAssert])", "type": "method", "name": "readFloatBE", "signatures": [ { "return": { "textRaw": "Return: Number ", "name": "return", "desc": "Number" }, "params": [ { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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.\n\n

\n

Set noAssert to true to skip validation of offset. This means that offset\nmay be beyond the end of the buffer. Defaults to false.\n\n

\n

Example:\n\n

\n
var buf = new Buffer(4);\n\nbuf[0] = 0x00;\nbuf[1] = 0x00;\nbuf[2] = 0x80;\nbuf[3] = 0x3f;\n\nconsole.log(buf.readFloatLE(0));\n\n// 0x01
\n" }, { "textRaw": "buf.readDoubleLE(offset, [noAssert])", "type": "method", "name": "readDoubleLE", "signatures": [ { "return": { "textRaw": "Return: Number ", "name": "return", "desc": "Number" }, "params": [ { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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.\n\n

\n

Set noAssert to true to skip validation of offset. This means that offset\nmay be beyond the end of the buffer. Defaults to false.\n\n

\n

Example:\n\n

\n
var buf = new Buffer(8);\n\nbuf[0] = 0x55;\nbuf[1] = 0x55;\nbuf[2] = 0x55;\nbuf[3] = 0x55;\nbuf[4] = 0x55;\nbuf[5] = 0x55;\nbuf[6] = 0xd5;\nbuf[7] = 0x3f;\n\nconsole.log(buf.readDoubleLE(0));\n\n// 0.3333333333333333
\n" }, { "textRaw": "buf.readDoubleBE(offset, [noAssert])", "type": "method", "name": "readDoubleBE", "signatures": [ { "return": { "textRaw": "Return: Number ", "name": "return", "desc": "Number" }, "params": [ { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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.\n\n

\n

Set noAssert to true to skip validation of offset. This means that offset\nmay be beyond the end of the buffer. Defaults to false.\n\n

\n

Example:\n\n

\n
var buf = new Buffer(8);\n\nbuf[0] = 0x55;\nbuf[1] = 0x55;\nbuf[2] = 0x55;\nbuf[3] = 0x55;\nbuf[4] = 0x55;\nbuf[5] = 0x55;\nbuf[6] = 0xd5;\nbuf[7] = 0x3f;\n\nconsole.log(buf.readDoubleLE(0));\n\n// 0.3333333333333333
\n" }, { "textRaw": "buf.writeUInt8(value, offset, [noAssert])", "type": "method", "name": "writeUInt8", "signatures": [ { "params": [ { "textRaw": "`value` Number ", "name": "value", "desc": "Number" }, { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, Default: false", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

Writes value to the buffer at the specified offset. Note, 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. Defaults to false.\n\n

\n

Example:\n\n

\n
var 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\n// <Buffer 03 04 23 42>
\n" }, { "textRaw": "buf.writeUInt16LE(value, offset, [noAssert])", "type": "method", "name": "writeUInt16LE", "signatures": [ { "params": [ { "textRaw": "`value` Number ", "name": "value", "desc": "Number" }, { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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. Note, 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. Defaults to false.\n\n

\n

Example:\n\n

\n
var buf = new Buffer(4);\nbuf.writeUInt16BE(0xdead, 0);\nbuf.writeUInt16BE(0xbeef, 2);\n\nconsole.log(buf);\n\nbuf.writeUInt16LE(0xdead, 0);\nbuf.writeUInt16LE(0xbeef, 2);\n\nconsole.log(buf);\n\n// <Buffer de ad be ef>\n// <Buffer ad de ef be>
\n" }, { "textRaw": "buf.writeUInt16BE(value, offset, [noAssert])", "type": "method", "name": "writeUInt16BE", "signatures": [ { "params": [ { "textRaw": "`value` Number ", "name": "value", "desc": "Number" }, { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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. Note, 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. Defaults to false.\n\n

\n

Example:\n\n

\n
var buf = new Buffer(4);\nbuf.writeUInt16BE(0xdead, 0);\nbuf.writeUInt16BE(0xbeef, 2);\n\nconsole.log(buf);\n\nbuf.writeUInt16LE(0xdead, 0);\nbuf.writeUInt16LE(0xbeef, 2);\n\nconsole.log(buf);\n\n// <Buffer de ad be ef>\n// <Buffer ad de ef be>
\n" }, { "textRaw": "buf.writeUInt32LE(value, offset, [noAssert])", "type": "method", "name": "writeUInt32LE", "signatures": [ { "params": [ { "textRaw": "`value` Number ", "name": "value", "desc": "Number" }, { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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. Note, 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. Defaults to false.\n\n

\n

Example:\n\n

\n
var buf = new Buffer(4);\nbuf.writeUInt32BE(0xfeedface, 0);\n\nconsole.log(buf);\n\nbuf.writeUInt32LE(0xfeedface, 0);\n\nconsole.log(buf);\n\n// <Buffer fe ed fa ce>\n// <Buffer ce fa ed fe>
\n" }, { "textRaw": "buf.writeUInt32BE(value, offset, [noAssert])", "type": "method", "name": "writeUInt32BE", "signatures": [ { "params": [ { "textRaw": "`value` Number ", "name": "value", "desc": "Number" }, { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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. Note, 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. Defaults to false.\n\n

\n

Example:\n\n

\n
var buf = new Buffer(4);\nbuf.writeUInt32BE(0xfeedface, 0);\n\nconsole.log(buf);\n\nbuf.writeUInt32LE(0xfeedface, 0);\n\nconsole.log(buf);\n\n// <Buffer fe ed fa ce>\n// <Buffer ce fa ed fe>
\n" }, { "textRaw": "buf.writeInt8(value, offset, [noAssert])", "type": "method", "name": "writeInt8", "signatures": [ { "params": [ { "textRaw": "`value` Number ", "name": "value", "desc": "Number" }, { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, Default: false", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "offset" }, { "name": "noAssert", "optional": true } ] } ], "desc": "

Writes value to the buffer at the specified offset. Note, 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. Defaults to false.\n\n

\n

Works as buffer.writeUInt8, except value is written out as a two's complement\nsigned integer into buffer.\n\n

\n" }, { "textRaw": "buf.writeInt16LE(value, offset, [noAssert])", "type": "method", "name": "writeInt16LE", "signatures": [ { "params": [ { "textRaw": "`value` Number ", "name": "value", "desc": "Number" }, { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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. Note, 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. Defaults to false.\n\n

\n

Works as buffer.writeUInt16*, except value is written out as a two's\ncomplement signed integer into buffer.\n\n

\n" }, { "textRaw": "buf.writeInt16BE(value, offset, [noAssert])", "type": "method", "name": "writeInt16BE", "signatures": [ { "params": [ { "textRaw": "`value` Number ", "name": "value", "desc": "Number" }, { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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. Note, 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. Defaults to false.\n\n

\n

Works as buffer.writeUInt16*, except value is written out as a two's\ncomplement signed integer into buffer.\n\n

\n" }, { "textRaw": "buf.writeInt32LE(value, offset, [noAssert])", "type": "method", "name": "writeInt32LE", "signatures": [ { "params": [ { "textRaw": "`value` Number ", "name": "value", "desc": "Number" }, { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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. Note, 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. Defaults to false.\n\n

\n

Works as buffer.writeUInt32*, except value is written out as a two's\ncomplement signed integer into buffer.\n\n

\n" }, { "textRaw": "buf.writeInt32BE(value, offset, [noAssert])", "type": "method", "name": "writeInt32BE", "signatures": [ { "params": [ { "textRaw": "`value` Number ", "name": "value", "desc": "Number" }, { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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. Note, 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. Defaults to false.\n\n

\n

Works as buffer.writeUInt32*, except value is written out as a two's\ncomplement signed integer into buffer.\n\n

\n" }, { "textRaw": "buf.writeFloatLE(value, offset, [noAssert])", "type": "method", "name": "writeFloatLE", "signatures": [ { "params": [ { "textRaw": "`value` Number ", "name": "value", "desc": "Number" }, { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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. Note, value must be a valid 32 bit float.\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. Defaults to false.\n\n

\n

Example:\n\n

\n
var buf = new Buffer(4);\nbuf.writeFloatBE(0xcafebabe, 0);\n\nconsole.log(buf);\n\nbuf.writeFloatLE(0xcafebabe, 0);\n\nconsole.log(buf);\n\n// <Buffer 4f 4a fe bb>\n// <Buffer bb fe 4a 4f>
\n" }, { "textRaw": "buf.writeFloatBE(value, offset, [noAssert])", "type": "method", "name": "writeFloatBE", "signatures": [ { "params": [ { "textRaw": "`value` Number ", "name": "value", "desc": "Number" }, { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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. Note, value must be a valid 32 bit float.\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. Defaults to false.\n\n

\n

Example:\n\n

\n
var buf = new Buffer(4);\nbuf.writeFloatBE(0xcafebabe, 0);\n\nconsole.log(buf);\n\nbuf.writeFloatLE(0xcafebabe, 0);\n\nconsole.log(buf);\n\n// <Buffer 4f 4a fe bb>\n// <Buffer bb fe 4a 4f>
\n" }, { "textRaw": "buf.writeDoubleLE(value, offset, [noAssert])", "type": "method", "name": "writeDoubleLE", "signatures": [ { "params": [ { "textRaw": "`value` Number ", "name": "value", "desc": "Number" }, { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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. Note, value 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. Defaults to false.\n\n

\n

Example:\n\n

\n
var buf = new Buffer(8);\nbuf.writeDoubleBE(0xdeadbeefcafebabe, 0);\n\nconsole.log(buf);\n\nbuf.writeDoubleLE(0xdeadbeefcafebabe, 0);\n\nconsole.log(buf);\n\n// <Buffer 43 eb d5 b7 dd f9 5f d7>\n// <Buffer d7 5f f9 dd b7 d5 eb 43>
\n" }, { "textRaw": "buf.writeDoubleBE(value, offset, [noAssert])", "type": "method", "name": "writeDoubleBE", "signatures": [ { "params": [ { "textRaw": "`value` Number ", "name": "value", "desc": "Number" }, { "textRaw": "`offset` Number ", "name": "offset", "desc": "Number" }, { "textRaw": "`noAssert` Boolean, Optional, Default: false ", "name": "noAssert", "desc": "Boolean, Optional, 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. Note, value 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. Defaults to false.\n\n

\n

Example:\n\n

\n
var buf = new Buffer(8);\nbuf.writeDoubleBE(0xdeadbeefcafebabe, 0);\n\nconsole.log(buf);\n\nbuf.writeDoubleLE(0xdeadbeefcafebabe, 0);\n\nconsole.log(buf);\n\n// <Buffer 43 eb d5 b7 dd f9 5f d7>\n// <Buffer d7 5f f9 dd b7 d5 eb 43>
\n" }, { "textRaw": "buf.fill(value, [offset], [end])", "type": "method", "name": "fill", "signatures": [ { "params": [ { "textRaw": "`value` ", "name": "value" }, { "textRaw": "`offset` Number, Optional ", "name": "offset", "optional": true, "desc": "Number" }, { "textRaw": "`end` Number, Optional ", "name": "end", "optional": true, "desc": "Number" } ] }, { "params": [ { "name": "value" }, { "name": "offset", "optional": true }, { "name": "end", "optional": true } ] } ], "desc": "

Fills the buffer with the specified value. If the offset (defaults to 0)\nand end (defaults to buffer.length) are not given it will fill the entire\nbuffer.\n\n

\n
var b = new Buffer(50);\nb.fill("h");
\n" } ], "properties": [ { "textRaw": "buf[index]", "name": "[index]", "desc": "

Get and set the octet at index. The values refer to individual bytes,\nso the legal range is between 0x00 and 0xFF hex or 0 and 255.\n\n

\n

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

\n
str = "node.js";\nbuf = new Buffer(str.length);\n\nfor (var i = 0; i < str.length ; i++) {\n  buf[i] = str.charCodeAt(i);\n}\n\nconsole.log(buf);\n\n// node.js
\n" }, { "textRaw": "`length` Number ", "name": "length", "desc": "

The size of the buffer in bytes. Note that this is not necessarily the size\nof the contents. length refers to the amount of memory allocated for the\nbuffer object. It does not change when the contents of the buffer are changed.\n\n

\n
buf = new Buffer(1234);\n\nconsole.log(buf.length);\nbuf.write("some string", 0, "ascii");\nconsole.log(buf.length);\n\n// 1234\n// 1234
\n", "shortDesc": "Number" } ], "signatures": [ { "params": [ { "textRaw": "`size` Number ", "name": "size", "desc": "Number" } ], "desc": "

Allocates a new buffer of size octets.\n\n

\n" }, { "params": [ { "name": "size" } ], "desc": "

Allocates a new buffer of size octets.\n\n

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

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

\n" }, { "params": [ { "name": "array" } ], "desc": "

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

\n" }, { "params": [ { "textRaw": "`str` String - string to encode. ", "name": "str", "desc": "String - string to encode." }, { "textRaw": "`encoding` String - encoding to use, Optional. ", "name": "encoding", "desc": "String - encoding to use, Optional.", "optional": true } ], "desc": "

Allocates a new buffer containing the given str.\nencoding defaults to 'utf8'.\n\n

\n" }, { "params": [ { "name": "str" }, { "name": "encoding", "optional": true } ], "desc": "

Allocates a new buffer containing the given str.\nencoding defaults to 'utf8'.\n\n

\n" } ] }, { "textRaw": "Class: SlowBuffer", "type": "class", "name": "SlowBuffer", "desc": "

This class is primarily for internal use. JavaScript programs should\nuse Buffer instead of using SlowBuffer.\n\n

\n

In order to avoid the overhead of allocating many C++ Buffer objects for\nsmall blocks of memory in the lifetime of a server, Node allocates memory\nin 8Kb (8192 byte) chunks. If a buffer is smaller than this size, then it\nwill be backed by a parent SlowBuffer object. If it is larger than this,\nthen Node will allocate a SlowBuffer slab for it directly.\n

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

How many bytes will be returned when buffer.inspect() is called. This can\nbe overridden by user modules.\n\n

\n

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

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