module buffer
Supported only in the v8 engine. Introduced in Max v9.2.0.
The buffer module exposed by require("buffer"), providing the buffer.IOBuffer class for handling binary data.
IOBuffer is the binary type used throughout the v8 networking APIs. It is a Uint8Array subclass in the spirit of Node's Buffer, but is not full Node Buffer parity. There is no global Buffer alias (which would conflict with the Max buffer~ wrapper). See buffer.IOBuffer for details.
Example
const { IOBuffer } = require("buffer");
const buf = IOBuffer.from("hello");
post(buf.toString(), "\n"); // hello
Index
Classes
Type Aliases
class IOBuffer
A Uint8Array subclass for binary data, used throughout the v8 networking APIs.
IOBuffer is the binary type used throughout the networking APIs. It is a subclass of Uint8Array. There is no global Buffer alias (which would conflict with the Max buffer~ wrapper), and IOBuffer is not full Node Buffer parity.
Obtain the class with const { IOBuffer } = require("buffer").
Example
const { IOBuffer } = require("buffer");
const a = IOBuffer.from("hello");
const b = IOBuffer.from("68656c6c6f", "hex");
post(a.equals(b), "\n"); // true
post(a.toString("base64"), "\n");
Constructors
Methods
- IOBuffer.alloc(size, fill)
- IOBuffer.byteLength(value, encoding)
- IOBuffer.concat(items)
- equals(other)
- IOBuffer.from(value, encoding)
- IOBuffer.from(arrayLike, mapfn, thisArg)
- IOBuffer.from(arrayLike, mapfn, thisArg)
- IOBuffer.isBuffer(value)
- slice(start, end)
- toString(encoding, start, end)
- toUint8Array()
new IOBuffer(value, encoding)
new IOBuffer(
value?:
number | ArrayBuffer | ArrayBufferView | string | ArrayLike<number>,
encoding?: IOBufferEncoding,
);
Constructs a new instance of the IOBuffer class
| Parameter | Type | Description |
|---|---|---|
| optional value | number | ArrayBuffer | ArrayBufferView | string | ArrayLike<number> | a byte length, an ArrayBuffer, a typed array / view, a string (decoded with encoding), or an array-like of byte values. |
| optional encoding | IOBufferEncoding | the encoding used when value is a string (default "utf8"). |
IOBuffer.alloc(size, fill) static
Allocates a zero- or fill-initialized IOBuffer of the given size.
static alloc(size: number, fill?: number | string): IOBuffer;
| Name | Type | Description |
|---|---|---|
| size | number | |
| optional fill | number | string | |
| Return Value | IOBuffer |
IOBuffer.byteLength(value, encoding) static
Returns the byte length of a string in the given encoding.
static byteLength(value: string, encoding?: IOBufferEncoding): number;
| Name | Type | Description |
|---|---|---|
| value | string | |
| optional encoding | IOBufferEncoding | |
| Return Value | number |
IOBuffer.concat(items) static
Concatenates several buffers into one.
static concat(items: IOBuffer[]): IOBuffer;
| Name | Type | Description |
|---|---|---|
| items | IOBuffer[] | |
| Return Value | IOBuffer |
equals(other)
Returns whether this buffer has the same bytes as another.
equals(other: IOBuffer): boolean;
| Name | Type | Description |
|---|---|---|
| other | IOBuffer | |
| Return Value | boolean |
IOBuffer.from(value, encoding) static
Creates an IOBuffer from a value.
static from(
value: ArrayBuffer | ArrayBufferView | string | ArrayLike<number>,
encoding?: IOBufferEncoding,
): IOBuffer;
| Name | Type | Description |
|---|---|---|
| value | ArrayBuffer | ArrayBufferView | string | ArrayLike<number> | |
| optional encoding | IOBufferEncoding | |
| Return Value | IOBuffer |
IOBuffer.from(arrayLike, mapfn, thisArg) static
Inherited Uint8Array.from form with a map function.
static from(
arrayLike: Iterable<number> | ArrayLike<number>,
mapfn?: (v: number, k: number) => number,
thisArg?: any,
): IOBuffer;
| Name | Type | Description |
|---|---|---|
| arrayLike | Iterable<number> | ArrayLike<number> | |
| optional mapfn | (v: number, k: number) => number | |
| optional thisArg | any | |
| Return Value | IOBuffer |
IOBuffer.from(arrayLike, mapfn, thisArg) static
Inherited Uint8Array.from form with a map function.
static from<T>(
arrayLike: Iterable<T> | ArrayLike<T>,
mapfn: (v: T, k: number) => number,
thisArg?: any,
): IOBuffer;
| Name | Type | Description |
|---|---|---|
| arrayLike | Iterable<T> | ArrayLike<T> | |
| mapfn | (v: T, k: number) => number | |
| optional thisArg | any | |
| Return Value | IOBuffer |
IOBuffer.isBuffer(value) static
Returns whether a value is an IOBuffer.
static isBuffer(value: any): boolean;
| Name | Type | Description |
|---|---|---|
| value | any | |
| Return Value | boolean |
slice(start, end)
Returns a new IOBuffer over a byte range (a view, like Uint8Array.slice).
slice(start?: number, end?: number): IOBuffer;
| Name | Type | Description |
|---|---|---|
| optional start | number | |
| optional end | number | |
| Return Value | IOBuffer |
toString(encoding, start, end)
Decodes (a range of) the buffer to a string.
toString(encoding?: IOBufferEncoding, start?: number, end?: number): string;
| Name | Type | Description |
|---|---|---|
| optional encoding | IOBufferEncoding | the output encoding (default "utf8"). |
| optional start | number | start byte offset. |
| optional end | number | end byte offset (exclusive). |
| Return Value | string |
toUint8Array()
Returns a plain Uint8Array view of the same bytes.
toUint8Array(): Uint8Array;
| Name | Type | Description |
|---|---|---|
| Return Value | Uint8Array |
type IOBufferEncoding
Encodings accepted by buffer.IOBuffer construction and conversion.
type IOBufferEncoding = "utf8" | "ascii" | "base64" | "hex";