Buffer
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
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
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
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
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
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
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
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
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
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
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
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 true
if obj
is a Buffer
, false
otherwise.
See: https://nodejs.org/api/buffer.html#buffer_class_method_buffer_isbuffer_obj
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
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
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.
Instance Members
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) |
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
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 true
if both buf
and otherBuffer
have exactly the same bytes, false
otherwise.
See: https://nodejs.org/api/buffer.html#buffer_buf_equals_otherbuffer
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) |
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) |
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) |
Creates and returns an iterator of buf
keys (indices).
See: https://nodejs.org/api/buffer.html#buffer_buf_keys
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) |
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) |
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) |
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) |
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) |
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) |
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) |
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) |
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) |
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) |
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 |
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 |
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) |
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) |
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) |
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) |
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 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 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) |
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
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
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 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
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
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
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) |
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) |
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) |
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) |
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) |
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) |
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) |
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) |
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) |
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) |
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 |
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 |
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) |
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) |
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) |
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) |
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) |
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.
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 |
Parameters |
:jsRequire |
"buffer", "Buffer" |