The Buffer
class is a global type for dealing with binary data directly. It can be constructed in a variety of ways.
See also:
Static variables
staticINSPECT_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 also:
staticread onlybyteOffset: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 also:
staticread onlyconstants:BufferConstants
staticread onlykMaxLength:Int
Static methods
staticinline_byteLength(string:String, ?encoding:String):Int
staticalloc(size:Int):Buffer
staticalloc(size:Int, fill:String, ?encoding:String):Buffer
staticalloc(size:Int, fill:Uint8Array):Buffer
staticalloc(size:Int, fill:Int):Buffer
staticallocUnsafe(size:Int):Buffer
staticallocUnsafeSlow(size:Int):Buffer
staticbyteLength(string:Buffer):Int
staticbyteLength(string:String, ?encoding:String):Int
staticbyteLength(string:ArrayBufferView):Int
staticbyteLength(string:ArrayBuffer):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 also:
staticcompareBuffers(buf1:Uint8Array, buf2: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 also:
staticconcat<T>(list:Array<T>, ?totalLength:Int):Buffer
staticfrom(string:String, ?encoding:String):Buffer
staticfrom(array:Array<Int>):Buffer
staticfrom(arrayBuffer:ArrayBuffer, ?byteOffset:Int, ?length:Int):Buffer
staticfrom(buffer:Uint8Array):Buffer
staticfrom(object:{}, ?offset:Int, ?length:Int):Buffer
staticfrom(object:{}, ?encoding:String, ?length:Int):Buffer
staticinlinehxFromBytes(b: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.
staticisEncoding(encoding:String):Bool
staticinlinetranscode(source: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 also:
Constructor
Methods
compare(target:Uint8Array, ?targetStart:Int, ?targetEnd:Int, ?sourceStart:Int, ?sourceEnd:Int):Int
compare(target:Uint8Array):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 also:
copy(target:Uint8Array, ?targetStart:Int, ?sourceStart:Int, ?sourceEnd:Int):Void
copy(target:Uint8Array):Void
Copies data from a region of buf
to a region in target
even if the target
memory region overlaps with buf
.
See also:
entries():Iterator<KeyValue<Int, Int>>
Creates and returns an iterator of [index, byte]
pairs from the contents of buf
.
See also:
equals(otherBuffer:Uint8Array):Bool
fill(value:String, ?offset:Int, ?end:Int, ?encoding:String):Buffer
fill(value:Uint8Array, ?offset:Int, ?end:Int):Buffer
fill(value:Int, ?offset:Int, ?end:Int):Buffer
Fills buf
with the specified value
. If the offset
and end
are not given, the entire buf
will be filled:
See also:
inlinehxToBytes():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.
includes(value:String, ?byteOffset:Int, ?encoding:String):Bool
includes(value:Uint8Array, ?byteOffset:Int):Bool
includes(value:Int, ?byteOffset:Int):Bool
Equivalent to buf.indexOf() !== -1
.
See also:
indexOf(value:String, ?byteOffset:Int, ?encoding:String):Int
indexOf(value:Uint8Array, ?byteOffset:Int):Int
indexOf(value:Int, ?byteOffset:Int):Int
lastIndexOf(value:String, ?byteOffset:Int, ?encoding:String):Int
lastIndexOf(value:Uint8Array, ?byteOffset:Int):Int
lastIndexOf(value:Int, ?byteOffset:Int):Int
Identical to buf.indexOf()
, except the last occurrence of value
is found
rather than the first occurrence.
See also:
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 also:
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 also:
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 also:
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 also:
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 also:
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 also:
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 also:
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 also:
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
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 also:
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 also:
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 also:
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 also:
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 also:
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 also:
readUInt8(?offset:Int):Int
Reads an unsigned 8-bit integer from buf
at the specified offset
.
See also:
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 also:
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 also:
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 also:
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 also:
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 also:
toJSON():Dynamic
Returns a JSON representation of buf
. JSON.stringify()
implicitly calls
this function when stringifying a Buffer
instance.
See also:
toString():String
toString(?encoding:String, ?start:Int, ?end:Int):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 also:
values():Iterator<Int>
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 also:
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 also:
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 also:
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 also:
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 also:
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 also:
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 also:
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 also:
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 also:
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 also:
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 also:
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 also:
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 also:
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 also:
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 also:
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 also:
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 also:
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 also: