Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

ByteSequence

import { ByteSequence } from "https://raw.githubusercontent.com/i-xi-dev/bytes.es/4.4.2/mod.ts";

Byte sequence

class ByteSequence {
private constructor(bytes: ArrayBuffer);
get byteLength(): number;
get size(): BytesSize;
get buffer(): ArrayBuffer;
get sha256Integrity(): Promise<string>;
get sha384Integrity(): Promise<string>;
get sha512Integrity(): Promise<string>;
 
asBigInt64Array(byteOffset?: number, byteLength?: number): BigInt64Array;
asBigUint64Array(byteOffset?: number, byteLength?: number): BigUint64Array;
asDataView(byteOffset?: number, byteLength?: number): DataView;
asFloat32Array(byteOffset?: number, byteLength?: number): Float32Array;
asFloat64Array(byteOffset?: number, byteLength?: number): Float64Array;
asInt16Array(byteOffset?: number, byteLength?: number): Int16Array;
asInt32Array(byteOffset?: number, byteLength?: number): Int32Array;
asInt8Array(byteOffset?: number, byteLength?: number): Int8Array;
asUint16Array(byteOffset?: number, byteLength?: number): Uint16Array;
asUint32Array(byteOffset?: number, byteLength?: number): Uint32Array;
asUint8Array(byteOffset?: number, byteLength?: number): Uint8Array;
asUint8ClampedArray(byteOffset?: number, byteLength?: number): Uint8ClampedArray;
at(index: number): number | undefined;
duplicate(): ByteSequence;
equals(otherBytes: Bytes): boolean;
format(options?: BytesFormat.Options): string;
getDataView(byteOffset?: number, byteLength?: number): DataView;
getUint8View(byteOffset?: number, byteLength?: number): Uint8Array;
getView<T extends ArrayBufferView>(
byteOffset?,
byteLength?: number,
): T;
segment(segmentByteLength: number): IterableIterator<ByteSequence>;
startsWith(otherBytes: Bytes): boolean;
subsequence(start: number, end?: number): ByteSequence;
toArray(): Array<number>;
toArrayBuffer(): ArrayBuffer;
toArrayBufferView<T extends ArrayBufferView>(ctor?: ArrayBufferViewConstructor<T>): T;
toBase64Encoded(options?: Base64.Options): string;
toBigInt64Array(): BigInt64Array;
toBigUint64Array(): BigUint64Array;
toBigUint64Iterable(byteOrder?: ByteOrder): Iterable<BigUint64>;
toBinaryString(): string;
toBlob(options?: BlobPropertyBag): Blob;
toDataURL(options?: BlobPropertyBag): URL;
toDataView(): DataView;
async toDigest(algorithm: Digest.Algorithm): Promise<ByteSequence>;
toFile(fileName: string, options?: FilePropertyBag): File;
toFloat32Array(): Float32Array;
toFloat64Array(): Float64Array;
toInt16Array(): Int16Array;
toInt32Array(): Int32Array;
toInt8Array(): Int8Array;
toJSON(): Array<number>;
toMd5Digest(): Promise<ByteSequence>;
toPercentEncoded(options?: Percent.Options): string;
toRequest(url: string, options: RequestInit): Request;
toResponse(options: ResponseInit): Response;
toSha1Digest(): Promise<ByteSequence>;
toSha256Digest(): Promise<ByteSequence>;
toSha384Digest(): Promise<ByteSequence>;
toSha512Digest(): Promise<ByteSequence>;
toStream(): ReadableStream<Uint8Array>;
toString(): string;
toText(decoder?: {
decode: (input?: Uint8Array) => string;
}
): string;
toUint16Array(): Uint16Array;
toUint16Iterable(byteOrder?: ByteOrder): Iterable<number>;
toUint32Array(): Uint32Array;
toUint32Iterable(byteOrder?: ByteOrder): Iterable<number>;
toUint8Array(): Uint8Array;
toUint8ClampedArray(): Uint8ClampedArray;
toUint8Iterable(): Iterable<Uint8>;
[Symbol.iterator](): IterableIterator<number>;
 
static allocate(byteLength: number): ByteSequence;
static from(sourceBytes: Bytes): ByteSequence;
static fromArray(byteArray: Array<number>): ByteSequence;
static fromArrayBuffer(buffer: ArrayBuffer): ByteSequence;
static fromArrayBufferView(bufferView: ArrayBufferView): ByteSequence;
static async fromAsyncBigUint64Iterable(source: AsyncIterable<bigint>, byteOrder?: ByteOrder): Promise<ByteSequence>;
static async fromAsyncUint16Iterable(source: AsyncIterable<number>, byteOrder?: ByteOrder): Promise<ByteSequence>;
static async fromAsyncUint32Iterable(source: AsyncIterable<number>, byteOrder?: ByteOrder): Promise<ByteSequence>;
static async fromAsyncUint8Iterable(source: AsyncIterable<number>): Promise<ByteSequence>;
static fromBase64Encoded(base64Encoded: string, options?: Base64.Options): ByteSequence;
static fromBigUint64Iterable(source: Iterable<bigint>, byteOrder?: ByteOrder): ByteSequence;
static fromBinaryString(binaryString: string): ByteSequence;
static async fromBlob(blob: Blob): Promise<ByteSequence>;
static fromBufferSource(bufferSource: BufferSource): ByteSequence;
static fromDataURL(dataUrl: URL | string): ByteSequence;
static fromPercentEncoded(percentEncoded: string, options?: Percent.Options): ByteSequence;
static async fromRequestOrResponse(reqOrRes: Request | Response, options?: RequestOrResponseReadingOptions): Promise<ByteSequence>;
static async fromStream(
options?: Loading.Options,
onProgressChange?: (event: ProgressEvent) => void,
): Promise<ByteSequence>;
static fromText(text: string, encoder?: {
encode: (input?: string) => Uint8Array;
}
): ByteSequence;
static fromUint16Iterable(source: Iterable<number>, byteOrder?: ByteOrder): ByteSequence;
static fromUint32Iterable(source: Iterable<number>, byteOrder?: ByteOrder): ByteSequence;
static fromUint8Iterable(source: Iterable<number>): ByteSequence;
static generateRandom(byteLength: number): ByteSequence;
static of(...bytes: Array<number>): ByteSequence;
static parse(formattedBytes: string, options?: BytesFormat.Options): ByteSequence;
static async withMetadataFromBlob(blob: Blob): Promise<{
data: ByteSequence;
options?: BlobPropertyBag | FilePropertyBag;
fileName?: string;
}
>
;
static withMetadataFromDataURL(dataUrl: URL | string): {
data: ByteSequence;
options?: BlobPropertyBag | FilePropertyBag;
}
;
static async withMetadataFromRequestOrResponse(reqOrRes: Request | Response, options?: RequestOrResponseReadingOptions): Promise<{
data: ByteSequence;
options?: BlobPropertyBag | FilePropertyBag;
fileName?: string;
}
>
;
static wrapArrayBuffer(buffer: ArrayBuffer): ByteSequence;
}

§Constructors

§
new ByteSequence(bytes: ArrayBuffer) private
[src]
@param bytes
  • An ArrayBuffer object.

§Properties

§
byteLength: number readonly
[src]

Gets the number of bytes.

@example
const bytes = ByteSequence.allocate(1024);
const byteCount = bytes.byteLength;
// byteCount
//   → 1024
@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const byteCount = bytes.byteLength;
// byteCount
//   → 8
§
size: BytesSize readonly
[src]

Gets the number of bytes as BytesSize.

@example
const bytes = ByteSequence.allocate(1024);
const kib = bytes.size.to("kibibyte");
// kib
//   → 1
@example
const bytes = ByteSequence.allocate(5_120_000);
const kib = bytes.size.to("kibibyte");
// (new Intl.NumberFormat("en")).format(kib) + " KiB"
//   → "5,000 KiB"
@example
const bytes = ByteSequence.allocate(5_000_000);
const kb = bytes.size.to("kilobyte");
// (new Intl.NumberFormat("en", { style: "unit", unit: "kilobyte" })).format(kb)
//   → "5,000 kB"
§
buffer: ArrayBuffer readonly
[src]

Gets the underlying ArrayBuffer.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const bufferRef = new Uint8Array(bytes.buffer);
bufferRef[0] = 0x0;
// bufferRef
//   → Uint8Array[ 0x0, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]

// new Uint8Array(bytes.buffer)
//   → Uint8Array[ 0x0, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
sha256Integrity: Promise<string> readonly
[src]

Returns the Promise that fulfills with a SRI integrity string with Base64-encoded SHA-256 digest for this byte sequence.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const integrity = await bytes.sha256Integrity;
// integrity
//   → "sha256-4pSrnUKfmpomeNmW5dvUDL9iNjpe1Bf2VMXwuoYeQgA="
§
sha384Integrity: Promise<string> readonly
[src]

Returns the Promise that fulfills with a SRI integrity string with Base64-encoded SHA-384 digest for this byte sequence.

§
sha512Integrity: Promise<string> readonly
[src]

Returns the Promise that fulfills with a SRI integrity string with Base64-encoded SHA-512 digest for this byte sequence.

§Methods

§
asBigInt64Array(byteOffset?: number, byteLength?: number): BigInt64Array
[src]

Returns the BigInt64Array that views the underlying ArrayBuffer of this instance.

@param byteOffset
  • The offset, in bytes.
@param byteLength
  • The length of the BigInt64Array, in bytes.
@return

The BigInt64Array.

§
asBigUint64Array(byteOffset?: number, byteLength?: number): BigUint64Array
[src]

Returns the BigUint64Array that views the underlying ArrayBuffer of this instance.

@param byteOffset
  • The offset, in bytes.
@param byteLength
  • The length of the BigUint64Array, in bytes.
@return

The BigUint64Array.

§
asDataView(byteOffset?: number, byteLength?: number): DataView
[src]

Returns the DataView that views the underlying ArrayBuffer of this instance.

@param byteOffset
  • The offset, in bytes.
@param byteLength
  • The length of the ArrayBufferView, in bytes.
@return

The DataView.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const dataViewPart = bytes.asDataView(6, 3);
// dataViewPart
//   → Uint8Array[ 0xE5, 0xB1, 0xB1 ]

dataViewPart.setUint8(0, 0);
dataViewPart.setUint8(1, 0);
dataViewPart.setUint8(2, 0);

// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0x0, 0x0, 0x0 ]
§
asFloat32Array(byteOffset?: number, byteLength?: number): Float32Array
[src]

Returns the Float32Array that views the underlying ArrayBuffer of this instance.

@param byteOffset
  • The offset, in bytes.
@param byteLength
  • The length of the Float32Array, in bytes.
@return

The Float32Array.

§
asFloat64Array(byteOffset?: number, byteLength?: number): Float64Array
[src]

Returns the Float64Array that views the underlying ArrayBuffer of this instance.

@param byteOffset
  • The offset, in bytes.
@param byteLength
  • The length of the Float64Array, in bytes.
@return

The Float64Array.

§
asInt16Array(byteOffset?: number, byteLength?: number): Int16Array
[src]

Returns the Int16Array that views the underlying ArrayBuffer of this instance.

@param byteOffset
  • The offset, in bytes.
@param byteLength
  • The length of the Int16Array, in bytes.
@return

The Int16Array.

§
asInt32Array(byteOffset?: number, byteLength?: number): Int32Array
[src]

Returns the Int32Array that views the underlying ArrayBuffer of this instance.

@param byteOffset
  • The offset, in bytes.
@param byteLength
  • The length of the Int32Array, in bytes.
@return

The Int32Array.

§
asInt8Array(byteOffset?: number, byteLength?: number): Int8Array
[src]

Returns the Int8Array that views the underlying ArrayBuffer of this instance.

@param byteOffset
  • The offset, in bytes.
@param byteLength
  • The length of the Int8Array, in bytes.
@return

The Int8Array.

§
asUint16Array(byteOffset?: number, byteLength?: number): Uint16Array
[src]

Returns the Uint16Array that views the underlying ArrayBuffer of this instance.

@param byteOffset
  • The offset, in bytes.
@param byteLength
  • The length of the Uint16Array, in bytes.
@return

The Uint16Array.

§
asUint32Array(byteOffset?: number, byteLength?: number): Uint32Array
[src]

Returns the Uint32Array that views the underlying ArrayBuffer of this instance.

@param byteOffset
  • The offset, in bytes.
@param byteLength
  • The length of the Uint32Array, in bytes.
@return

The Uint32Array.

§
asUint8Array(byteOffset?: number, byteLength?: number): Uint8Array
[src]

Returns the Uint8Array that views the underlying ArrayBuffer of this instance.

@param byteOffset
  • The offset, in bytes.
