()
| 1294 | } |
| 1295 | |
| 1296 | private advance(): Header | undefined | typeof NeedInput { |
| 1297 | while (this.current !== undefined) { |
| 1298 | if (this.readCurrent() === NeedInput) return NeedInput |
| 1299 | } |
| 1300 | if (this.finished) return this.finish() |
| 1301 | const queue = this.queue |
| 1302 | if (queue.length < 4) return this.needInput() |
| 1303 | const at = queue.consumed |
| 1304 | const head = queue.peek(Math.min(queue.length, 30)) |
| 1305 | const view = new DataView(head.buffer) |
| 1306 | const signature = view.getUint32(0, true) |
| 1307 | if (signature === CENTRAL || signature === END || signature === END64) return this.finish() |
| 1308 | if (signature !== LOCAL) { |
| 1309 | throw invalidHeader(`unexpected signature 0x${signature.toString(16).padStart(8, "0")} at byte ${at}`) |
| 1310 | } |
| 1311 | if (head.length < 30) return this.needInput() |
| 1312 | const length = 30 + view.getUint16(26, true) + view.getUint16(28, true) |
| 1313 | if (queue.length < length) return this.needInput() |
| 1314 | try { |
| 1315 | this.current = this.parseLocal(queue.take(length)) |
| 1316 | } catch (error) { |
| 1317 | if (isZipError(error)) { |
| 1318 | throw new ZipError({ kind: error.kind, message: `${error.message} (header at byte ${at})` }) |
| 1319 | } |
| 1320 | throw error |
| 1321 | } |
| 1322 | return this.current.header |
| 1323 | } |
| 1324 | |
| 1325 | // Returns the buffered body bytes of the entry from generation `id`, or |
| 1326 | // `undefined` once the whole body has been read and checked |
no test coverage detected