js: export more classes, root_entries list method

This commit is contained in:
Brandon Liu
2022-06-01 10:10:41 +08:00
parent bd64156412
commit 6018d3d547

View File

@@ -225,7 +225,7 @@ export interface Source {
getKey: () => string; getKey: () => string;
} }
class FileSource implements Source { export class FileSource implements Source {
file: File; file: File;
constructor(file: File) { constructor(file: File) {
@@ -243,7 +243,7 @@ class FileSource implements Source {
} }
} }
class FetchSource implements Source { export class FetchSource implements Source {
url: string; url: string;
constructor(url: string) { constructor(url: string) {
@@ -279,7 +279,7 @@ interface CacheEntry {
buffer: Promise<DataView>; buffer: Promise<DataView>;
} }
class LRUCacheSource implements Source { export class LRUCacheSource implements Source {
entries: Map<number, CacheEntry>; entries: Map<number, CacheEntry>;
maxEntries: number; maxEntries: number;
source: Source; source: Source;
@@ -327,7 +327,7 @@ class LRUCacheSource implements Source {
export class PMTiles { export class PMTiles {
source: Source; source: Source;
constructor(source: any, maxLeaves = 64) { constructor(source: string | Source, maxLeaves = 64) {
if (typeof source === "string") { if (typeof source === "string") {
this.source = new LRUCacheSource(new FetchSource(source), maxLeaves); this.source = new LRUCacheSource(new FetchSource(source), maxLeaves);
} else { } else {
@@ -356,6 +356,15 @@ export class PMTiles {
}; };
} }
async root_entries(): Promise<Entry[]> {
const root = await this.fetchRoot();
let entries = [];
for (var i = 0; i < root.header.root_entries; i++) {
entries.push(parseEntry(root.dir,i));
}
return entries;
}
async metadata(): Promise<any> { async metadata(): Promise<any> {
const root = await this.fetchRoot(); const root = await this.fetchRoot();
const dec = new TextDecoder("utf-8"); const dec = new TextDecoder("utf-8");