MCPcopy Index your code
hub / github.com/protomaps/PMTiles / getHeader

Method getHeader

js/src/index.ts:764–791  ·  view source on GitHub ↗
(source: Source)

Source from the content-addressed store, hash-verified

762 }
763
764 async getHeader(source: Source): Promise<Header> {
765 const cacheKey = source.getKey();
766 const cacheValue = this.cache.get(cacheKey);
767 if (cacheValue) {
768 cacheValue.lastUsed = this.counter++;
769 const data = await cacheValue.data;
770 return data as Header;
771 }
772
773 const p = new Promise<Header>((resolve, reject) => {
774 getHeaderAndRoot(source, this.decompress)
775 .then((res) => {
776 if (res[1]) {
777 this.cache.set(res[1][0], {
778 lastUsed: this.counter++,
779 data: Promise.resolve(res[1][2]),
780 });
781 }
782 resolve(res[0]);
783 this.prune();
784 })
785 .catch((e) => {
786 reject(e);
787 });
788 });
789 this.cache.set(cacheKey, { lastUsed: this.counter++, data: p });
790 return p;
791 }
792
793 async getDirectory(
794 source: Source,

Callers 1

invalidateMethod · 0.95

Calls 4

pruneMethod · 0.95
getHeaderAndRootFunction · 0.85
getKeyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected