Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/esm/server/embed/types/node.ns.d.ts>Buffer

A fast, smart, & global CDN for modern(es2015+) web development.
Latest
class Buffer
extends Uint8Array
import { Buffer } from "https://deno.land/x/esm@v135_2/server/embed/types/node.ns.d.ts";

Raw data is stored in instances of the Buffer class. A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. A Buffer cannot be resized. Valid string encodings: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex'

Constructors

new
Buffer(str: string, encoding?: BufferEncoding)

Allocates a new buffer containing the given {str}.

new
Buffer(size: number)

Allocates a new buffer of {size} octets.

new
Buffer(array: Uint8Array)

Allocates a new buffer containing the given {array} of octets.

new
Buffer(arrayBuffer: ArrayBuffer | SharedArrayBuffer)

Produces a Buffer backed by the same allocated memory as the given {ArrayBuffer}/{SharedArrayBuffer}.

new
Buffer(array: ReadonlyArray<any>)

Allocates a new buffer containing the given {array} of octets.

new
Buffer(buffer: Buffer)

Copies the passed {buffer} data onto a new {Buffer} instance.

Methods

compare(
otherBuffer: Uint8Array,
targetStart?: number,
targetEnd?: number,
sourceStart?: number,
sourceEnd?: number,
): number
copy(
targetBuffer: Uint8Array,
targetStart?: number,
sourceStart?: number,
sourceEnd?: number,
): number
entries(): IterableIterator<[number, number]>
equals(otherBuffer: Uint8Array): boolean
fill(
value: string | Uint8Array | number,
offset?: number,
end?: number,
encoding?: BufferEncoding,
): this
includes(
value: string | number | Buffer,
byteOffset?: number,
encoding?: BufferEncoding,
): boolean
indexOf(
value: string | number | Uint8Array,
byteOffset?: number,
encoding?: BufferEncoding,
): number
keys(): IterableIterator<number>
lastIndexOf(
value: string | number | Uint8Array,
byteOffset?: number,
encoding?: BufferEncoding,
): number
readBigInt64BE(offset?: number): bigint
readBigInt64LE(offset?: number): bigint
readBigUInt64BE(offset?: number): bigint
readBigUInt64LE(offset?: number): bigint
readDoubleBE(offset?: number): number
readDoubleLE(offset?: number): number
readFloatBE(offset?: number): number
readFloatLE(offset?: number): number
readInt16BE(offset?: number): number
readInt16LE(offset?: number): number
readInt32BE(offset?: number): number
readInt32LE(offset?: number): number
readInt8(offset?: number): number
readIntBE(offset: number, byteLength: number): number
readIntLE(offset: number, byteLength: number): number
readUInt16BE(offset?: number): number
readUInt16LE(offset?: number): number
readUInt32BE(offset?: number): number
readUInt32LE(offset?: number): number
readUInt8(offset?: number): number
readUIntBE(offset: number, byteLength: number): number
readUIntLE(offset: number, byteLength: number): number
reverse(): this
slice(begin?: number, end?: number): Buffer

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

This method is incompatible with Uint8Array#slice(), which returns a copy of the original memory.

subarray(begin?: number, end?: number): Buffer

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

This method is compatible with Uint8Array#subarray().

swap16(): Buffer
swap32(): Buffer
swap64(): Buffer
toJSON(): { type: "Buffer"; data: number[]; }
toString(
encoding?: BufferEncoding,
start?: number,
end?: number,
): string
values(): IterableIterator<number>
write(string: string, encoding?: BufferEncoding): number
write(
string: string,
offset: number,
encoding?: BufferEncoding,
): number
write(
string: string,
offset: number,
length: number,
encoding?: BufferEncoding,
): number
writeBigInt64BE(value: bigint, offset?: number): number
writeBigInt64LE(value: bigint, offset?: number): number
writeBigUInt64BE(value: bigint, offset?: number): number
writeBigUInt64LE(value: bigint, offset?: number): number
writeDoubleBE(value: number, offset?: number): number
writeDoubleLE(value: number, offset?: number): number
writeFloatBE(value: number, offset?: number): number
writeFloatLE(value: number, offset?: number): number
writeInt16BE(value: number, offset?: number): number
writeInt16LE(value: number, offset?: number): number
writeInt32BE(value: number, offset?: number): number
writeInt32LE(value: number, offset?: number): number
writeInt8(value: number, offset?: number): number
writeIntBE(
value: number,
offset: number,
byteLength: number,
): number
writeIntLE(
value: number,
offset: number,
byteLength: number,
): number
writeUInt16BE(value: number, offset?: number): number
writeUInt16LE(value: number, offset?: number): number
writeUInt32BE(value: number, offset?: number): number
writeUInt32LE(value: number, offset?: number): number
writeUInt8(value: number, offset?: number): number
writeUIntBE(
value: number,
offset: number,
byteLength: number,
): number
writeUIntLE(
value: number,
offset: number,
byteLength: number,
): number

Static Properties

poolSize: number

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.

Static Methods

alloc(
size: number,
fill?: string | Buffer | number,
encoding?: BufferEncoding,
): Buffer

Allocates a new buffer of {size} octets.

allocUnsafe(size: number): 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.

allocUnsafeSlow(size: number): 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.

byteLength(string:
| string
| NodeJS.ArrayBufferView
| ArrayBuffer
| SharedArrayBuffer
, encoding?: BufferEncoding
): number

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.

compare(buf1: Uint8Array, buf2: Uint8Array): number

The same as buf1.compare(buf2).

concat(list: ReadonlyArray<Uint8Array>, totalLength?: number): Buffer

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.

from(
arrayBuffer: WithImplicitCoercion<ArrayBuffer | SharedArrayBuffer>,
byteOffset?: number,
length?: number,
): 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.

from(data: Uint8Array | ReadonlyArray<number>): Buffer

Creates a new Buffer using the passed {data}

from(data: WithImplicitCoercion<Uint8Array | ReadonlyArray<number> | string>): Buffer
from(str: WithImplicitCoercion<string> | { [[Symbol.toPrimitive]](hint: "string"): string; }, encoding?: BufferEncoding): 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'.

isBuffer(obj: any): obj is Buffer

Returns true if {obj} is a Buffer

isEncoding(encoding: string): encoding is BufferEncoding

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'

of(...items: number[]): Buffer

Creates a new Buffer using the passed {data}