Files
blitzkit/packages/scripts/src/core/vfs/zip.ts
T

38 lines
892 B
TypeScript
Raw Normal View History

2025-11-29 15:16:09 -06:00
import { normalize } from "path/posix";
2025-11-29 14:34:06 -06:00
import { HTTPRangeReader, unzip, ZipEntry } from "unzipit";
import { AbstractVFS } from "./abstract";
export class ZipVFS extends AbstractVFS {
2025-11-29 15:16:09 -06:00
entries = new Map<string, ZipEntry>();
2025-11-29 14:34:06 -06:00
constructor(private url: string, private root = "app/") {
super();
}
async init() {
const reader = new HTTPRangeReader(this.url);
const { entries } = await unzip(reader);
for (const entry of Object.values(entries)) {
2025-11-29 15:16:09 -06:00
const normalized = normalize(entry.name.slice(this.root.length));
this.entries.set(normalized, entry);
2025-11-29 14:34:06 -06:00
}
return this;
}
2025-11-29 15:16:09 -06:00
has(path: string) {
return path in this.entries;
}
async raw(path: string) {
const arrayBuffer = await this.entries.get(path)!.arrayBuffer();
return new Uint8Array(arrayBuffer);
}
paths() {
return Array.from(this.entries.keys());
}
dispose() {}
2025-11-29 14:34:06 -06:00
}