* Read len bytes as a subarray view, advancing cursor by len bytes. * The returned Uint8Array shares the underlying buffer with the reader.
(len: number)
| 94 | * The returned Uint8Array shares the underlying buffer with the reader. |
| 95 | */ |
| 96 | readBytes(len: number): Uint8Array { |
| 97 | if (!Number.isInteger(len) || len < 0) { |
| 98 | throw new Error( |
| 99 | `BinaryReader.readBytes: len must be a non-negative integer (got ${String(len)})`, |
| 100 | ); |
| 101 | } |
| 102 | this.ensureAvailable(len); |
| 103 | const out = this.bytes.subarray(this.off, this.off + len); |
| 104 | this.off += len; |
| 105 | return out; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Validate that n bytes are available from current cursor position. |