Buffer

js.lib.Uint8Arrayjs.node.buffer.Buffer (extern class)

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

See: https://nodejs.org/api/buffer.html#buffer_class_buffer

Static Members

poolSize: Int

This is the size (in bytes) of pre-allocated internal Buffer instances used for pooling. This value may be modified.

See: https://nodejs.org/api/buffer.html#buffer_class_property_buffer_poolsize

byteOffset: Int

When setting byteOffset in Buffer.from(ArrayBuffer, byteOffset, length) or sometimes when allocating a buffer smaller than Buffer.poolSize the buffer doesn't start from a zero offset on the underlying ArrayBuffer.

See: https://nodejs.org/api/buffer.html#buffer_buf_byteoffset

INSPECT_MAX_BYTES: Int

Default: 50

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

This is a property on the buffer module returned by require('buffer'), not on the Buffer global or a Buffer instance.

See: https://nodejs.org/api/buffer.html#buffer_buffer_inspect_max_bytes

kMaxLength: Int

An alias for buffer.constants.MAX_LENGTH.

This is a property on the buffer module returned by require('buffer'), not on the Buffer global or a Buffer instance.

See: https://nodejs.org/api/buffer.html#buffer_buffer_kmaxlength

constants: BufferConstants

buffer.constants is a property on the buffer module returned by require('buffer'), not on the Buffer global or a Buffer instance.

See: https://nodejs.org/api/buffer.html#buffer_buffer_constants

alloc(size: Int): Buffer

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

See: https://nodejs.org/api/buffer.html#buffer_class_method_buffer_alloc_size_fill_encoding
Name Type
size Int
Returns
Buffer

allocUnsafe(size: Int): Buffer

Allocates a new Buffer of size bytes. If size is larger than buffer.constants.MAX_LENGTH or smaller than 0, ERR_INVALID_OPT_VALUE is thrown. A zero-length Buffer is created if size is 0.

See: https://nodejs.org/api/buffer.html#buffer_class_method_buffer_allocunsafe_size
Name Type
size Int
Returns
Buffer

allocUnsafeSlow(size: Int): Buffer

Allocates a new Buffer of size bytes. If size is larger than buffer.constants.MAX_LENGTH or smaller than 0, ERR_INVALID_OPT_VALUE is thrown. A zero-length Buffer is created if size is 0.

See: https://nodejs.org/api/buffer.html#buffer_class_method_buffer_allocunsafeslow_size
Name Type
size Int
Returns
Buffer

byteLength(string: Buffer): Int

Returns the actual byte length of a string. This is not the same as String.prototype.length since that returns the number of characters in a string.

See: https://nodejs.org/api/buffer.html#buffer_class_method_buffer_bytelength_string_encoding
Name Type
string Buffer
Returns
Int

compareBuffers(buf1: js.lib.Uint8Array, buf2: js.lib.Uint8Array): Int

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

See: https://nodejs.org/api/buffer.html#buffer_class_method_buffer_compare_buf1_buf2
Name Type
buf1 js.lib.Uint8Array
buf2 js.lib.Uint8Array
Returns
Int

concat(list: Array<concat.T>, ?totalLength: Int): Buffer

Returns a new Buffer which is the result of concatenating all the Buffer instances in the list together.

See: https://nodejs.org/api/buffer.html#buffer_class_method_buffer_concat_list_totallength
Name Type Default
list Array<concat.T>
totalLength Int (optional)
Returns
Buffer

isBuffer(obj: Dynamic): Bool

Returns true if obj is a Buffer, false otherwise.

See: https://nodejs.org/api/buffer.html#buffer_class_method_buffer_isbuffer_obj
Name Type
obj Dynamic
Returns
Bool

isEncoding(encoding: String): Bool

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

See: https://nodejs.org/api/buffer.html#buffer_class_method_buffer_isencoding_encoding
Name Type
encoding String
Returns
Bool

transcode(source: js.lib.Uint8Array, fromEnc: String, toEnc: String): Buffer

Re-encodes the given Buffer or Uint8Array instance from one character encoding to another. Returns a new Buffer instance.

See: https://nodejs.org/api/buffer.html#buffer_buffer_transcode_source_fromenc_toenc
Name Type
source js.lib.Uint8Array
fromEnc String
toEnc String
Returns
Buffer

hxFromBytes(b: haxe.io.Bytes): Buffer

