| 21 | } |
| 22 | |
| 23 | export class Uint8ArrayExactReadable implements ExactReadable { |
| 24 | #data: Uint8Array; |
| 25 | #position: number; |
| 26 | |
| 27 | get position() { |
| 28 | return this.#position; |
| 29 | } |
| 30 | |
| 31 | constructor(data: Uint8Array) { |
| 32 | this.#data = data; |
| 33 | this.#position = 0; |
| 34 | } |
| 35 | |
| 36 | readExactly(length: number): Uint8Array { |
| 37 | if (this.#position + length > this.#data.length) { |
| 38 | throw new ExactReadableEndedError(); |
| 39 | } |
| 40 | |
| 41 | const result = this.#data.subarray( |
| 42 | this.#position, |
| 43 | this.#position + length, |
| 44 | ); |
| 45 | |
| 46 | this.#position += length; |
| 47 | return result; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | export interface AsyncExactReadable { |
| 52 | readonly position: number; |
nothing calls this directly
no outgoing calls
no test coverage detected