(
current: Current
)
| 1410 | // sizes only on overflow are handled by matching each layout against the |
| 1411 | // data read; among several matches, one followed by a header signature wins. |
| 1412 | private descriptor( |
| 1413 | current: Current |
| 1414 | ): { readonly crc: number; readonly compressedSize: number; readonly size: number } | typeof NeedInput { |
| 1415 | const queue = this.queue |
| 1416 | if (queue.length < DESCRIPTOR_PEEK && !this.ended) return NeedInput |
| 1417 | const bytes = queue.peek(Math.min(queue.length, DESCRIPTOR_PEEK)) |
| 1418 | const view = new DataView(bytes.buffer) |
| 1419 | const candidates: Array<{ length: number; crc: number; compressedSize: number; size: number }> = [] |
| 1420 | const offsets = bytes.length >= 4 && view.getUint32(0, true) === DESCRIPTOR ? [4, 0] : [0] |
| 1421 | for (const offset of offsets) { |
| 1422 | for (const wide of current.zip64 ? [true, false] : [false, true]) { |
| 1423 | const length = offset + (wide ? 20 : 12) |
| 1424 | if (length > bytes.length) continue |
| 1425 | candidates.push({ |
| 1426 | length, |
| 1427 | crc: view.getUint32(offset, true), |
| 1428 | compressedSize: wide ? readUint64(view, offset + 4) : view.getUint32(offset + 4, true), |
| 1429 | size: wide ? readUint64(view, offset + 12) : view.getUint32(offset + 8, true) |
| 1430 | }) |
| 1431 | } |
| 1432 | } |
| 1433 | const matches = candidates.filter((candidate) => |
| 1434 | candidate.crc === current.actualCrc && candidate.compressedSize === current.actualCompressedSize && |
| 1435 | candidate.size === current.actualSize |
| 1436 | ) |
| 1437 | const match = |
| 1438 | matches.find((candidate) => |
| 1439 | candidate.length + 4 <= bytes.length && isHeaderSignature(view.getUint32(candidate.length, true)) |
| 1440 | ) ?? matches[0] |
| 1441 | if (match !== undefined) { |
| 1442 | queue.skip(match.length) |
| 1443 | return match |
| 1444 | } |
| 1445 | // A complete archive has at least an end record after the descriptor |
| 1446 | if (candidates.length === 0 || (this.ended && bytes.length < DESCRIPTOR_PEEK)) { |
| 1447 | throw truncated(queue.consumed + queue.length) |
| 1448 | } |
| 1449 | queue.skip(candidates[0].length) |
| 1450 | return candidates[0] |
| 1451 | } |
| 1452 | |
| 1453 | private parseLocal(bytes: Uint8Array): Current { |
| 1454 | const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.length) |
no test coverage detected