@param byteLength
  • The length of the Uint8Array, in bytes.
@return

The Uint8Array.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const uint8ViewPart = bytes.asUint8Array(6, 3);
// uint8ViewPart
//   → Uint8Array[ 0xE5, 0xB1, 0xB1 ]

uint8ViewPart.fill(0);

// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0x0, 0x0, 0x0 ]
§
asUint8ClampedArray(byteOffset?: number, byteLength?: number): Uint8ClampedArray
[src]

Returns the Uint8ClampedArray that views the underlying ArrayBuffer of this instance.

@param byteOffset
  • The offset, in bytes.
@param byteLength
  • The length of the Uint8ClampedArray, in bytes.
@return

The Uint8ClampedArray.

§
at(index: number): number | undefined
[src]
§
duplicate(): ByteSequence
[src]

Returns a new instance of ByteSequence with new underlying ArrayBuffer duplicated from the underlying ArrayBuffer of this instance.

@return

A new ByteSequence object.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const clone = bytes.duplicate();

clone.getUint8View()[0] = 0;
// clone.toArray()
//   → Uint8Array[ 0x0, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]

// bytes.toArray()
//   → Uint8Array[ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
equals(otherBytes: Bytes): boolean
[src]

Determines whether this byte sequence is equal to the byte sequence represented by another object.

@param otherBytes
  • The object that represents a byte sequence.
@return

If this is equal to the specified byte sequence, true; otherwise, false.

§
format(options?: BytesFormat.Options): string
[src]

Returns the string contains formatted bytes.

@param options
  • The BytesFormat.Options dictionary.
@return

The string contains formatted bytes.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const str = bytes.format();
// str
//   → "E5AF8CE5A3ABE5B1B1"
@example
const options = {
  lowerCase: true,
};
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const str = bytes.format(options);
// str
//   → "e5af8ce5a3abe5b1b1"
§
getDataView(byteOffset?: number, byteLength?: number): DataView deprecated
[src]

The alias for the asDataView method.

@deprecated
§
getUint8View(byteOffset?: number, byteLength?: number): Uint8Array deprecated
[src]

The alias for the asUint8Array method.

@deprecated
§
getView<T extends ArrayBufferView>(ctor?: ArrayBufferViewConstructor<T>, byteOffset?, byteLength?: number): T deprecated
[src]

Returns the ArrayBufferView that views the underlying ArrayBuffer of this instance.

@deprecated
@param ctor
  • The constructor of ArrayBufferView. The default is Uint8Array.
@param byteOffset
  • The offset, in bytes.
@param byteLength
  • The length of the ArrayBufferView, in bytes.
@return

The ArrayBufferView.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const uint8ViewPart = bytes.getView(Uint8Array, 6, 3);
// uint8ViewPart
//   → Uint8Array[ 0xE5, 0xB1, 0xB1 ]

uint8ViewPart.fill(0);

// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0x0, 0x0, 0x0 ]
§
segment(segmentByteLength: number): IterableIterator<ByteSequence>
[src]

Returns a new iterator that contains byte sequences divided by the specified length.

@param segmentByteLength
  • The segment length, in bytes.
@return

A new iterator.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const subsequenceClones = [ ...bytes.segment(3) ];
// subsequenceClones[0]
//   → Uint8Array[ 0xE5, 0xAF, 0x8C ]
// subsequenceClones[1]
//   → Uint8Array[ 0xE5, 0xA3, 0xAB ]
// subsequenceClones[2]
//   → Uint8Array[ 0xE5, 0xB1, 0xB1 ]
§
startsWith(otherBytes: Bytes): boolean
[src]

Determines whether this byte sequence starts with the specified byte sequence.

@param otherBytes
  • The object that represents a byte sequence.
@return

If this starts with the specified byte sequence, true; otherwise, false.

§
subsequence(start: number, end?: number): ByteSequence
[src]

Returns a new instance of ByteSequence with new underlying ArrayBuffer duplicated from a subsequence of the underlying ArrayBuffer of this instance.

@param start
  • The subsequence start index.
@param end
  • The subsequence end index.
@return

A new ByteSequence object.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const subsequenceClone = bytes.subsequence(6, 9);

subsequenceClone.getUint8View()[0] = 0;
// subsequenceClone.toArray()
//   → Uint8Array[ 0x0, 0xB1, 0xB1 ]

// bytes.toArray()
//   → Uint8Array[ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
toArray(): Array<number>
[src]

Returns the 8-bit unsigned integer Array representing this byte sequence.

@return

The Array of 8-bit unsigned integers.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const array = bytes.toArray();
// array
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
toArrayBuffer(): ArrayBuffer
[src]

Returns the ArrayBuffer duplicated from the underlying ArrayBuffer of this instance.

@return

The ArrayBuffer.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const dstBuffer = bytes.toArrayBuffer();
dstBuffer[0] = 0x0;
const dstView = new Uint8Array(dstBuffer);
// dstView
//   → Uint8Array[ 0x0, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]

const srcView = new Uint8Array(bytes.buffer);
// srcView
//   → Uint8Array[ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
toArrayBufferView<T extends ArrayBufferView>(ctor?: ArrayBufferViewConstructor<T>): T deprecated
[src]

Returns the ArrayBufferView that views a new ArrayBuffer duplicated from the underlying ArrayBuffer of this instance.

@deprecated
@param ctor
  • The ArrayBufferViews constructor. The default is Uint8Array.
@return

The ArrayBufferView.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const uint8Array = bytes.toArrayBufferView(Uint8ClampedArray);
// uint8Array
//   → Uint8ClampedArray[ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]

uint8Array.fill(0);
// uint8Array
//   → Uint8ClampedArray[ 0, 0, 0, 0, 0, 0, 0, 0, 0 ]

// bytes.toArrayBufferView(Uint8ClampedArray)
//   → Uint8ClampedArray[ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
toBase64Encoded(options?: Base64.Options): string
[src]

Returns the string contains Base64-encoded bytes of this byte sequence.

@param options
@return

The string contains Base64-encoded bytes.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const encoded = bytes.toBase64Encoded();
// encoded
//   → "5a+M5aOr5bGx"
@example
// Base64 URL (https://datatracker.ietf.org/doc/html/rfc4648#section-5) encoding

const base64Url = {
  tableLastChars: ["-", "_"],
  noPadding: true,
};
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const encoded = bytes.toBase64Encoded(base64Url);
// encoded
//   → "5a-M5aOr5bGx"
§
toBigInt64Array(): BigInt64Array
[src]

