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

Method getDirectory

js/src/index.ts:793–821  ·  view source on GitHub ↗
(
    source: Source,
    offset: number,
    length: number,
    header: Header
  )

Source from the content-addressed store, hash-verified

791 }
792
793 async getDirectory(
794 source: Source,
795 offset: number,
796 length: number,
797 header: Header
798 ): Promise<Entry[]> {
799 const cacheKey = `${source.getKey()}|${
800 header.etag || ""
801 }|${offset}|${length}`;
802 const cacheValue = this.cache.get(cacheKey);
803 if (cacheValue) {
804 cacheValue.lastUsed = this.counter++;
805 const data = await cacheValue.data;
806 return data as Entry[];
807 }
808
809 const p = new Promise<Entry[]>((resolve, reject) => {
810 getDirectory(source, this.decompress, offset, length, header)
811 .then((directory) => {
812 resolve(directory);
813 this.prune();
814 })
815 .catch((e) => {
816 reject(e);
817 });
818 });
819 this.cache.set(cacheKey, { lastUsed: this.counter++, data: p });
820 return p;
821 }
822
823 prune() {
824 if (this.cache.size >= this.maxCacheEntries) {

Callers

nothing calls this directly

Calls 4

pruneMethod · 0.95
getDirectoryFunction · 0.85
getKeyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected