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

Creating a typed array from a Buffer works with the following caveats:\n\n

\n
    \n
  1. The buffer's memory is copied, not shared.

    \n
  2. \n
  3. The buffer's memory is interpreted as an array, not a byte array. 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

NOTE: Node.js v0.8 simply retained a reference to the buffer in array.buffer\ninstead of cloning it.\n\n

\n

While more efficient, it introduces subtle incompatibilities with the typed\narrays specification. ArrayBuffer#slice() makes a copy of the slice while\nBuffer#slice() creates a view.\n\n

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

Example: build a single buffer from a list of three buffers:\n\n

\n
var buf1 = new Buffer(10);\nvar buf2 = new Buffer(14);\nvar buf3 = new Buffer(18);\n\nbuf1.fill(0);\nbuf2.fill(0);\nbuf3.fill(0);\n\nvar buffers = [buf1, buf2, buf3];\n\nvar totalLength = 0;\nfor (var i = 0; i < buffers.length; i++) {\n  totalLength += buffers[i].length;\n}\n\nconsole.log(totalLength);\nvar bufA = Buffer.concat(buffers, totalLength);\nconsole.log(bufA);\nconsole.log(bufA.length);\n\n// 42\n// <Buffer 00 00 00 00 ...>\n// 42
\n" }, { "textRaw": "Class Method: Buffer.compare(buf1, buf2)", "type": "classMethod", "name": "compare", "signatures": [ { "params": [ { "textRaw": "`buf1` {Buffer} ", "name": "buf1", "type": "Buffer" }, { "textRaw": "`buf2` {Buffer} ", "name": "buf2", "type": "Buffer" } ] }, { "params": [ { "name": "buf1" }, { "name": "buf2" } ] } ], "desc": "

The same as buf1.compare(buf2). Useful\nfor sorting an Array of Buffers:\n\n

\n
var arr = [Buffer('1234'), Buffer('0123')];\narr.sort(Buffer.compare);
\n" } ], "properties": [ { "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

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
buf = new Buffer(10);\nbuf.write("abcdefghj", 0, "ascii");\nconsole.log(buf.length); // 10\nbuf = buf.slice(0,5);\nconsole.log(buf.length); // 5
\n", "shortDesc": "Number" }, { "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" } ], "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" }, { "textRaw": "buf.writeIntLE(value, offset, byteLength[, noAssert])", "type": "method", "name": "writeIntLE", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "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` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length`" }, { "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
var b = new Buffer(6);\nb.writeUIntBE(0x1234567890ab, 0, 6);\n// <Buffer 12 34 56 78 90 ab>
\n

Set noAssert to true to skip validation of value and offset. Defaults\nto false.\n\n

\n" }, { "textRaw": "buf.writeIntBE(value, offset, byteLength[, noAssert])", "type": "method", "name": "writeIntBE", "signatures": [ { "return": { "textRaw": "Return: {Number} ", "name": "return", "type": "Number" }, "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` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length`" }, { "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
var b = new Buffer(6);\nb.writeUIntBE(0x1234567890ab, 0, 6);\n// <Buffer 12 34 56 78 90 ab>
\n

Set noAssert to true to skip validation of value and offset. Defaults\nto false.\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` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length`" }, { "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": "

A generalized version of all numeric read methods. Supports up to 48 bits of\naccuracy. For example:\n\n