Returns the BigInt64Array that views a new ArrayBuffer duplicated from the underlying ArrayBuffer of this instance.

@return

The BigInt64Array.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1, 0, 0, 0, 0, 0, 0, 0);
const int64Array = bytes.toBigInt64Array();
// int64Array
//   When the platform byte order is little-endian
//   → BigInt64Array[ -5_627_903_438_910_345_243n, 177n ]
//   When the platform byte order is big-endian
//   → BigInt64Array[ -1_896_142_000_178_338_383n, -5_692_549_928_996_306_944n ]
§
toBigUint64Array(): BigUint64Array
[src]

Returns the BigUint64Array that views a new ArrayBuffer duplicated from the underlying ArrayBuffer of this instance.

@return

The BigUint64Array.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1, 0, 0, 0, 0, 0, 0, 0);
const uint64Array = bytes.toBigUint64Array();
// uint64Array
//   When the platform byte order is little-endian
//   → BigUint64Array[ 0xB1E5ABA3E58CAFE5n, 0x00000000000000B1n ]
//   When the platform byte order is big-endian
//   → BigUint64Array[ 0xE5AF8CE5A3ABE5B1n, 0xB100000000000000n ]
§
toBigUint64Iterable(byteOrder?: ByteOrder): Iterable<BigUint64>
[src]

Returns a 64-bit unsigned integer Iterable represented by this byte sequence.

@param byteOrder
  • The byte order. If omitted, the platform byte order is used.
@return

The Iterable of 64-bit unsigned integers.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1);
const uint64s = bytes.toBigUint64Iterable();
// [...uint64s]
//   When the platform byte order is little-endian
//   → [ 0xB1E5_ABA3_E58C_AFE5n ]
//   When the platform byte order is big-endian
//   → [ 0xE5AF_8CE5_A3AB_E5B1n ]

const uint64sLe = bytes.toBigUint64Iterable(ByteOrder.LITTLE_ENDIAN);
// [...uint64sLe]
//   → [ 0xB1E5_ABA3_E58C_AFE5n ]

const uint64sBe = bytes.toBigUint64Iterable(ByteOrder.BIG_ENDIAN);
// [...uint64sBe]
//   → [ 0xE5AF_8CE5_A3AB_E5B1n ]
§
toBinaryString(): string
[src]

Returns the isomorphic decoded string of this byte sequence.

@return
@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const binaryString = bytes.toBinaryString();
// binaryString
//   → "å¯\u{8C}士山"
§
toBlob(options?: BlobPropertyBag): Blob
[src]

Returns the Blob object representing this byte sequence.

@param options
@return

The Blob object.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const blob = bytes.toBlob({ type: "application/octet-stream" });
// new Uint8Array(await blob.arrayBuffer())
//   → Uint8Array[ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
// blob.type
//   → "application/octet-stream"
§
toDataURL(options?: BlobPropertyBag): URL
[src]

Returns the data URL representing this byte sequence.

@param options
@return

The data URL.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const dataUrl = bytes.toDataURL({ type: "application/octet-stream" });
// dataUrl.toString()
//   → "data:application/octet-stream;base64,5a+M5aOr5bGx"
§
toDataView(): DataView
[src]

Returns the DataView that views a new ArrayBuffer duplicated from the underlying ArrayBuffer of this instance.

@return

The DataView.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const dataView = bytes.toDataView();
// new Uint8Array(dataView.buffer)
//   → Uint8Array[ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]

dataView.setUint8(0, 0);
dataView.setUint8(1, 0);
dataView.setUint8(2, 0);
dataView.setUint8(3, 0);
// new Uint8Array(dataView.buffer)
//   → Uint8Array[ 0, 0, 0, 0, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]

// new Uint8Array(bytes.toDataView().buffer)
//   → Uint8Array[ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
toDigest(algorithm: Digest.Algorithm): Promise<ByteSequence>
[src]

Computes the digest for this byte sequence.

@param algorithm
  • The digest algorithm.
@return

The Promise that fulfills with a ByteSequence object of the digest.

@example
const md5 = {
  // compute: (input: BuuferSource) => Promise<ArrayBuffer>
  async compute(input) {
    // ...
  }
};
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const digestBytes = await bytes.toDigest(md5);
// digestBytes.format()
//   → "52A6AD27415BD86EC64B57EFBEA27F98"
§
toFile(fileName: string, options?: FilePropertyBag): File
[src]

Returns the File object representing this byte sequence.

@param fileName
  • The file name.
@param options
  • The FilePropertyBag object, but endings property is ignored.
@return

The File object.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const file = bytes.toFile("samp.dat", {
  type: "application/octet-stream",
  lastModified: 1640995200000,
});
// new Uint8Array(await file.arrayBuffer())
//   → Uint8Array[ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
// file.name
//   → "samp.dat"
// file.type
//   → "application/octet-stream"
// file.lastModified
//   → 1640995200000
§
toFloat32Array(): Float32Array
[src]

Returns the Float32Array that views a new ArrayBuffer duplicated from the underlying ArrayBuffer of this instance.

@return

The Float32Array.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1, 0, 0, 0);
const float32Array = bytes.toFloat32Array();
// float32Array
//   When the platform byte order is little-endian
//   → Float32Array[ -8.304699862546052e+22, -6.68429001038362e-9, 2.4802982818549262e-43 ]
//   When the platform byte order is big-endian
//   → Float32Array[ -1.0362664748269274e+23, -1.8637135243899587e-17, -1.862645149230957e-9 ]
§
toFloat64Array(): Float64Array
[src]

Returns the Float64Array that views a new ArrayBuffer duplicated from the underlying ArrayBuffer of this instance.

@return

The Float64Array.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1, 0, 0, 0, 0, 0, 0, 0);
const float64Array = bytes.toFloat64Array();
// float64Array
//   When the platform byte order is little-endian
//   → Float64Array[ -2.5118824744887084e-68, 8.74e-322 ]
//   When the platform byte order is big-endian
//   → Float64Array[ -6.54593944702149e+181, -1.131959884853339e-72 ]
§
toInt16Array(): Int16Array
[src]

Returns the Int16Array that views a new ArrayBuffer duplicated from the underlying ArrayBuffer of this instance.

@return

The Int16Array.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1, 0);
const int16Array = bytes.toInt16Array();
// int16Array
//   When the platform byte order is little-endian
//   → Int16Array[ -20_507, -6_772, -21_597, -19_995, 177 ]
//   When the platform byte order is big-endian
//   → Int16Array[ -6_737, -29_467, -23_637, -6_735, -20_224 ]
§
toInt32Array(): Int32Array
[src]