Create Buffer object from haxe.io.Bytes using the same underlying data storage. Any modifications done using the returned object will be reflected in given haxe.io.Bytes object.

Name Type
b haxe.io.Bytes
Returns
Buffer

Instance Members

compare(target: js.lib.Uint8Array, ?targetStart: Int, ?targetEnd: Int, ?sourceStart: Int, ?sourceEnd: Int): Int

Compares buf with target and returns a number indicating whether buf comes before, after, or is the same as target in sort order. Comparison is based on the actual sequence of bytes in each Buffer.

See: https://nodejs.org/api/buffer.html#buffer_buf_compare_target_targetstart_targetend_sourcestart_sourceend
Name Type Default
target js.lib.Uint8Array
targetStart Int (optional)
targetEnd Int (optional)
sourceStart Int (optional)
sourceEnd Int (optional)
Returns
Int

copy(target: js.lib.Uint8Array, ?targetStart: Int, ?sourceStart: Int, ?sourceEnd: Int): Void

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

See: https://nodejs.org/api/buffer.html#buffer_buf_copy_target_targetstart_sourcestart_sourceend
Name Type Default
target js.lib.Uint8Array
targetStart Int (optional)
sourceStart Int (optional)
sourceEnd Int (optional)

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

See: https://nodejs.org/api/buffer.html#buffer_buf_entries
Returns
js.node.Iterator

equals(otherBuffer: js.lib.Uint8Array): Bool

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

See: https://nodejs.org/api/buffer.html#buffer_buf_equals_otherbuffer
Name Type
otherBuffer js.lib.Uint8Array
Returns
Bool

fill(value: String, ?offset: Int, ?end: Int, ?encoding: String): Buffer

Fills buf with the specified value. If the offset and end are not given, the entire buf will be filled:

See: https://nodejs.org/api/buffer.html#buffer_buf_fill_value_offset_end_encoding
Name Type Default
value String
offset Int (optional)
end Int (optional)
encoding String (optional)
Returns
Buffer

includes(value: String, ?byteOffset: Int, ?encoding: String): Bool

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

See: https://nodejs.org/api/buffer.html#buffer_buf_includes_value_byteoffset_encoding
Name Type Default
value String
byteOffset Int (optional)
encoding String (optional)
Returns
Bool

indexOf(value: String, ?byteOffset: Int, ?encoding: String): Int

If value is:

  • a string, value is interpreted according to the character encoding in encoding.
  • a Buffer or Uint8Array, value will be used in its entirety. To compare a partial Buffer, use buf.slice().
  • a number, value will be interpreted as an unsigned 8-bit integer value between 0 and 255.
See: https://nodejs.org/api/buffer.html#buffer_buf_indexof_value_byteoffset_encoding
Name Type Default
value String
byteOffset Int (optional)
encoding String (optional)
Returns
Int

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

See: https://nodejs.org/api/buffer.html#buffer_buf_keys
Returns
js.node.Iterator

lastIndexOf(value: String, ?byteOffset: Int, ?encoding: String): Int

Identical to buf.indexOf(), except the last occurrence of value is found rather than the first occurrence.

See: https://nodejs.org/api/buffer.html#buffer_buf_lastindexof_value_byteoffset_encoding
Name Type Default
value String
byteOffset Int (optional)
encoding String (optional)
Returns
Int

readDoubleBE(?offset: Int): Float

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

See: https://nodejs.org/api/buffer.html#buffer_buf_readdoublebe_offset
Name Type Default
offset Int (optional)
Returns
Float

readDoubleLE(?offset: Int): Float

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

See: https://nodejs.org/api/buffer.html#buffer_buf_readdoublele_offset
Name Type Default
offset Int (optional)
Returns
Float

readFloatBE(?offset: Int): Float

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

See: https://nodejs.org/api/buffer.html#buffer_buf_readfloatbe_offset
Name Type Default
offset Int (optional)
Returns
Float

readFloatLE(?offset: Int): Float

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

See: https://nodejs.org/api/buffer.html#buffer_buf_readfloatle_offset
Name Type Default
offset Int (optional)
Returns
Float

readInt8(?offset: Int): Int

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

https://nodejs.org/api/buffer.html#buffer_buf_readint8_offset

Name Type Default
offset Int (optional)
Returns
Int

readInt16BE(?offset: Int): Int

