( source: Source, decompress: DecompressFunc )
| 579 | } |
| 580 | |
| 581 | async function getHeaderAndRoot( |
| 582 | source: Source, |
| 583 | decompress: DecompressFunc |
| 584 | ): Promise<[Header, [string, number, Entry[] | ArrayBuffer]?]> { |
| 585 | const resp = await source.getBytes(0, 16384); |
| 586 | |
| 587 | const v = new DataView(resp.data); |
| 588 | if (v.getUint16(0, true) !== 0x4d50) { |
| 589 | throw new Error("Wrong magic number for PMTiles archive"); |
| 590 | } |
| 591 | |
| 592 | const headerData = resp.data.slice(0, HEADER_SIZE_BYTES); |
| 593 | |
| 594 | const header = bytesToHeader(headerData, resp.etag); |
| 595 | |
| 596 | // optimistically set the root directory |
| 597 | // TODO check root bounds |
| 598 | const rootDirData = resp.data.slice( |
| 599 | header.rootDirectoryOffset, |
| 600 | header.rootDirectoryOffset + header.rootDirectoryLength |
| 601 | ); |
| 602 | const dirKey = `${source.getKey()}|${header.etag || ""}|${ |
| 603 | header.rootDirectoryOffset |
| 604 | }|${header.rootDirectoryLength}`; |
| 605 | |
| 606 | const rootDir = deserializeIndex( |
| 607 | await decompress(rootDirData, header.internalCompression) |
| 608 | ); |
| 609 | return [header, [dirKey, rootDir.length, rootDir]]; |
| 610 | } |
| 611 | |
| 612 | async function getDirectory( |
| 613 | source: Source, |
no test coverage detected
searching dependent graphs…