Usage in Deno
```typescript import * as mod from "node:node__buffer.d.ts"; ````Buffer` objects are used to represent a fixed-length sequence of bytes. Many
Node.js APIs support `Buffer`s.
The `Buffer` class is a subclass of JavaScript's [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) class and
extends it with methods that cover additional use cases. Node.js APIs accept
plain [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) s wherever `Buffer`s are supported as well.
While the `Buffer` class is available within the global scope, it is still
recommended to explicitly reference it via an import or require statement.
```js
import { Buffer } from 'node:buffer';
// Creates a zero-filled Buffer of length 10.
const buf1 = Buffer.alloc(10);
// Creates a Buffer of length 10,
// filled with bytes which all have the value `1`.
const buf2 = Buffer.alloc(10, 1);
// Creates an uninitialized buffer of length 10.
// This is faster than calling Buffer.alloc() but the returned
// Buffer instance might contain old data that needs to be
// overwritten using fill(), write(), or other functions that fill the Buffer's
// contents.
const buf3 = Buffer.allocUnsafe(10);
// Creates a Buffer containing the bytes [1, 2, 3].
const buf4 = Buffer.from([1, 2, 3]);
// Creates a Buffer containing the bytes [1, 1, 1, 1] – the entries
// are all truncated using `(value & 255)` to fit into the range 0–255.
const buf5 = Buffer.from([257, 257.5, -255, '1']);
// Creates a Buffer containing the UTF-8-encoded bytes for the string 'tést':
// [0x74, 0xc3, 0xa9, 0x73, 0x74] (in hexadecimal notation)
// [116, 195, 169, 115, 116] (in decimal notation)
const buf6 = Buffer.from('tést');
// Creates a Buffer containing the Latin-1 bytes [0x74, 0xe9, 0x73, 0x74].
const buf7 = Buffer.from('tést', 'latin1');
```
c
I
v
c
I
v
File
A [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) provides information about files.
f
atob
Decodes a string of Base64-encoded data into bytes, and encodes those bytes
into a string using Latin-1 (ISO-8859-1).
The `data` may be any JavaScript-value that can be coerced into a string.
**This function is only provided for compatibility with legacy web platform APIs**
**and should never be used in new code, because they use strings to represent**
**binary data and predate the introduction of typed arrays in JavaScript.**
**For code running using Node.js APIs, converting between base64-encoded strings**
**and binary data should be performed using `Buffer.from(str, 'base64')` and `buf.toString('base64')`.**
f
btoa
Decodes a string into bytes using Latin-1 (ISO-8859), and encodes those bytes
into a string using Base64.
The `data` may be any JavaScript-value that can be coerced into a string.
**This function is only provided for compatibility with legacy web platform APIs**
**and should never be used in new code, because they use strings to represent**
**binary data and predate the introduction of typed arrays in JavaScript.**
**For code running using Node.js APIs, converting between base64-encoded strings**
**and binary data should be performed using `Buffer.from(str, 'base64')` and `buf.toString('base64')`.**
f
isAscii
This function returns `true` if `input` contains only valid ASCII-encoded data,
including the case in which `input` is empty.
Throws if the `input` is a detached array buffer.
f
isUtf8
This function returns `true` if `input` contains only valid UTF-8-encoded data,
including the case in which `input` is empty.
Throws if the `input` is a detached array buffer.
f
resolveObjectURL
Resolves a `'blob:nodedata:...'` an associated `Blob` object registered using
a prior call to `URL.createObjectURL()`.
f
transcode
Re-encodes the given `Buffer` or `Uint8Array` instance from one character
encoding to another. Returns a new `Buffer` instance.
Throws if the `fromEnc` or `toEnc` specify invalid character encodings or if
conversion from `fromEnc` to `toEnc` is not permitted.
Encodings supported by `buffer.transcode()` are: `'ascii'`, `'utf8'`, `'utf16le'`, `'ucs2'`, `'latin1'`, and `'binary'`.
The transcoding process will use substitution characters if a given byte
sequence cannot be adequately represented in the target encoding. For instance:
```js
import { Buffer, transcode } from 'node:buffer';
const newBuf = transcode(Buffer.from('€'), 'utf8', 'ascii');
console.log(newBuf.toString('ascii'));
// Prints: '?'
```
Because the Euro (`€`) sign is not representable in US-ASCII, it is replaced
with `?` in the transcoded `Buffer`.
I
I
v
Buffer
No documentation available
- compare
- copy
- equals
- fill
- includes
- indexOf
- lastIndexOf
- readBigInt64BE
- readBigInt64LE
- readBigUInt64BE
- readBigUInt64LE
- readBigUint64BE
- readBigUint64LE
- readDoubleBE
- readDoubleLE
- readFloatBE
- readFloatLE
- readInt16BE
- readInt16LE
- readInt32BE
- readInt32LE
- readInt8
- readIntBE
- readIntLE
- readUInt16BE
- readUInt16LE
- readUInt32BE
- readUInt32LE
- readUInt8
- readUIntBE
- readUIntLE
- readUint16BE
- readUint16LE
- readUint32BE
- readUint32LE
- readUint8
- readUintBE
- readUintLE
- reverse
- slice
- subarray
- swap16
- swap32
- swap64
- toJSON
- toString
- write
- writeBigInt64BE
- writeBigInt64LE
- writeBigUInt64BE
- writeBigUInt64LE
- writeBigUint64BE
- writeBigUint64LE
- writeDoubleBE
- writeDoubleLE
- writeFloatBE
- writeFloatLE
- writeInt16BE
- writeInt16LE
- writeInt32BE
- writeInt32LE
- writeInt8
- writeIntBE
- writeIntLE
- writeUInt16BE
- writeUInt16LE
- writeUInt32BE
- writeUInt32LE
- writeUInt8
- writeUIntBE
- writeUIntLE
- writeUint16BE
- writeUint16LE
- writeUint32BE
- writeUint32LE
- writeUint8
- writeUintBE
- writeUintLE
I
BufferConstructor
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'|'base64url'|'binary'(deprecated)|'hex'
I
I
T
BufferEncoding
No documentation available
T
TranscodeEncoding
No documentation available
T
WithImplicitCoercion
No documentation available
v
v
INSPECT_MAX_BYTES
No documentation available
v
kMaxLength
No documentation available
v
kStringMaxLength
No documentation available
v