Reads a signed 16-bit integer from buf at the specified offset with the specified endian format (readInt16BE() returns big endian, readInt16LE() returns little endian).

See: https://nodejs.org/api/buffer.html#buffer_buf_readint16be_offset
Name Type Default
offset Int (optional)
Returns
Int

readInt16LE(?offset: Int): Int

Reads a signed 16-bit integer from buf at the specified offset with the specified endian format (readInt16BE() returns big endian, readInt16LE() returns little endian).

See: https://nodejs.org/api/buffer.html#buffer_buf_readint16le_offset
Name Type Default
offset Int (optional)
Returns
Int

readInt32BE(?offset: Int): Int

Reads a signed 32-bit integer from buf at the specified offset with the specified endian format (readInt32BE() returns big endian, readInt32LE() returns little endian).

See: https://nodejs.org/api/buffer.html#buffer_buf_readint32be_offset
Name Type Default
offset Int (optional)
Returns
Int

readInt32LE(?offset: Int): Int

Reads a signed 32-bit integer from buf at the specified offset with the specified endian format (readInt32BE() returns big endian, readInt32LE() returns little endian).

See: https://nodejs.org/api/buffer.html#buffer_buf_readint32be_offset
Name Type Default
offset Int (optional)
Returns
Int

readIntBE(offset: Int, byteLength: Int): Int

Reads byteLength number of bytes from buf at the specified offset and interprets the result as a two's complement signed value. Supports up to 48 bits of accuracy.

See: https://nodejs.org/api/buffer.html#buffer_buf_readintbe_offset_bytelength
Name Type
offset Int
byteLength Int
Returns
Int

readIntLE(offset: Int, byteLength: Int): Int

Reads byteLength number of bytes from buf at the specified offset and interprets the result as a two's complement signed value. Supports up to 48 bits of accuracy.

See: https://nodejs.org/api/buffer.html#buffer_buf_readintle_offset_bytelength
Name Type
offset Int
byteLength Int
Returns
Int

readUInt8(?offset: Int): Int

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

See: https://nodejs.org/api/buffer.html#buffer_buf_readuint8_offset
Name Type Default
offset Int (optional)
Returns
Int

readUInt16BE(?offset: Int): Int

Reads an unsigned 16-bit integer from buf at the specified offset with specified endian format readUInt16BE() returns big endian, readUInt16LE() returns little endian).

See: https://nodejs.org/api/buffer.html#buffer_buf_readuint16be_offset
Name Type Default
offset Int (optional)
Returns
Int

readUInt16LE(?offset: Int): Int

Reads an unsigned 16-bit integer from buf at the specified offset with specified endian format (readUInt16BE() returns big endian, readUInt16LE() returns little endian).

See: https://nodejs.org/api/buffer.html#buffer_buf_readuint16le_offset
Name Type Default
offset Int (optional)
Returns
Int

readUInt32BE(?offset: Int): Int

Reads an unsigned 32-bit integer from buf at the specified offset with specified endian format (readUInt32BE() returns big endian, readUInt32LE() returns little endian).

See: https://nodejs.org/api/buffer.html#buffer_buf_readuint32be_offset
Name Type Default
offset Int (optional)
Returns
Int

readUInt32LE(?offset: Int): Int

Reads an unsigned 32-bit integer from buf at the specified offset with specified endian format (readUInt32BE() returns big endian, readUInt32LE() returns little endian).

See: https://nodejs.org/api/buffer.html#buffer_buf_readuint32be_offset
Name Type Default
offset Int (optional)
Returns
Int

subarray(?start: Int, ?end: Int): Buffer

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

See: https://nodejs.org/api/buffer.html#buffer_buf_subarray_start_end
Name Type Default
start Int (optional)
end Int (optional)
Returns
Buffer

slice(?start: Int, ?end: Int): Buffer

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

See: https://nodejs.org/api/buffer.html#buffer_buf_slice_start_end
Name Type Default
start Int (optional)
end Int (optional)
Returns
Buffer

swap16(): Buffer

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

See: https://nodejs.org/api/buffer.html#buffer_buf_swap16
Returns
Buffer

swap32(): Buffer

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

See: https://nodejs.org/api/buffer.html#buffer_buf_swap32
Returns
Buffer

swap64(): Buffer

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

See: https://nodejs.org/api/buffer.html#buffer_buf_swap64
Returns
Buffer

