Buffer

sealed external class Buffer : Uint8Array(source)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val buffer: ArrayBufferLike
Link copied to clipboard
open override val byteLength: Int
Link copied to clipboard
open override val byteOffset: Int
Link copied to clipboard
Link copied to clipboard
open override val length: Int

Functions

Link copied to clipboard
fun at(index: Int): Byte?
Link copied to clipboard
fun compare(target: Uint8Array, targetStart: Number = definedExternally, targetEnd: Number = definedExternally, sourceStart: Number = definedExternally, sourceEnd: Number = definedExternally): Int

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

Link copied to clipboard
fun copy(target: Uint8Array, targetStart: Number = definedExternally, sourceStart: Number = definedExternally, sourceEnd: Number = definedExternally): Double

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

Link copied to clipboard
fun copyWithin(target: Int, start: Int, end: Int): Uint8Array
Link copied to clipboard
open override fun entries(): JsIterator<JsTuple2<Int, Byte>>
Link copied to clipboard
fun equals(otherBuffer: Uint8Array): Boolean

Returns true if both buf and otherBuffer have exactly the same bytes,false otherwise. Equivalent to buf.compare(otherBuffer) === 0.

Link copied to clipboard
fun every(predicate: (value: Byte) -> Unit): Boolean
Link copied to clipboard
fun fill(value: Byte, start: Int, end: Int): Uint8Array

fun fill(value: Uint8Array, offset: Number = definedExternally, end: Number = definedExternally, encoding: BufferEncoding = definedExternally)
fun fill(value: Double, offset: Number = definedExternally, end: Number = definedExternally, encoding: BufferEncoding = definedExternally)
fun fill(value: String, offset: Number = definedExternally, end: Number = definedExternally, encoding: BufferEncoding = definedExternally)

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

Link copied to clipboard
fun filter(predicate: (value: Byte) -> Boolean): Uint8Array
Link copied to clipboard
fun find(predicate: (value: Byte) -> Boolean): Byte?
Link copied to clipboard
fun findIndex(predicate: (value: Byte) -> Boolean): Int
Link copied to clipboard
open override fun forEach(action: (item: Byte) -> Unit)
Link copied to clipboard
open operator fun get(index: Int): Byte
open operator fun get(key: Symbol.iterator): () -> JsIterator<Byte>
Link copied to clipboard
fun includes(searchElement: Byte, fromIndex: Int): Boolean

fun includes(value: Double, byteOffset: Number = definedExternally, encoding: BufferEncoding = definedExternally): Boolean
fun includes(value: String, byteOffset: Number = definedExternally, encoding: BufferEncoding = definedExternally): Boolean
fun includes(value: Buffer, byteOffset: Number = definedExternally, encoding: BufferEncoding = definedExternally): Boolean

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

Link copied to clipboard
fun indexOf(searchElement: Byte, fromIndex: Int): Int

fun indexOf(value: Uint8Array, byteOffset: Number = definedExternally, encoding: BufferEncoding = definedExternally): Double
fun indexOf(value: Double, byteOffset: Number = definedExternally, encoding: BufferEncoding = definedExternally): Double
fun indexOf(value: String, byteOffset: Number = definedExternally, encoding: BufferEncoding = definedExternally): Double

If value is:

Link copied to clipboard
open inline operator fun iterator(): Iterator<Byte>
Link copied to clipboard
fun join(separator: String): String
Link copied to clipboard
open override fun keys(): JsIterator<Int>
Link copied to clipboard
fun lastIndexOf(searchElement: Byte, fromIndex: Int): Int

fun lastIndexOf(value: Uint8Array, byteOffset: Number = definedExternally, encoding: BufferEncoding = definedExternally): Double
fun lastIndexOf(value: Double, byteOffset: Number = definedExternally, encoding: BufferEncoding = definedExternally): Double
fun lastIndexOf(value: String, byteOffset: Number = definedExternally, encoding: BufferEncoding = definedExternally): Double

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