Returns the Int32Array that views a new ArrayBuffer duplicated from the underlying ArrayBuffer of this instance.

@return

The Int32Array.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1, 0, 0, 0);
const int32Array = bytes.toInt32Array();
// int32Array
//   When the platform byte order is little-endian
//   → Int32Array[ -443_764_763, -1_310_348_381, 177 ]
//   When the platform byte order is big-endian
//   → Int32Array[ -441_479_963, -1_549_015_631, -1_325_400_064 ]
§
toInt8Array(): Int8Array
[src]

Returns the Int8Array that views a new ArrayBuffer duplicated from the underlying ArrayBuffer of this instance.

@return

The Int8Array.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const int8Array = bytes.toInt8Array();
// int8Array
//   → Int8Array[ -27, -81, -116, -27, -93, -85, -27, -79, -79 ]
§
toJSON(): Array<number>
[src]

The alias for the toArray method.

@return

The Array of 8-bit unsigned integers.

§
toMd5Digest(): Promise<ByteSequence> deprecated
[src]

Computes the MD5 digest for this byte sequence.

@deprecated
@return

The Promise that fulfills with a ByteSequence object of the MD5 digest.

§
toPercentEncoded(options?: Percent.Options): string
[src]

Returns the string contains Percent-encoded bytes of this byte sequence.

@param options
  • The Percent.Options dictionary.
@return

The string contains Percent-encoded bytes.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const encoded = bytes.toPercentEncoded();
// encoded
//   → "%E5%AF%8C%E5%A3%AB%E5%B1%B1"
@example
// URL component encoding

const urlComponent = {
  encodeSet: [ 0x20, 0x22, 0x23, 0x24, 0x26, 0x2B, 0x2C, 0x2F, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x60, 0x7B, 0x7C, 0x7D ],
};
const bytes = ByteSequence.fromText("富士山");
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
const encoded = bytes.toPercentEncoded(urlComponent);
// encoded
//   → "%E5%AF%8C%E5%A3%AB%E5%B1%B1"
@example
// encoding for the value of application/x-www-form-urlencoded

const formUrlEnc = {
  encodeSet: [ 0x20, 0x22, 0x23, 0x24, 0x26, 0x2B, 0x2C, 0x2F, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x60, 0x7B, 0x7C, 0x7D ],
  spaceAsPlus: true,
};
const bytes = ByteSequence.fromText("富士山");
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
const encoded = bytes.toPercentEncoded(formUrlEnc);
// encoded
//   → "%E5%AF%8C%E5%A3%AB%E5%B1%B1"
§
toRequest(url: string, options: RequestInit): Request
[src]
@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const request = bytes.toRequest("http://example.com/foo", {
  method: "POST",
  headers: new Headers({
    "Content-Type": "application/octet-stream",
  }),
});
// new Uint8Array(await request.arrayBuffer())
//   → Uint8Array[ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
// request.headers.get("Content-Type")
//   → "application/octet-stream"
§
toResponse(options: ResponseInit): Response
[src]
@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const response = bytes.toResponse({
  headers: new Headers({
    "Content-Type": "application/octet-stream",
  }),
});
// new Uint8Array(await response.arrayBuffer())
//   → Uint8Array[ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
// response.headers.get("Content-Type")
//   → "application/octet-stream"
§
toSha1Digest(): Promise<ByteSequence> deprecated
[src]

Computes the SHA-1 digest for this byte sequence.

@deprecated
@return

The Promise that fulfills with a ByteSequence object of the SHA-1 digest.

§
toSha256Digest(): Promise<ByteSequence>
[src]

Computes the SHA-256 digest for this byte sequence.

@return

The Promise that fulfills with a ByteSequence object of the SHA-256 digest.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const digestBytes = await bytes.toSha256Digest();
// digestBytes.format()
//   → "E294AB9D429F9A9A2678D996E5DBD40CBF62363A5ED417F654C5F0BA861E4200"
§
toSha384Digest(): Promise<ByteSequence>
[src]

Computes the SHA-384 digest for this byte sequence.

@return

The Promise that fulfills with a ByteSequence object of the SHA-384 digest.

§
toSha512Digest(): Promise<ByteSequence>
[src]

Computes the SHA-512 digest for this byte sequence.

@return

The Promise that fulfills with a ByteSequence object of the SHA-512 digest.

§
toStream(): ReadableStream<Uint8Array>
[src]
§
toString(): string
[src]

Returns the string contains hexadecimal formatted bytes. Equivalents to the format method with no parameters.

@return

The string contains hexadecimal formatted bytes.

§
toText(decoder?: {
decode: (input?: Uint8Array) => string;
}
): string
[src]

Returns a decoded string by the specified text encoding of this bytes.

@param decoder
  • The text decoder, for example TextDecoder. The default is UTF-8 decoder, which does not add or remove BOM.
@return

A string decoded in the specified text encoding.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const text = bytes.toText();
// text
//   → "富士山"
@example
// EUC-JP decoding (Node.js)

import iconv from "iconv-lite";
const eucJp = {
  // decode: (encoded: Uint8Array) => string
  decode(encoded) {
    return iconv.decode(Buffer.from(encoded), "EUC-JP");
  },
};
const bytes = ByteSequence.of(0xC9, 0xD9, 0xBB, 0xCE, 0xBB, 0xB3);
const text = bytes.toText(eucJp);
// text
//   → "富士山"
@example
// UTF-8 decoding (remove the BOM)

const decoder = new TextDecoder("utf-8", { ignoreBOM: false });
const utf8 = {
  // decode: (encoded: Uint8Array) => string
  decode(encoded) {
    return decoder.decode(encoded);
  },
};
const bytes = ByteSequence.of(0xEF, 0xBB, 0xBF, 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const text = bytes.toText(utf8);
// text
//   → "富士山"
§
toUint16Array(): Uint16Array
[src]

Returns the Uint16Array that views a new ArrayBuffer duplicated from the underlying ArrayBuffer of this instance.

@return

The Uint16Array.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1, 0);
const uint16Array = bytes.toUint16Array();
// uint16Array
//   When the platform byte order is little-endian
//   → Uint16Array[ 0xAFE5, 0xE58C, 0xABA3, 0xB1E5, 0x00B1 ]
//   When the platform byte order is big-endian
//   → Uint16Array[ 0xE5AF, 0x8CE5, 0xA3AB, 0xE5B1, 0xB100 ]
§
toUint16Iterable(byteOrder?: ByteOrder): Iterable<number>
[src]