toJSON(): Dynamic

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

See: https://nodejs.org/api/buffer.html#buffer_buf_tojson
Returns
Dynamic

toString(): String

Decodes buf to a string according to the specified character encoding in encoding. start and end may be passed to decode only a subset of buf.

See: https://nodejs.org/api/buffer.html#buffer_buf_tostring_encoding_start_end
Returns
String

Creates and returns an iterator for buf values (bytes). This function is called automatically when a Buffer is used in a for..of statement.

See: https://nodejs.org/api/buffer.html#buffer_buf_values
Returns
js.node.Iterator

write(string: String, ?offset: Int, ?length: Int, ?encoding: String): Int

Writes string to buf at offset according to the character encoding in encoding. The length parameter is the number of bytes to write. If buf did not contain enough space to fit the entire string, only part of string will be written. However, partially encoded characters will not be written.

See: https://nodejs.org/api/buffer.html#buffer_buf_write_string_offset_length_encoding
Name Type Default
string String
offset Int (optional)
length Int (optional)
encoding String (optional)
Returns
Int

writeDoubleBE(value: Float, ?offset: Int): Void

Writes value to buf at the specified offset with specified endian format (writeDoubleBE() writes big endian, writeDoubleLE() writes little endian). value should be a valid 64-bit double. Behavior is undefined when value is anything other than a 64-bit double.

See: https://nodejs.org/api/buffer.html#buffer_buf_writedoublebe_value_offset
Name Type Default
value Float
offset Int (optional)

writeDoubleLE(value: Float, ?offset: Int): Void

Writes value to buf at the specified offset with specified endian format (writeDoubleBE() writes big endian, writeDoubleLE() writes little endian). value should be a valid 64-bit double. Behavior is undefined when value is anything other than a 64-bit double.

See: https://nodejs.org/api/buffer.html#buffer_buf_writedoublele_value_offset
Name Type Default
value Float
offset Int (optional)

writeFloatBE(value: Float, ?offset: Int): Void

Writes value to buf at the specified offset with specified endian format (writeFloatBE() writes big endian, writeFloatLE() writes little endian). value should be a valid 32-bit float. Behavior is undefined when value is anything other than a 32-bit float.

See: https://nodejs.org/api/buffer.html#buffer_buf_writefloatbe_value_offset
Name Type Default
value Float
offset Int (optional)

writeFloatLE(value: Float, ?offset: Int): Void

Writes value to buf at the specified offset with specified endian format (writeFloatBE() writes big endian, writeFloatLE() writes little endian). value should be a valid 32-bit float. Behavior is undefined when value is anything other than a 32-bit float.

See: https://nodejs.org/api/buffer.html#buffer_buf_writefloatle_value_offset
Name Type Default
value Float
offset Int (optional)

writeInt8(value: Int, ?offset: Int): Void

Writes value to buf at the specified offset. value should be a valid signed 8-bit integer. Behavior is undefined when value is anything other than a signed 8-bit integer.

See: https://nodejs.org/api/buffer.html#buffer_buf_writeint8_value_offset
Name Type Default
value Int
offset Int (optional)

writeInt16BE(value: Int, ?offset: Int): Void

Writes value to buf at the specified offset with specified endian format (writeInt16BE() writes big endian, writeInt16LE() writes little endian). value should be a valid signed 16-bit integer. Behavior is undefined when value is anything other than a signed 16-bit integer.

See: https://nodejs.org/api/buffer.html#buffer_buf_writeint16be_value_offset
Name Type Default
value Int
offset Int (optional)

writeInt16LE(value: Int, ?offset: Int): Void

Writes value to buf at the specified offset with specified endian format (writeInt16BE() writes big endian, writeInt16LE() writes little endian). value should be a valid signed 16-bit integer. Behavior is undefined when value is anything other than a signed 16-bit integer.

See: https://nodejs.org/api/buffer.html#buffer_buf_writeint16le_value_offset
Name Type Default
value Int
offset Int (optional)

writeInt32BE(value: Int, ?offset: Int): Void

Writes value to buf at the specified offset with specified endian format (writeInt32BE() writes big endian, writeInt32LE() writes little endian). value should be a valid signed 32-bit integer. Behavior is undefined when value is anything other than a signed 32-bit integer.