Link copied to clipboard
fun map(transform: (value: Byte) -> Byte): Uint8Array
Link copied to clipboard
fun readBigInt64BE(offset: Number = definedExternally): BigInt

Reads a signed, big-endian 64-bit integer from buf at the specified offset.

Link copied to clipboard
fun readBigInt64LE(offset: Number = definedExternally): BigInt

Reads a signed, little-endian 64-bit integer from buf at the specifiedoffset.

Link copied to clipboard
fun readBigUInt64BE(offset: Number = definedExternally): BigInt

Reads an unsigned, big-endian 64-bit integer from buf at the specifiedoffset.

Link copied to clipboard
fun readBigUint64BE(offset: Number = definedExternally): BigInt
Link copied to clipboard
fun readBigUInt64LE(offset: Number = definedExternally): BigInt

Reads an unsigned, little-endian 64-bit integer from buf at the specifiedoffset.

Link copied to clipboard
fun readBigUint64LE(offset: Number = definedExternally): BigInt
Link copied to clipboard
fun readDoubleBE(offset: Number = definedExternally): Double

Reads a 64-bit, big-endian double from buf at the specified offset.

Link copied to clipboard
fun readDoubleLE(offset: Number = definedExternally): Double

Reads a 64-bit, little-endian double from buf at the specified offset.

Link copied to clipboard
fun readFloatBE(offset: Number = definedExternally): Double

Reads a 32-bit, big-endian float from buf at the specified offset.

Link copied to clipboard
fun readFloatLE(offset: Number = definedExternally): Double

Reads a 32-bit, little-endian float from buf at the specified offset.

Link copied to clipboard
fun readInt16BE(offset: Number = definedExternally): Double

Reads a signed, big-endian 16-bit integer from buf at the specified offset.

Link copied to clipboard
fun readInt16LE(offset: Number = definedExternally): Double

Reads a signed, little-endian 16-bit integer from buf at the specifiedoffset.

Link copied to clipboard
fun readInt32BE(offset: Number = definedExternally): Double

Reads a signed, big-endian 32-bit integer from buf at the specified offset.

Link copied to clipboard
fun readInt32LE(offset: Number = definedExternally): Double

Reads a signed, little-endian 32-bit integer from buf at the specifiedoffset.

Link copied to clipboard
fun readInt8(offset: Number = definedExternally): Double

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

Link copied to clipboard
fun readIntBE(offset: Number, byteLength: Number): Double

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

Link copied to clipboard
fun readIntLE(offset: Number, byteLength: Number): Double

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

Link copied to clipboard
fun readUInt16BE(offset: Number = definedExternally): Double

Reads an unsigned, big-endian 16-bit integer from buf at the specifiedoffset.

Link copied to clipboard
fun readUint16BE(offset: Number = definedExternally): Double
Link copied to clipboard
fun readUInt16LE(offset: Number = definedExternally): Double

Reads an unsigned, little-endian 16-bit integer from buf at the specified offset.

Link copied to clipboard
fun readUint16LE(offset: Number = definedExternally): Double
Link copied to clipboard
fun readUInt32BE(offset: Number = definedExternally): Double

Reads an unsigned, big-endian 32-bit integer from buf at the specifiedoffset.

Link copied to clipboard
fun readUint32BE(offset: Number = definedExternally): Double
Link copied to clipboard
fun readUInt32LE(offset: Number = definedExternally): Double

Reads an unsigned, little-endian 32-bit integer from buf at the specifiedoffset.

Link copied to clipboard
fun readUint32LE(offset: Number = definedExternally): Double
Link copied to clipboard
fun readUInt8(offset: Number = definedExternally): Double

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

Link copied to clipboard
fun readUint8(offset: Number = definedExternally): Double
Link copied to clipboard
fun readUIntBE(offset: Number, byteLength: Number): Double

Reads byteLength number of bytes from buf at the specified offset and interprets the result as an unsigned big-endian integer supporting up to 48 bits of accuracy.

