Class Reader<Type>

Represents an instance used to read unknown type of data.

Example

Here is an example of custom Reader class used to read binary strings:

class BinaryStringReader extends Reader {

constructor(binaryString) {
super();
this.binaryString = binaryString;
}

init() {
super.init();
this.size = this.binaryString.length;
}

readUint8Array(offset, length) {
const result = new Uint8Array(length);
for (let indexCharacter = 0; indexCharacter < length; indexCharacter++) {
result[indexCharacter] = this.binaryString.charCodeAt(indexCharacter + offset) & 0xFF;
}
return result;
}
}

Type Parameters

  • Type

Hierarchy (view full)

Implements

Constructors

Properties

Methods

Constructors

Properties

readable: ReadableStream<any>

The ReadableStream instance.

size: number

The total size of the data in bytes.

Methods

  • Reads a chunk of data

    Parameters

    • index: number

      The byte index of the data to read.

    • length: number

      The length of the data to read in bytes.

    Returns Promise<Uint8Array>

    A promise resolving to a chunk of data.