(
source: Source,
offset: number,
length: number,
header: Header
)
| 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) { |
nothing calls this directly
no test coverage detected