Link copied to clipboard
fun readUintBE(offset: Number, byteLength: Number): Double
Link copied to clipboard
fun readUIntLE(offset: Number, byteLength: Number): Double

Reads byteLength number of bytes from buf at the specified offset and interprets the result as an unsigned, little-endian integer supporting up to 48 bits of accuracy.

Link copied to clipboard
fun readUintLE(offset: Number, byteLength: Number): Double
Link copied to clipboard
Link copied to clipboard
open operator fun set(index: Int, value: Byte)
fun set(array: Uint8Array, offset: Int)
fun set(array: ReadonlyArray<Byte>, offset: Int)
Link copied to clipboard
fun slice(start: Int, end: Int): Uint8Array

fun slice(start: Number = definedExternally, end: Number = definedExternally): Buffer

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

Link copied to clipboard
fun some(predicate: (value: Byte) -> Boolean): Boolean
Link copied to clipboard
fun sort(comparison: (a: Byte, b: Byte) -> Int): Uint8Array
Link copied to clipboard
fun subarray(start: Int, end: Int): Uint8Array

fun subarray(start: Number = definedExternally, end: Number = definedExternally): Buffer

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

Link copied to clipboard
fun 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.

Link copied to clipboard
fun 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.

Link copied to clipboard
fun 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.

Link copied to clipboard
inline fun toByteArray(): ByteArray
Link copied to clipboard

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

Link copied to clipboard
Link copied to clipboard
fun toString(encoding: BufferEncoding = definedExternally, start: Number = definedExternally, end: Number = definedExternally): String

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

Link copied to clipboard
inline fun toUByteArray(): UByteArray
Link copied to clipboard
Link copied to clipboard
open override fun values(): JsIterator<Byte>
Link copied to clipboard
fun write(string: String, encoding: BufferEncoding = definedExternally): Double

Writes string to buf at offset according to the character encoding inencoding. 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.

fun write(string: String, offset: Number, encoding: BufferEncoding = definedExternally): Double
fun write(string: String, offset: Number, length: Number, encoding: BufferEncoding = definedExternally): Double
Link copied to clipboard
fun writeBigInt64BE(value: BigInt, offset: Number = definedExternally): Double

Writes value to buf at the specified offset as big-endian.

Link copied to clipboard
fun writeBigInt64LE(value: BigInt, offset: Number = definedExternally): Double

Writes value to buf at the specified offset as little-endian.

Link copied to clipboard
fun writeBigUInt64BE(value: BigInt, offset: Number = definedExternally): Double

Writes value to buf at the specified offset as big-endian.

Link copied to clipboard
fun writeBigUint64BE(value: BigInt, offset: Number = definedExternally): Double
Link copied to clipboard
fun writeBigUInt64LE(value: BigInt, offset: Number = definedExternally): Double

Writes value to buf at the specified offset as little-endian

Link copied to clipboard
fun writeBigUint64LE(value: BigInt, offset: Number = definedExternally): Double
Link copied to clipboard
fun writeDoubleBE(value: Number, offset: Number = definedExternally): Double

Writes value to buf at the specified offset as big-endian. The value must be a JavaScript number. Behavior is undefined when value is anything other than a JavaScript number.

Link copied to clipboard
fun writeDoubleLE(value: Number, offset: Number = definedExternally): Double

Writes value to buf at the specified offset as little-endian. The value must be a JavaScript number. Behavior is undefined when value is anything other than a JavaScript number.

Link copied to clipboard
fun writeFloatBE(value: Number, offset: Number = definedExternally): Double

Writes value to buf at the specified offset as big-endian. Behavior is undefined when value is anything other than a JavaScript number.

Link copied to clipboard
fun writeFloatLE(value: Number, offset: Number = definedExternally): Double

Writes value to buf at the specified offset as little-endian. Behavior is undefined when value is anything other than a JavaScript number.

Link copied to clipboard
fun writeInt16BE(value: Number, offset: Number = definedExternally): Double

Writes value to buf at the specified offset as big-endian. The value must be a valid signed 16-bit integer. Behavior is undefined when value is anything other than a signed 16-bit integer.

Link copied to clipboard
fun writeInt16LE(value: Number, offset: Number = definedExternally): Double

Writes value to buf at the specified offset as little-endian. The value must be a valid signed 16-bit integer. Behavior is undefined when value is anything other than a signed 16-bit integer.

Link copied to clipboard
fun writeInt32BE(value: Number, offset: Number = definedExternally): Double

Writes value to buf at the specified offset as big-endian. The value must be a valid signed 32-bit integer. Behavior is undefined when value is anything other than a signed 32-bit integer.

Link copied to clipboard
fun writeInt32LE(value: Number, offset: Number = definedExternally): Double

Writes value to buf at the specified offset as little-endian. The value must be a valid signed 32-bit integer. Behavior is undefined when value is anything other than a signed 32-bit integer.

Link copied to clipboard
fun writeInt8(value: Number, offset: Number = definedExternally): Double

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

Link copied to clipboard
fun writeIntBE(value: Number, offset: Number, byteLength: Number): Double

Writes byteLength bytes of value to buf at the specified offsetas big-endian. Supports up to 48 bits of accuracy. Behavior is undefined whenvalue is anything other than a signed integer.

Link copied to clipboard
fun writeIntLE(value: Number, offset: Number, byteLength: Number): Double

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

Link copied to clipboard
fun writeUInt16BE(value: Number, offset: Number = definedExternally): Double

Writes value to buf at the specified offset as big-endian. The value must be a valid unsigned 16-bit integer. Behavior is undefined when valueis anything other than an unsigned 16-bit integer.

Link copied to clipboard
fun writeUint16BE(value: Number, offset: Number = definedExternally): Double
Link copied to clipboard
fun writeUInt16LE(value: Number, offset: Number = definedExternally): Double

Writes value to buf at the specified offset as little-endian. The value must be a valid unsigned 16-bit integer. Behavior is undefined when value is anything other than an unsigned 16-bit integer.

Link copied to clipboard
fun writeUint16LE(value: Number, offset: Number = definedExternally): Double
Link copied to clipboard
fun writeUInt32BE(value: Number, offset: Number = definedExternally): Double

Writes value to buf at the specified offset as big-endian. The value must be a valid unsigned 32-bit integer. Behavior is undefined when valueis anything other than an unsigned 32-bit integer.

Link copied to clipboard
fun writeUint32BE(value: Number, offset: Number = definedExternally): Double
Link copied to clipboard
fun writeUInt32LE(value: Number, offset: Number = definedExternally): Double

Writes value to buf at the specified offset as little-endian. The value must be a valid unsigned 32-bit integer. Behavior is undefined when value is anything other than an unsigned 32-bit integer.

Link copied to clipboard
fun writeUint32LE(value: Number, offset: Number = definedExternally): Double
Link copied to clipboard
fun writeUInt8(value: Number, offset: Number = definedExternally): Double

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

Link copied to clipboard
fun writeUint8(value: Number, offset: Number = definedExternally): Double
Link copied to clipboard
fun writeUIntBE(value: Number, offset: Number, byteLength: Number): Double

Writes byteLength bytes of value to buf at the specified offsetas big-endian. Supports up to 48 bits of accuracy. Behavior is undefined when value is anything other than an unsigned integer.

Link copied to clipboard
fun writeUintBE(value: Number, offset: Number, byteLength: Number): Double
Link copied to clipboard
fun writeUIntLE(value: Number, offset: Number, byteLength: Number): Double

Writes byteLength bytes of value to buf at the specified offsetas little-endian. Supports up to 48 bits of accuracy. Behavior is undefined when value is anything other than an unsigned integer.

Link copied to clipboard
fun writeUintLE(value: Number, offset: Number, byteLength: Number): Double