Returns a 16-bit unsigned integer Iterable represented by this byte sequence.

@param byteOrder
  • The byte order. If omitted, the platform byte order is used.
@return

The Iterable of 16-bit unsigned integers.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1, 0);
const uint16s = bytes.toUint16Iterable();
// [...uint16s]
//   When the platform byte order is little-endian
//   → [ 0xAFE5, 0xE58C, 0xABA3, 0xB1E5, 0x00B1 ]
//   When the platform byte order is big-endian
//   → [ 0xE5AF, 0x8CE5, 0xA3AB, 0xE5B1, 0xB100 ]

const uint16sLe = bytes.toUint16Iterable(ByteOrder.LITTLE_ENDIAN);
// [...uint16sLe]
//   → [ 0xAFE5, 0xE58C, 0xABA3, 0xB1E5, 0x00B1 ]

const uint16sBe = bytes.toUint16Iterable(ByteOrder.BIG_ENDIAN);
// [...uint16sBe]
//   → [ 0xE5AF, 0x8CE5, 0xA3AB, 0xE5B1, 0xB100 ]
§
toUint32Array(): Uint32Array
[src]

Returns the Uint32Array that views a new ArrayBuffer duplicated from the underlying ArrayBuffer of this instance.

@return

The Uint32Array.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1, 0, 0, 0);
const uint32Array = bytes.toUint32Array();
// uint32Array
//   When the platform byte order is little-endian
//   → Uint32Array[ 0xE58CAFE5, 0xB1E5ABA3, 0x000000B1 ]
//   When the platform byte order is big-endian
//   → Uint32Array[ 0xE5AF8CE5, 0xA3ABE5B1, 0xB1000000 ]
§
toUint32Iterable(byteOrder?: ByteOrder): Iterable<number>
[src]

Returns a 32-bit unsigned integer Iterable represented by this byte sequence.

@param byteOrder
  • The byte order. If omitted, the platform byte order is used.
@return

The Iterable of 32-bit unsigned integers.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1, 0, 0, 0);
const uint32s = bytes.toUint32Iterable();
// [...uint32s]
//   When the platform byte order is little-endian
//   → [ 0xE58C_AFE5, 0xB1E5_ABA3, 0x0000_00B1 ]
//   When the platform byte order is big-endian
//   → [ 0xE5AF_8CE5, 0xA3AB_E5B1, 0xB100_0000 ]

const uint32sLe = bytes.toUint32Iterable(ByteOrder.LITTLE_ENDIAN);
// [...uint32sLe]
//   → [ 0xE58C_AFE5, 0xB1E5_ABA3, 0x0000_00B1 ]

const uint32sBe = bytes.toUint32Iterable(ByteOrder.BIG_ENDIAN);
// [...uint32sBe]
//   → [ 0xE5AF_8CE5, 0xA3AB_E5B1, 0xB100_0000 ]
§
toUint8Array(): Uint8Array
[src]

Returns the Uint8Array that views a new ArrayBuffer duplicated from the underlying ArrayBuffer of this instance.

@return

The Uint8Array.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const uint8Array = bytes.toUint8Array();
// uint8Array
//   → Uint8Array[ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
uint8Array.fill(0);
// uint8Array
//   → Uint8Array[ 0, 0, 0, 0, 0, 0, 0, 0, 0 ]

// bytes.toUint8Array()
//   → Uint8Array[ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
toUint8ClampedArray(): Uint8ClampedArray
[src]

Returns the Uint8ClampedArray that views a new ArrayBuffer duplicated from the underlying ArrayBuffer of this instance.

@return

The Uint8ClampedArray.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const uint8ClampedArray = bytes.toUint8ClampedArray();
// uint8ClampedArray
//   → Uint8ClampedArray[ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
toUint8Iterable(): Iterable<Uint8>
[src]

Returns the 8-bit unsigned integer Iterable representing this byte sequence.

@return

The Iterable of 8-bit unsigned integers.

@example
const bytes = ByteSequence.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const uint8s = bytes.toUint8Iterable();
// [...uint8s]
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
[Symbol.iterator](): IterableIterator<number>
[src]

§Static Methods

§
allocate(byteLength: number): ByteSequence
[src]

Creates a new instance of ByteSequence of the specified size. Its bytes are filled with zeros.

@param byteLength
  • The size, in bytes.
@return

A new ByteSequence object.

@example
const bytes = ByteSequence.allocate(1024);
// bytes.byteLength
//   → 1024
§
from(sourceBytes: Bytes): ByteSequence
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer created from the specified ByteSequence, BufferSource, or 8-bit unsigned integer Array.

@param sourceBytes
  • The Bytes object represents a byte sequence.
@return

A new ByteSequence object.

§
fromArray(byteArray: Array<number>): ByteSequence
[src]

The alias for the fromUint8Iterable method.

@param byteArray
  • The 8-bit unsigned integer Array represents a byte sequence.
@return

A new ByteSequence object.

§
fromArrayBuffer(buffer: ArrayBuffer): ByteSequence
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer that duplicates the specified ArrayBuffer.

@param buffer
  • The ArrayBuffer.
@return

A new ByteSequence object.

@example
const srcBuffer = Uint8Array.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1).buffer;
const bytes = ByteSequence.fromArrayBuffer(srcBuffer);
const dstBuffer = bytes.buffer;
// (dstBuffer === srcBuffer)
//   → false
§
fromArrayBufferView(bufferView: ArrayBufferView): ByteSequence
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer that duplicates the underlying ArrayBuffer of the specified ArrayBufferView.

@param bufferView
  • The object that represents a byte sequence.
@return

A new ByteSequence object.

@example
const uint8Array = Uint8Array.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const bytes = ByteSequence.fromArrayBufferView(uint8Array);
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
@example
const buffer = Uint8Array.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1).buffer;
const dataView = new DataView(buffer);
const bytes = ByteSequence.fromArrayBufferView(dataView);
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
fromAsyncBigUint64Iterable(source: AsyncIterable<bigint>, byteOrder?: ByteOrder): Promise<ByteSequence>
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer created from the specified 64-bit unsigned integer AsyncIterable.

@param source
  • The 64-bit unsigned integer AsyncIterable represents a byte sequence.
