Buffer

object Buffer
Companion
class
class Object
trait Matchable
class Any

Value members

Concrete methods

@inline
def alloc(size: Double): Buffer

Allocates a new buffer of {size} octets.

Allocates a new buffer of {size} octets.

Value Params
encoding

encoding used for call to buf.fill while initalizing

fill

if specified, buffer will be initialized by calling buf.fill(fill). If parameter is omitted, buffer will be filled with zeros.

size

count of octets to allocate.

@inline
def alloc(size: Double, fill: Buffer): Buffer
@inline
def alloc(size: Double, fill: Buffer, encoding: BufferEncoding): Buffer
@inline
def alloc(size: Double, fill: String): Buffer
@inline
def alloc(size: Double, fill: String, encoding: BufferEncoding): Buffer
@inline
def alloc(size: Double, fill: Double): Buffer
@inline
def alloc(size: Double, fill: Double, encoding: BufferEncoding): Buffer
@inline
def alloc(size: Double, fill: Unit, encoding: BufferEncoding): Buffer
@inline
def allocUnsafe(size: Double): Buffer

Allocates a new buffer of {size} octets, leaving memory not initialized, so the contents of the newly created Buffer are unknown and may contain sensitive data.

Allocates a new buffer of {size} octets, leaving memory not initialized, so the contents of the newly created Buffer are unknown and may contain sensitive data.

Value Params
size

count of octets to allocate

@inline
def allocUnsafeSlow(size: Double): Buffer

Allocates a new non-pooled buffer of {size} octets, leaving memory not initialized, so the contents of the newly created Buffer are unknown and may contain sensitive data.

Allocates a new non-pooled buffer of {size} octets, leaving memory not initialized, so the contents of the newly created Buffer are unknown and may contain sensitive data.

Value Params
size

count of octets to allocate

@inline
def byteLength(string: ArrayBufferView): Double
@inline
def byteLength(string: ArrayBufferView, encoding: BufferEncoding): Double
@inline
def byteLength(string: SharedArrayBuffer): Double
@inline
def byteLength(string: SharedArrayBuffer, encoding: BufferEncoding): Double
@inline
def byteLength(string: String): Double

Gives the actual byte length of a string. encoding defaults to 'utf8'. This is not the same as String.prototype.length since that returns the number of characters in a string.

Gives the actual byte length of a string. encoding defaults to 'utf8'. This is not the same as String.prototype.length since that returns the number of characters in a string.

Value Params
encoding

encoding used to evaluate (defaults to 'utf8')

string

string to test.

@inline
def byteLength(string: String, encoding: BufferEncoding): Double
@inline
def byteLength(string: ArrayBuffer): Double
@inline
def byteLength(string: ArrayBuffer, encoding: BufferEncoding): Double
@inline
def compare(buf1: Uint8Array, buf2: Uint8Array): Double

The same as buf1.compare(buf2).

The same as buf1.compare(buf2).

@inline
def concat(list: Array[Uint8Array]): Buffer

Returns a buffer which is the result of concatenating all the buffers in the list together.

Returns a buffer which is the result of concatenating all the buffers in the list together.

If the list has no items, or if the totalLength is 0, then it returns a zero-length buffer. If the list has exactly one item, then the first item of the list is returned. If the list has more than one item, then a new Buffer is created.

Value Params
list

An array of Buffer objects to concatenate

totalLength

Total length of the buffers when concatenated. If totalLength is not provided, it is read from the buffers in the list. However, this adds an additional loop to the function, so it is faster to provide the length explicitly.

@inline
def concat(list: Array[Uint8Array], totalLength: Double): Buffer
@inline
def from(arrayBuffer: WithImplicitCoercion[ArrayBuffer | SharedArrayBuffer]): Buffer

When passed a reference to the .buffer property of a TypedArray instance, the newly created Buffer will share the same allocated memory as the TypedArray. The optional {byteOffset} and {length} arguments specify a memory range within the {arrayBuffer} that will be shared by the Buffer.

When passed a reference to the .buffer property of a TypedArray instance, the newly created Buffer will share the same allocated memory as the TypedArray. The optional {byteOffset} and {length} arguments specify a memory range within the {arrayBuffer} that will be shared by the Buffer.

Value Params
arrayBuffer

The .buffer property of any TypedArray or a new ArrayBuffer()

@inline
def from(arrayBuffer: WithImplicitCoercion[ArrayBuffer | SharedArrayBuffer], byteOffset: Double): Buffer
@inline
def from(arrayBuffer: WithImplicitCoercion[ArrayBuffer | SharedArrayBuffer], byteOffset: Double, length: Double): Buffer
@inline
def from(arrayBuffer: WithImplicitCoercion[ArrayBuffer | SharedArrayBuffer], byteOffset: Unit, length: Double): Buffer
@inline
def from(data: WithImplicitCoercion[Array[Double] | String | Uint8Array]): 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'.

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'.

@inline
def from(data: Array[Double]): Buffer
@inline
def from(data: Uint8Array): Buffer

Creates a new Buffer using the passed {data}

Creates a new Buffer using the passed {data}

Value Params
data

data to create a new Buffer

@inline
def from(str: ToPrimitive): Buffer
@inline
def from(str: ToPrimitive, encoding: BufferEncoding): Buffer
@inline
def from(str: WithImplicitCoercion[String], encoding: BufferEncoding): Buffer
@inline
def isBuffer(obj: Any): Boolean

Returns true if {obj} is a Buffer

Returns true if {obj} is a Buffer

Value Params
obj

object to test.

@inline
def isEncoding(encoding: String): Boolean

Returns true if {encoding} is a valid encoding argument. Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex'

Returns true if {encoding} is a valid encoding argument. Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex'

Value Params
encoding

string to test.

@inline
def of(items: Double*): Buffer

Creates a new Buffer using the passed {data}

Creates a new Buffer using the passed {data}

Value Params
values

to create a new Buffer

@JSImport("buffer", "Buffer.poolSize") @native
def poolSize: Double

This is the number of bytes used to determine the size of pre-allocated, internal Buffer instances used for pooling. This value may be modified.

This is the number of bytes used to determine the size of pre-allocated, internal Buffer instances used for pooling. This value may be modified.

@inline
def poolSize_=(x: Double): Unit

Concrete fields

@JSImport("buffer", "Buffer") @native
val ^: Any