* Parse the index section of the object stream. * Returns array of (objNum, offset) pairs.
()
| 105 | * Returns array of (objNum, offset) pairs. |
| 106 | */ |
| 107 | private parseIndex(): ObjectStreamEntry[] { |
| 108 | const result: ObjectStreamEntry[] = []; |
| 109 | |
| 110 | if (this.decodedData === null) { |
| 111 | throw new ObjectParseError("Decoded data not parsed"); |
| 112 | } |
| 113 | |
| 114 | // Create scanner for the index portion only |
| 115 | const indexData = this.decodedData.subarray(0, this.first); |
| 116 | const scanner = new Scanner(indexData); |
| 117 | const reader = new TokenReader(scanner); |
| 118 | |
| 119 | for (let i = 0; i < this.n; i++) { |
| 120 | const objNumToken = reader.nextToken(); |
| 121 | const offsetToken = reader.nextToken(); |
| 122 | |
| 123 | if (objNumToken.type !== "number") { |
| 124 | throw new ObjectParseError( |
| 125 | `Invalid object stream index at entry ${i}: expected object number, got ${objNumToken.type}`, |
| 126 | ); |
| 127 | } |
| 128 | |
| 129 | if (offsetToken.type !== "number") { |
| 130 | throw new ObjectParseError( |
| 131 | `Invalid object stream index at entry ${i}: expected offset, got ${offsetToken.type}`, |
| 132 | ); |
| 133 | } |
| 134 | |
| 135 | result.push({ |
| 136 | objNum: objNumToken.value, |
| 137 | offset: offsetToken.value, |
| 138 | }); |
| 139 | } |
| 140 | |
| 141 | return result; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Get an object by its index within the stream. |