@param byteOrder
  • The byte order. If omitted, write in the platform byte order.
@return

A new ByteSequence object.

§
fromAsyncUint16Iterable(source: AsyncIterable<number>, byteOrder?: ByteOrder): Promise<ByteSequence>
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer created from the specified 16-bit unsigned integer AsyncIterable.

@param source
  • The 16-bit unsigned integer AsyncIterable represents a byte sequence.
@param byteOrder
  • The byte order. If omitted, write in the platform byte order.
@return

A new ByteSequence object.

§
fromAsyncUint32Iterable(source: AsyncIterable<number>, byteOrder?: ByteOrder): Promise<ByteSequence>
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer created from the specified 32-bit unsigned integer AsyncIterable.

@param source
  • The 32-bit unsigned integer AsyncIterable represents a byte sequence.
@param byteOrder
  • The byte order. If omitted, write in the platform byte order.
@return

A new ByteSequence object.

§
fromAsyncUint8Iterable(source: AsyncIterable<number>): Promise<ByteSequence>
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer created from the specified 8-bit unsigned integer AsyncIterable.

@param source
  • The 8-bit unsigned integer AsyncIterable represents a byte sequence.
@return

A new ByteSequence object.

§
fromBase64Encoded(base64Encoded: string, options?: Base64.Options): ByteSequence
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer created from the string contains Base64-encoded bytes.

@param base64Encoded
  • The string to decode.
@param options
@return

A new ByteSequence object.

@example
const bytes = ByteSequence.fromBase64Encoded("5a+M5aOr5bGx");
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
@example
// Base64 URL (https://datatracker.ietf.org/doc/html/rfc4648#section-5) decoding

const base64Url = {
  tableLastChars: ["-", "_"],
  noPadding: true,
};
const bytes = ByteSequence.fromBase64Encoded("5a-M5aOr5bGx", base64Url);
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
fromBigUint64Iterable(source: Iterable<bigint>, byteOrder?: ByteOrder): ByteSequence
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer created from the specified 64-bit unsigned integer Iterable.

@param source
  • The 64-bit unsigned integer Iterable represents a byte sequence.
@param byteOrder
  • The byte order. If omitted, write in the platform byte order.
@return

A new ByteSequence object.

§
fromBinaryString(binaryString: string): ByteSequence
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer created from the isomorphic encoded string.

@param binaryString
@return

A new ByteSequence object.

@example
const bytes = ByteSequence.fromBinaryString("å¯\u{8C}士山");
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
fromBlob(blob: Blob): Promise<ByteSequence>
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer created from the specified Blob object.

@param blob
  • The Blob object (including File object).
@return

The Promise that fulfills with a new ByteSequence object.

@example
const blob = new Blob([ Uint8Array.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1) ]);
const bytes = await ByteSequence.fromBlob(blob);
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
@example
const file = new File([ Uint8Array.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1) ], "samp.dat");
const bytes = await ByteSequence.fromBlob(file);
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
fromBufferSource(bufferSource: BufferSource): ByteSequence
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer that duplicates the underlying ArrayBuffer of the specified BufferSource.

@param bufferSource
  • The object that represents a byte sequence.
@return

A new ByteSequence object.

@example
const srcBuffer = Uint8Array.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1).buffer;
const bytes = ByteSequence.fromBufferSource(srcBuffer);
const dstBuffer = bytes.buffer;
// (dstBuffer === srcBuffer)
//   → false
// new Uint8Array(dstBuffer)
//   → Uint8Array[ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
@example
const uint8Array = Uint8Array.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1);
const bytes = ByteSequence.fromBufferSource(uint8Array);
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
fromDataURL(dataUrl: URL | string): ByteSequence
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer created from the specified data URL.

@param dataUrl
  • The data URL.
@return

A new ByteSequence object.

@example
const bytes = await ByteSequence.fromDataURL("data:application/octet-stream;base64,5a+M5aOr5bGx");
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
fromPercentEncoded(percentEncoded: string, options?: Percent.Options): ByteSequence
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer created from the string contains Percent-encoded bytes.

@param percentEncoded
  • The string to decode.
@param options
  • The Percent.Options dictionary.
@return

A new ByteSequence object.

@example
const bytes = ByteSequence.fromPercentEncoded("%E5%AF%8C%E5%A3%AB%E5%B1%B1");
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
@example
// URL component decoding

const urlComponent = {
  encodeSet: [ 0x20, 0x22, 0x23, 0x24, 0x26, 0x2B, 0x2C, 0x2F, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x60, 0x7B, 0x7C, 0x7D ],
};
const bytes = ByteSequence.fromPercentEncoded("%E5%AF%8C%E5%A3%AB%E5%B1%B1", urlComponent);
// bytes.toText()
//   → "富士山"
@example
// decoding for the value of application/x-www-form-urlencoded

const formUrlEnc = {
  encodeSet: [ 0x20, 0x22, 0x23, 0x24, 0x26, 0x2B, 0x2C, 0x2F, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x60, 0x7B, 0x7C, 0x7D ],
  spaceAsPlus: true,
};
const bytes = ByteSequence.fromPercentEncoded("%E5%AF%8C%E5%A3%AB%E5%B1%B1", formUrlEnc);
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
// bytes.toText()
//   → "富士山"
§
fromRequestOrResponse(reqOrRes: Request | Response, options?: RequestOrResponseReadingOptions): Promise<ByteSequence>
[src]
@example
const request = new Request("http://example.com/foo", {
  method: "POST",
  body: new Blob([ Uint8Array.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1) ]),
});
const bytes = await ByteSequence.fromRequestOrResponse(request);
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
@example
const blob = new Blob([ Uint8Array.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1) ]);
const response = new Response(blob);
const bytes = await ByteSequence.fromRequestOrResponse(response);
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
fromStream(source: BytesStream.Source, options?: Loading.Options, onProgressChange?: (event: ProgressEvent) => void): Promise<ByteSequence>
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer created from the specified ReadableStream of Uint8Array.

If you want to read Node.js Readable stream of Buffer, you can use stream.Readable.toWeb method (Node.js 17.0.0+)

@param source
  • The ReadableStream of Uint8Array or the async iterator of Uint8Array.
@param options
  • The BytesStream.ReadingOptions object.
@param onProgressChange
  • The ProgressEvent listener. | type | x | | :--- | :--- | | "loadstart", "progress", "loadend" | These will be fired. | | "load" | This will not fire. Instead, the Promise is resolved. | | "abort", "timeout", "error" | These will not fire. Instead, the Promise is rejected. |
@return

The Promise that fulfills with a new ByteSequence object.

@example
const blob = new Blob([ Uint8Array.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1) ]);
const stream = blob.stream();
const bytes = await ByteSequence.fromStream(stream);
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
fromText(text: string, encoder?: {
encode: (input?: string) => Uint8Array;
}
): ByteSequence
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer generated from the specified string by the specified text encoding.

@param text
  • The string.
@param encoder
  • The text encoder, for example TextEncoder. The default is UTF-8 encoder, which does not add or remove BOM.
@return

A new ByteSequence object.

@example
const bytes = ByteSequence.fromText("富士山");
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
@example
// EUC-JP encoding (Node.js)

import iconv from "iconv-lite";
const eucJp = {
  // encode: (toEncode: string) => Uint8Array
  encode(toEncode) {
    return iconv.encode(toEncode, "EUC-JP");
  },
};
const bytes = ByteSequence.fromText("富士山", eucJp);
// bytes.toArray()
//   → [ 0xC9, 0xD9, 0xBB, 0xCE, 0xBB, 0xB3 ]
@example
// UTF-8 encoding (add the BOM)

const encoder = new TextEncoder();
const utf8 = {
  // encode: (toEncode: string) => Uint8Array
  encode(toEncode) {
    const prepend = toEncode.startsWith("\uFEFF") ? "" : "\uFEFF";
    return encoder.encode(prepend + toEncode);
  },
};
const bytes = ByteSequence.fromText("富士山", utf8);
// bytes.toArray()
//   → [ 0xEF, 0xBB, 0xBF, 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
fromUint16Iterable(source: Iterable<number>, byteOrder?: ByteOrder): ByteSequence
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer created from the specified 16-bit unsigned integer Iterable.

@param source
  • The 16-bit unsigned integer Iterable represents a byte sequence.
@param byteOrder
  • The byte order. If omitted, write in the platform byte order.
@return

A new ByteSequence object.

§
fromUint32Iterable(source: Iterable<number>, byteOrder?: ByteOrder): ByteSequence
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer created from the specified 32-bit unsigned integer Iterable.

@param source
  • The 32-bit unsigned integer Iterable represents a byte sequence.
@param byteOrder
  • The byte order. If omitted, write in the platform byte order.
@return

A new ByteSequence object.

§
fromUint8Iterable(source: Iterable<number>): ByteSequence
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer created from the specified 8-bit unsigned integer Iterable.

@param source
  • The 8-bit unsigned integer Iterable represents a byte sequence.
@return

A new ByteSequence object.

@example
const array = [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ];
const bytes = ByteSequence.fromUint8Iterable(array);
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
generateRandom(byteLength: number): ByteSequence
[src]

Creates a new instance of ByteSequence of the specified size. Its bytes are filled with random values.

@param byteLength
  • The size, in bytes.
@return

A new ByteSequence object.

@example
const randomBytes = ByteSequence.generateRandom(1024);
// randomBytes.byteLength
//   → 1024
§
of(...bytes: Array<number>): ByteSequence
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer created from the specified 8-bit unsigned integer iterator.

@param bytes
  • The iterator of 8-bit unsigned integers.
@return

A new ByteSequence object.

§
parse(formattedBytes: string, options?: BytesFormat.Options): ByteSequence
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer created from the string contains formatted bytes.

@param formattedBytes
  • The string to parse.
@param options
  • The BytesFormat.Options dictionary.
@return

A new ByteSequence object.

@example
const bytes = ByteSequence.parse("E5AF8CE5A3ABE5B1B1");
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
@example
const options = {
  lowerCase: true,
};
const bytes = ByteSequence.parse("e5af8ce5a3abe5b1b1", options);
// bytes.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
§
withMetadataFromBlob(blob: Blob): Promise<{
data: ByteSequence;
options?: BlobPropertyBag | FilePropertyBag;
fileName?: string;
}
>
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer created from the specified Blob object.

@param blob
  • The Blob object (including File object).
@return

The Promise that fulfills with a new ByteSequence and a BlobPropertyBag.

@example
const blob = new Blob([ Uint8Array.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1) ], { type: "application/octet-stream" });
const { data, options } = await ByteSequence.withMetadataFromBlob(blob);
// data.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
// options.type
//   → "application/octet-stream"
§
withMetadataFromDataURL(dataUrl: URL | string): {
data: ByteSequence;
options?: BlobPropertyBag | FilePropertyBag;
}
[src]

Creates a new instance of ByteSequence with new underlying ArrayBuffer created from the specified data URL.

@param dataUrl
  • The data URL.
@return

A new ByteSequence object.

@example
const { data, options } = await ByteSequence.withMetadataFromDataURL("data:application/octet-stream;base64,5a+M5aOr5bGx");
// data.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
// options.type
//   → "application/octet-stream"
§
withMetadataFromRequestOrResponse(reqOrRes: Request | Response, options?: RequestOrResponseReadingOptions): Promise<{
data: ByteSequence;
options?: BlobPropertyBag | FilePropertyBag;
fileName?: string;
}
>
[src]
@example
const request = new Request("http://example.com/foo", {
  method: "POST",
  headers: new Headers({
    "Content-Type": "application/octet-stream",
  }),
  body: new Blob([ Uint8Array.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1) ]),
});
const { data, options } = await ByteSequence.withMetadataFromRequestOrResponse(request);
// data.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
// options.type
//   → "application/octet-stream"
@example
const blob = new Blob([ Uint8Array.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1) ]);
const response = new Response(blob, {
  headers: new Headers({
    "Content-Type": "application/octet-stream",
  }),
});
const { data, options } = await ByteSequence.withMetadataFromRequestOrResponse(response);
// data.toArray()
//   → [ 0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1 ]
// options.type
//   → "application/octet-stream"
§
wrapArrayBuffer(buffer: ArrayBuffer): ByteSequence
[src]

Creates a new instance of ByteSequence with the specified underlying ArrayBuffer.

@param buffer
  • The ArrayBuffer.
@return

A new ByteSequence object.

@example
const srcBuffer = Uint8Array.of(0xE5, 0xAF, 0x8C, 0xE5, 0xA3, 0xAB, 0xE5, 0xB1, 0xB1).buffer;
const bytes = ByteSequence.wrapArrayBuffer(srcBuffer);
const srcBufferRef = bytes.buffer;
// (srcBufferRef === srcBuffer)
//   → true