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

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

See also:

staticread onlykMaxLength: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 also:

staticpoolSize:Int

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

See also:

Static methods

@:has_untypedstaticinline_byteLength(string:String, ?encoding:String):Int

Deprecated: "In haxe 3.3+, use Buffer.byteLength instead!"

staticalloc(size:Int):Buffer

staticalloc(size:Int, fill:String, ?encoding:String):Buffer

staticalloc(size:Int, fill:Uint8Array):Buffer

staticalloc(size:Int, fill:Int):Buffer

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

See also:

staticallocUnsafe(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 also:

staticallocUnsafeSlow(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 also:

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:

@:native("compare")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

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

See also:

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

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

See also:

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

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

See also:

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

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

indexOf(value:Uint8Array, ?byteOffset:Int):Int

indexOf(value:Int, ?byteOffset:Int):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 also:

keys():Iterator<Int>

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

See also:

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:

Inherited Variables

Defined by Uint8Array

@:native("BYTES_PER_ELEMENT")finalBYTES_PER_ELEMENT_:Int

Returns a number value of the element size.

finalbuffer:ArrayBuffer

Returns the ArrayBuffer referenced by the Uint8Array Fixed at construction time and thus read only.

finalbyteLength:Int

Returns the length (in bytes) of the Uint8Array from the start of its ArrayBuffer. Fixed at construction time and thus read only.

finalbyteOffset:Int

Returns the offset (in bytes) of the Uint8Array from the start of its ArrayBuffer. Fixed at construction time and thus read only.

finallength:Int

Returns the number of elements hold in the Uint8Array. Fixed at construction time and thus read only.

Inherited Methods

Defined by Uint8Array

copyWithin(target:Int, start:Int, ?end:Int):Uint8Array

Copies a sequence of array elements within the array. See also Array.prototype.copyWithin().

every(callback:(currentValue:Int, index:Int, array:Uint8Array) ‑> Bool, ?thisArg:Any):Bool

every(callback:(currentValue:Int) ‑> Bool, ?thisArg:Any):Bool

every(callback:(currentValue:Int, index:Int) ‑> Bool, ?thisArg:Any):Bool

Tests whether all elements in the array pass the test provided by a function. See also Array.prototype.every().

filter(callback:(element:Int, index:Int, array:Uint8Array) ‑> Bool, ?thisArg:Any):Uint8Array

filter(callback:(element:Int) ‑> Bool, ?thisArg:Any):Uint8Array

filter(callback:(element:Int, index:Int) ‑> Bool, ?thisArg:Any):Uint8Array

Creates a new array with all of the elements of this array for which the provided filtering function returns true. See also Array.prototype.filter().

find(callback:(element:Int, index:Int, array:Uint8Array) ‑> Bool, ?thisArg:Any):Null<Int>

find(callback:(element:Int) ‑> Bool, ?thisArg:Any):Null<Int>

find(callback:(element:Int, index:Int) ‑> Bool, ?thisArg:Any):Null<Int>

Returns the found value in the array, if an element in the array satisfies the provided testing function or undefined if not found. See also Array.prototype.find().

findIndex(callback:(element:Int, index:Int, array:Uint8Array) ‑> Bool, ?thisArg:Any):Int

findIndex(callback:(element:Int) ‑> Bool, ?thisArg:Any):Int

findIndex(callback:(element:Int, index:Int) ‑> Bool, ?thisArg:Any):Int

Returns the found index in the array, if an element in the array satisfies the provided testing function or -1 if not found. See also Array.prototype.findIndex().

forEach(callback:(element:Int, index:Int, array:Uint8Array) ‑> Void, ?thisArg:Any):Void

forEach(callback:(element:Int) ‑> Void, ?thisArg:Any):Void

forEach(callback:(element:Int, index:Int) ‑> Void, ?thisArg:Any):Void

Calls a function for each element in the array. See also Array.prototype.forEach().

join(?separator:String):String

Joins all elements of an array into a string. See also Array.prototype.join().

map(callback:(element:Int, index:Int, array:Uint8Array) ‑> Int, ?thisArg:Any):Uint8Array

map(callback:(element:Int) ‑> Int, ?thisArg:Any):Uint8Array

map(callback:(element:Int, index:Int) ‑> Int, ?thisArg:Any):Uint8Array

Creates a new array with the results of calling a provided function on every element in this array. See also Array.prototype.map().

reduce<T>(callback:(previousValue:T, currentValue:Int, index:Int, array:Uint8Array) ‑> T, initialValue:T):T

reduce<T>(callback:(previousValue:T, currentValue:Int) ‑> T, initialValue:T):T

reduce<T>(callback:(previousValue:T, currentValue:Int, index:Int) ‑> T, initialValue:T):T

reduce(callbackfn:(previousValue:Int, currentValue:Int) ‑> Int):Int

reduce(callbackfn:(previousValue:Int, currentValue:Int, index:Int) ‑> Int):Int

reduce(callbackfn:(previousValue:Int, currentValue:Int, index:Int, array:Uint8Array) ‑> Int):Int

Apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value. See also Array.prototype.reduce().

reduceRight<T>(callback:(previousValue:T, currentValue:Int, index:Int, array:Uint8Array) ‑> T, initialValue:T):T

reduceRight<T>(callback:(previousValue:T, currentValue:Int) ‑> T, initialValue:T):T

reduceRight<T>(callback:(previousValue:T, currentValue:Int, index:Int) ‑> T, initialValue:T):T

reduceRight(callbackfn:(previousValue:Int, currentValue:Int) ‑> Int):Int

reduceRight(callbackfn:(previousValue:Int, currentValue:Int, index:Int) ‑> Int):Int

reduceRight(callbackfn:(previousValue:Int, currentValue:Int, index:Int, array:Uint8Array) ‑> Int):Int

Apply a function against an accumulator and each value of the array (from right-to-left) as to reduce it to a single value. See also Array.prototype.reduceRight().

reverse():Uint8Array

Reverses the order of the elements of an array — the first becomes the last, and the last becomes the first. See also Array.prototype.reverse().

set(array:Array<Int>, ?offset:Int):Void

set(array:Int8Array, ?offset:Int):Void

set(array:Uint8Array, ?offset:Int):Void

set(array:Uint8ClampedArray, ?offset:Int):Void

set(array:Int16Array, ?offset:Int):Void

set(array:Uint16Array, ?offset:Int):Void

set(array:Int32Array, ?offset:Int):Void

set(array:Uint32Array, ?offset:Int):Void

set(array:Float32Array, ?offset:Int):Void

set(array:Float64Array, ?offset:Int):Void

Stores multiple values in the typed array, reading input values from a specified array.

some(callback:(element:Int, index:Int, array:Uint8Array) ‑> Bool, ?thisArg:Any):Bool

some(callback:(element:Int) ‑> Bool, ?thisArg:Any):Bool

some(callback:(element:Int, index:Int) ‑> Bool, ?thisArg:Any):Bool

Returns true if at least one element in this array satisfies the provided testing function. See also Array.prototype.some().

sort(?compareFn:(x:Int, y:Int) ‑> Int):Uint8Array

Sorts the elements of an array in place and returns the array. See also Array.prototype.sort().

toLocaleString(?locales:String, ?options:Null<NumberFormatOptions>):String

Returns a string representing the array and its elements. See also Array.prototype.toString().