buffer.length

buf.length <Number> Returns the amount of memory allocated for the Buffer in number of bytes. Note that this does not necessarily reflect the amount of usable data within the Buffer. For instance, in the example below, a Buffer with 1234 bytes is allocated, but only 11 ASCII bytes are written. const buf = Buffer.allocUnsafe(1234); console.log(buf.length); // Prints: 1234 buf.write('some string', 0, 'ascii'); console.log(buf.length); // Prints: 1234 While the length property is no

buffer.keys()

buf.keys() Return: <Iterator> Creates and returns an iterator of Buffer keys (indices). const buf = Buffer.from('buffer'); for (var key of buf.keys()) { console.log(key); } // prints: // 0 // 1 // 2 // 3 // 4 // 5

Buffer.isEncoding()

Class Method: Buffer.isEncoding(encoding) encoding <String> The encoding string to test Return: <Boolean> Returns true if the encoding is a valid encoding argument, or false otherwise.

Buffer.isBuffer()

Class Method: Buffer.isBuffer(obj) obj <Object> Return: <Boolean> Returns 'true' if obj is a Buffer.

buffer.INSPECT_MAX_BYTES

buffer.INSPECT_MAX_BYTES <Number> Default: 50 Returns the maximum number of bytes that will be returned when buffer.inspect() is called. This can be overridden by user modules. See util.inspect() for more details on buffer.inspect() behavior. Note that this is a property on the buffer module as returned by require('buffer'), not on the Buffer global or a Buffer instance.

buffer.indexOf()

buf.indexOf(value[, byteOffset][, encoding]) value <String> | <Buffer> | <Number> byteOffset <Number> Default: 0 encoding <String> Default: 'utf8' Return: <Number> Operates similar to Array#indexOf() in that it returns either the starting index position of value in Buffer or -1 if the Buffer does not contain value. The value can be a String, Buffer or Number. Strings are by default interpreted as UTF8. Buffers will use the entire Buffer (to compare a

buffer.includes()

buf.includes(value[, byteOffset][, encoding]) value <String> | <Buffer> | <Number> byteOffset <Number> Default: 0 encoding <String> Default: 'utf8' Return: <Boolean> Operates similar to Array#includes(). The value can be a String, Buffer or Number. Strings are interpreted as UTF8 unless overridden with the encoding argument. Buffers will use the entire Buffer (to compare a partial Buffer use buf.slice()). Numbers can range from 0 to 255. The byteOffs

Buffer.from()

Class Method: Buffer.from(array) array <Array> Allocates a new Buffer using an array of octets. const buf = Buffer.from([0x62,0x75,0x66,0x66,0x65,0x72]); // creates a new Buffer containing ASCII bytes // ['b','u','f','f','e','r'] A TypeError will be thrown if array is not an Array.

buffer.fill()

buf.fill(value[, offset[, end]][, encoding]) value <String> | <Buffer> | <Number> offset <Number> Default: 0 end <Number> Default: buf.length encoding <String> Default: 'utf8' Return: <Buffer> Fills the Buffer with the specified value. If the offset (defaults to 0) and end (defaults to buf.length) are not given the entire buffer will be filled. The method returns a reference to the Buffer, so calls can be chained. This is meant as a small simp

buffer.equals()

buf.equals(otherBuffer) otherBuffer <Buffer> Return: <Boolean> Returns a boolean indicating whether this and otherBuffer have exactly the same bytes. const buf1 = Buffer.from('ABC'); const buf2 = Buffer.from('414243', 'hex'); const buf3 = Buffer.from('ABCD'); console.log(buf1.equals(buf2)); // Prints: true console.log(buf1.equals(buf3)); // Prints: false