MCPcopy Create free account
hub / github.com/protomaps/PMTiles / getHeaderAndRoot

Function getHeaderAndRoot

js/src/index.ts:581–610  ·  view source on GitHub ↗
(
  source: Source,
  decompress: DecompressFunc
)

Source from the content-addressed store, hash-verified

579}
580
581async 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
612async function getDirectory(
613 source: Source,

Callers 2

getHeaderMethod · 0.85
getHeaderMethod · 0.85

Calls 4

bytesToHeaderFunction · 0.85
deserializeIndexFunction · 0.85
getBytesMethod · 0.45
getKeyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…