Represents an instance used to read unknown type of data.
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; }} Copy
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; }}
Creates the Reader instance
The data to read.
The ReadableStream instance.
ReadableStream
The total size of the data in bytes.
Optional
Initializes the instance asynchronously
Reads a chunk of data
The byte index of the data to read.
The length of the data to read in bytes.
A promise resolving to a chunk of data.
Represents an instance used to read unknown type of data.
Example
Here is an example of custom Reader class used to read binary strings: