BufferClass

interface BufferClass : ProxyInstantiable, ProxyObject

Provides the prototype for the Node.js Buffer type, and acts as a meta-object for it, allowing the creation of new instances via "static" methods. A single instance of this class should be injected into a guest context to act as the Buffer symbol itself.

Properties

Link copied to clipboard
abstract var poolSize: Int

The size of the internal pool used for unsafe buffers. This value has no effect in the host implementation as NIO buffers with a managed pool are used instead.

Functions

Link copied to clipboard
abstract fun alloc(size: Int, fill: PolyglotValue? = null, encoding: String? = null): BufferInstance

Allocate a new buffer of the given size, optionally using the data from fill and, if the value is a string, converting it to bytes using a specific encoding. The buffer's bytes are initialized to zero.

Link copied to clipboard
abstract fun allocUnsafe(size: Int): BufferInstance

Allocate a new buffer of the given size without initializing it. The returned buffer contains arbitrary values and must be manually zeroed out.

Link copied to clipboard
abstract fun allocUnsafeSlow(size: Int): BufferInstance

Allocate a new buffer of the given size without initializing it. The returned buffer contains arbitrary values and must be manually zeroed out.

Link copied to clipboard
abstract fun byteLength(string: PolyglotValue, encoding: String?): Int

Returns the length of a string when converted to bytes using the given encoding (defaults to UTF-8). Note that per the Node.js API documentation, string may also be a Buffer, ArrayBuffer, DataView, or TypedArray, in which case the value of the byteLength property is returned instead.

Link copied to clipboard
abstract fun compare(buf1: PolyglotValue, buf2: PolyglotValue): Int

Compare two instances of Buffer or UInt8Array.

Link copied to clipboard
abstract fun concat(list: PolyglotValue, totalLength: Int? = null): BufferInstance

Allocate a new buffer and fill it by concatenating the data from a list of values (either Buffer or Uint8Array instances), up to totalLength if specified.

Link copied to clipboard
abstract fun copyBytesFrom(view: PolyglotValue, offset: Int? = null, length: Int? = null): BufferInstance

Allocates a new Buffer instance using the data from a view (a TypedArray object). Optional offset and length parameters can be used to restrict the window of data copied from the view.

Link copied to clipboard
abstract fun from(source: PolyglotValue, offset: Int? = null, length: Int? = null, encoding: String? = null): BufferInstance

Allocate a new buffer and fill it using the data from the given source. The source may be a simple integer[] array, Buffer or UInt8Array instance, in which case other parameters are ignored; an ArrayBuffer or SharedArrayBuffer, which allow setting an offset and length for the data to copy; or a string, which is converted to bytes using the encoding.

Link copied to clipboard
abstract fun getMember(key: String): Any
Link copied to clipboard
abstract fun getMemberKeys(): Any
Link copied to clipboard
abstract fun hasMember(key: String): Boolean
Link copied to clipboard
abstract fun isBuffer(obj: PolyglotValue): Boolean

Returns whether a given object is a Buffer instance.

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

Returns whether a given string represents a valid encoding supported by the runtime.

Link copied to clipboard
abstract fun newInstance(vararg arguments: Value): Any
Link copied to clipboard
abstract fun putMember(key: String, value: Value)
Link copied to clipboard
open fun removeMember(key: String): Boolean