Companion

Properties

Link copied to clipboard

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

Functions

Link copied to clipboard
fun alloc(size: Number): Buffer
fun alloc(size: Number, fill: Uint8Array<*> = definedExternally, encoding: BufferEncoding = definedExternally): Buffer
fun alloc(size: Number, fill: Double = definedExternally, encoding: BufferEncoding = definedExternally): Buffer
fun alloc(size: Number, fill: String = definedExternally, encoding: BufferEncoding = definedExternally): Buffer

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

Link copied to clipboard

Allocates a new Buffer of size bytes. If size is larger than {@link constants.MAX_LENGTH} or smaller than 0, ERR_OUT_OF_RANGE is thrown.

Link copied to clipboard

Allocates a new Buffer of size bytes. If size is larger than {@link constants.MAX_LENGTH} or smaller than 0, ERR_OUT_OF_RANGE is thrown. A zero-length Buffer is created if size is 0.

Link copied to clipboard
fun byteLength(string: ArrayBuffer, encoding: BufferEncoding = definedExternally): Double
fun byteLength(string: ArrayBufferView<*>, encoding: BufferEncoding = definedExternally): Double
fun byteLength(string: SharedArrayBuffer, encoding: BufferEncoding = definedExternally): Double
fun byteLength(string: String, encoding: BufferEncoding = definedExternally): Double
fun byteLength(string: Buffer, encoding: BufferEncoding = definedExternally): Double

Returns the byte length of a string when encoded using encoding. This is not the same as String.prototype.length, which does not account for the encoding that is used to convert the string into bytes.

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

Link copied to clipboard
fun concat(list: ReadonlyArray<Uint8Array<*>>, totalLength: Number = definedExternally): Buffer

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

Link copied to clipboard
fun copyBytesFrom(view: TypedArray<*, *, *, *>, offset: Number = definedExternally, length: Number = definedExternally): Buffer

Copies the underlying memory of view into a new Buffer.

Link copied to clipboard
fun from(data: Uint8Array<*>): Buffer

Creates a new Buffer using the passed {data}


fun from(str: ToPrimitiveSymbolHolder, encoding: BufferEncoding = definedExternally): Buffer
fun from(str: WithImplicitCoercion<String>, encoding: BufferEncoding = definedExternally): Buffer

Creates a new Buffer containing the given JavaScript string {str}. If provided, the {encoding} parameter identifies the character encoding. If not provided, {encoding} defaults to 'utf8'.

fun from(arrayBuffer: WithImplicitCoercion<Any>, byteOffset: Number = definedExternally, length: Number = definedExternally): Buffer

Allocates a new Buffer using an array of bytes in the range 0255. Array entries outside that range will be truncated to fit into it.

Link copied to clipboard
fun isBuffer(obj: Any?): Boolean

Returns true if obj is a Buffer, false otherwise.

Link copied to clipboard
fun isEncoding(encoding: String): Boolean

Returns true if encoding is the name of a supported character encoding, or false otherwise.

Link copied to clipboard
fun of(vararg items: Double): Buffer

Creates a new Buffer using the passed {data}