See: https://nodejs.org/api/buffer.html#buffer_buf_writeint32be_value_offset
Name Type Default
value Int
offset Int (optional)

writeInt32LE(value: Int, ?offset: Int): Void

Writes value to buf at the specified offset with specified endian format (writeInt32BE() writes big endian, writeInt32LE() writes little endian). value should be a valid signed 32-bit integer. Behavior is undefined when value is anything other than a signed 32-bit integer.

See: https://nodejs.org/api/buffer.html#buffer_buf_writeint32le_value_offset
Name Type Default
value Int
offset Int (optional)

writeIntBE(value: Int, offset: Int, byteLength: Int): Int

Writes byteLength bytes of value to buf at the specified offset. Supports up to 48 bits of accuracy. Behavior is undefined when value is anything other than a signed integer.

See: https://nodejs.org/api/buffer.html#buffer_buf_writeintbe_value_offset_bytelength
Name Type
value Int
offset Int
byteLength Int
Returns
Int

writeIntLE(value: Int, offset: Int, byteLength: Int): Int

Writes byteLength bytes of value to buf at the specified offset. Supports up to 48 bits of accuracy. Behavior is undefined when value is anything other than a signed integer.

See: https://nodejs.org/api/buffer.html#buffer_buf_writeintle_value_offset_bytelength
Name Type
value Int
offset Int
byteLength Int
Returns
Int

writeUInt8(value: Int, ?offset: Int): Void

Writes value to buf at the specified offset. value should be a valid unsigned 8-bit integer. Behavior is undefined when value is anything other than an unsigned 8-bit integer.

See: https://nodejs.org/api/buffer.html#buffer_buf_writeuint8_value_offset
Name Type Default
value Int
offset Int (optional)

writeUInt16BE(value: Int, ?offset: Int): Void

Writes value to buf at the specified offset with specified endian format (writeUInt16BE() writes big endian, writeUInt16LE() writes little endian). value should be a valid unsigned 16-bit integer. Behavior is undefined when value is anything other than an unsigned 16-bit integer.

See: https://nodejs.org/api/buffer.html#buffer_buf_writeuint16be_value_offset
Name Type Default
value Int
offset Int (optional)

writeUInt16LE(value: Int, ?offset: Int): Void

Writes value to buf at the specified offset with specified endian format (writeUInt16BE() writes big endian, writeUInt16LE() writes little endian). value should be a valid unsigned 16-bit integer. Behavior is undefined when value is anything other than an unsigned 16-bit integer.

See: https://nodejs.org/api/buffer.html#buffer_buf_writeuint16le_value_offset
Name Type Default
value Int
offset Int (optional)

writeUInt32BE(value: Int, ?offset: Int): Void

Writes value to buf at the specified offset with specified endian format (writeUInt32BE() writes big endian, writeUInt32LE() writes little endian). value should be a valid unsigned 32-bit integer. Behavior is undefined when value is anything other than an unsigned 32-bit integer.

See: https://nodejs.org/api/buffer.html#buffer_buf_writeuint32be_value_offset
Name Type Default
value Int
offset Int (optional)

writeUInt32LE(value: Int, ?offset: Int): Void

Writes value to buf at the specified offset with specified endian format (writeUInt32BE() writes big endian, writeUInt32LE() writes little endian). value should be a valid unsigned 32-bit integer. Behavior is undefined when value is anything other than an unsigned 32-bit integer.

See: https://nodejs.org/api/buffer.html#buffer_buf_writeuint32le_value_offset
Name Type Default
value Int
offset Int (optional)

hxToBytes(): haxe.io.Bytes

Create haxe.io.Bytes object that uses the same underlying data storage as this buffer. Any modifications done using the returned object will be reflected in the this buffer.

Returns
haxe.io.Bytes

new(string: String, ?encoding: String): Void

Allocates a new buffer.

See: https://nodejs.org/api/buffer.html#buffer_new_buffer_array, https://nodejs.org/api/buffer.html#buffer_new_buffer_arraybuffer_byteoffset_length, https://nodejs.org/api/buffer.html#buffer_new_buffer_buffer, https://nodejs.org/api/buffer.html#buffer_new_buffer_size, https://nodejs.org/api/buffer.html#buffer_new_buffer_string_encoding
Name Type Default
string String
encoding String (optional)

Metadata

Name Parameters
:jsRequire "buffer", "Buffer"