\n
var b = new Buffer(6);\nb.writeUInt16LE(0x90ab, 0);\nb.writeUInt32LE(0x12345678, 2);\nb.readUIntLE(0, 6).toString(16);  // Specify 6 bytes (48 bits)\n// output: '1234567890ab'
\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" }, { "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` ", "name": "offset", "type": "Number", "desc": "`0 <= offset <= buf.length`" }, { "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": "

A generalized version of all numeric read methods. Supports up to 48 bits of\naccuracy. For example:\n\n

\n
var b = new Buffer(6);\nb.writeUInt16LE(0x90ab, 0);\nb.writeUInt32LE(0x12345678, 2);\nb.readUIntLE(0, 6).toString(16);  // Specify 6 bytes (48 bits)\n// output: '1234567890ab'
\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" }, { "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 using the specified\ncharacter set encoding. If encoding is undefined or null, then encoding\ndefaults to 'utf8'. The start and end parameters default to 0 and\nbuffer.length when undefined.\n\n

\n
buf = new Buffer(26);\nfor (var i = 0 ; i < 26 ; i++) {\n  buf[i] = i + 97; // 97 is ASCII a\n}\nbuf.toString('ascii'); // outputs: abcdefghijklmnopqrstuvwxyz\nbuf.toString('ascii',0,5); // outputs: abcde\nbuf.toString('utf8',0,5); // outputs: abcde\nbuf.toString(undefined,0,5); // encoding defaults to 'utf8', outputs abcde
\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. JSON.stringify\nimplicitly calls this function when stringifying 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// '{"type":"Buffer","data":[116,101,115,116]}'\n\nvar copy = JSON.parse(json, function(key, value) {\n    return value && value.type === 'Buffer'\n      ? new Buffer(value.data)\n      : value;\n  });\n\nconsole.log(copy);\n// <Buffer 74 65 73 74>
\n", "signatures": [ { "params": [] } ] }, { "textRaw": "buf.equals(otherBuffer)", "type": "method", "name": "equals", "signatures": [ { "params": [ { "textRaw": "`otherBuffer` {Buffer} ", "name": "otherBuffer", "type": "Buffer" } ] }, { "params": [ { "name": "otherBuffer" } ] } ], "desc": "

Returns a boolean of whether this and otherBuffer have the same\nbytes.\n\n

\n" }, { "textRaw": "buf.compare(otherBuffer)", "type": "method", "name": "compare", "signatures": [ { "params": [ { "textRaw": "`otherBuffer` {Buffer} ", "name": "otherBuffer", "type": "Buffer" } ] }, { "params": [ { "name": "otherBuffer" } ] } ], "desc": "

Returns a number indicating whether this comes before or after or is\nthe same as the otherBuffer in sort order.\n\n\n

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

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. If undefined the\ntargetStart and sourceStart parameters default to 0 while sourceEnd\ndefaults 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

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

\n
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.slice([start[, end]])", "type": "method", "name": "slice", "signatures": [ { "params": [ { "textRaw": "`start` Number, Optional, Default: 0 ", "name": "start", "desc": "Number, Optional, Default: 0" }, { "textRaw": "`end` Number, Optional, Default: `buffer.length` ", "name": "end", "desc": "Number, Optional, Default: `buffer.length`", "optional": true } ] }, { "params": [ { "name": "start" }, { "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. Negative indexes start from the end of the buffer.\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.indexOf(value[, byteOffset])", "type": "method", "name": "indexOf", "signatures": [ { "return": { "textRaw": "Return: Number ", "name": "return", "desc": "Number" }, "params": [ { "textRaw": "`value` String, Buffer or Number ", "name": "value", "desc": "String, Buffer or Number" }, { "textRaw": "`byteOffset` Number, Optional, Default: 0 ", "name": "byteOffset", "desc": "Number, Optional, Default: 0", "optional": true } ] }, { "params": [ { "name": "value" }, { "name": "byteOffset", "optional": true } ] } ], "desc": "

Operates similar to\nArray#indexOf().\nAccepts a String, Buffer or Number. Strings are interpreted as UTF8. Buffers\nwill use the entire buffer. So in order to compare a partial Buffer use\nBuffer#slice(). Numbers can range from 0 to 255.\n\n

\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, behavior is unspecified if value is not a 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, behavior is unspecified if value is not a 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" }, { "textRaw": "buffer.values()", "type": "method", "name": "values", "desc": "

Creates iterator for buffer values (bytes). This function is called automatically\nwhen buffer is used in a for..of statement.\n\n

\n", "signatures": [ { "params": [] } ] }, { "textRaw": "buffer.keys()", "type": "method", "name": "keys", "desc": "

Creates iterator for buffer keys (indices).\n\n

\n", "signatures": [ { "params": [] } ] }, { "textRaw": "buffer.entries()", "type": "method", "name": "entries", "desc": "

Creates iterator for [index, byte] arrays.\n\n

\n", "signatures": [ { "params": [] } ] } ], "signatures": [ { "params": [ { "textRaw": "`size` Number ", "name": "size", "desc": "Number" } ], "desc": "

Allocates a new buffer of size bytes. size must be less than\n1,073,741,824 bytes (1 GB) on 32 bits architectures or\n2,147,483,648 bytes (2 GB) on 64 bits architectures,\notherwise a RangeError is thrown.\n\n

\n

Unlike ArrayBuffers, the underlying memory for buffers is not initialized. So\nthe contents of a newly created Buffer are unknown and could contain\nsensitive data. Use buf.fill(0) to initialize a buffer to zeroes.\n\n

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

Allocates a new buffer of size bytes. size must be less than\n1,073,741,824 bytes (1 GB) on 32 bits architectures or\n2,147,483,648 bytes (2 GB) on 64 bits architectures,\notherwise a RangeError is thrown.\n\n

\n

Unlike ArrayBuffers, the underlying memory for buffers is not initialized. So\nthe contents of a newly created Buffer are unknown and could contain\nsensitive data. Use buf.fill(0) to initialize a buffer to zeroes.\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": "`buffer` {Buffer} ", "name": "buffer", "type": "Buffer" } ], "desc": "

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

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

Copies the passed buffer data onto a new Buffer instance.\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": "

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 and copy out the relevant bits.\n\n

\n
// need to keep around a few small chunks of memory\nvar store = [];\n\nsocket.on('readable', function() {\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

Though this should be used sparingly and only be a last resort after a developer\nhas actively observed undue memory retention in their applications.\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" } ], "modules": [ { "textRaw": "ES6 iteration", "name": "es6_iteration", "desc": "

Buffers can be iterated over using for..of syntax:\n\n

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

Additionally, buffer.values(), buffer.keys() and buffer.entries()\nmethods can be used to create iterators.\n\n

\n", "type": "module", "displayName": "ES6 iteration" } ], "type": "module", "displayName": "Buffer" } ] }