Module

std/node/buffer.ts>Buffer

Deno standard library
Go to Latest
class Buffer
extends Uint8Array
import { Buffer } from "https://deno.land/std@0.80.0/node/buffer.ts";

Methods

copy(
targetBuffer: Buffer | Uint8Array,
targetStart?,
sourceStart?,
sourceEnd?,
): number

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

equals(otherBuffer: Uint8Array | Buffer): boolean
readBigInt64BE(offset?): bigint
readBigInt64LE(offset?): bigint
readBigUInt64BE(offset?): bigint
readBigUInt64LE(offset?): bigint
readDoubleBE(offset?): number
readDoubleLE(offset?): number
readFloatBE(offset?): number
readFloatLE(offset?): number
readInt16BE(offset?): number
readInt16LE(offset?): number
readInt32BE(offset?): number
readInt32LE(offset?): number
readInt8(offset?): number
readUInt16BE(offset?): number
readUInt16LE(offset?): number
readUInt32BE(offset?): number
readUInt32LE(offset?): number
readUInt8(offset?): number
slice(begin?, end?): Buffer

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

toJSON(): Record<string, unknown>

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

toString(
encoding?,
start?,
end?,
): string

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

write(
string: string,
offset?,
length?,
): number

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

writeBigInt64BE(value: bigint, offset?): number
writeBigInt64LE(value: bigint, offset?): number
writeBigUInt64BE(value: bigint, offset?): number
writeBigUInt64LE(value: bigint, offset?): number
writeDoubleBE(value: number, offset?): number
writeDoubleLE(value: number, offset?): number
writeFloatBE(value: number, offset?): number
writeFloatLE(value: number, offset?): number
writeInt16BE(value: number, offset?): number
writeInt16LE(value: number, offset?): number
writeInt32BE(value: number, offset?): number
writeInt32LE(value: number, offset?): number
writeInt8(value: number, offset?): number
writeUInt16BE(value: number, offset?): number
writeUInt16LE(value: number, offset?): number
writeUInt32BE(value: number, offset?): number
writeUInt32LE(value: number, offset?): number
writeUInt8(value: number, offset?): number

Static Methods

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

Allocates a new Buffer of size bytes.

allocUnsafe(size: number): Buffer
byteLength(string:
| string
| Buffer
| ArrayBufferView
| ArrayBuffer
| SharedArrayBuffer
, encoding?
): number

Returns the byte length of a string when encoded. 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.

concat(list: Buffer[] | Uint8Array[], totalLength?: number): Buffer

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

from(array: number[]): Buffer

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

from(
arrayBuffer: ArrayBuffer | SharedArrayBuffer,
byteOffset?: number,
length?: number,
): Buffer

This creates a view of the ArrayBuffer without copying the underlying memory. For example, 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.

from(buffer: Buffer | Uint8Array): Buffer

Copies the passed buffer data onto a new Buffer instance.

from(string: string, encoding?: string): Buffer

Creates a new Buffer containing string.

isBuffer(obj: unknown): obj is Buffer

Returns true if obj is a Buffer, false otherwise.

isEncoding(encoding: any): boolean