feat: implement all methods

This commit is contained in:
TrèsAbhi committed 2025-11-29 15:16:09 -06:00
1 parent f33a73e1bb
commit 9ffc040723
5 files changed
+134 -102

No files matched your search

+19 -2
View File
@@ -1,8 +1,9 @@
import { normalize } from "path/posix";
import { HTTPRangeReader, unzip, ZipEntry } from "unzipit";
import { AbstractVFS } from "./abstract";
export class ZipVFS extends AbstractVFS {
entries: Record<string, ZipEntry> = {};
entries = new Map<string, ZipEntry>();
constructor(private url: string, private root = "app/") {
super();
@@ -13,9 +14,25 @@ export class ZipVFS extends AbstractVFS {
const { entries } = await unzip(reader);
for (const entry of Object.values(entries)) {
this.entries[entry.name.slice(this.root.length)] = entry;
const normalized = normalize(entry.name.slice(this.root.length));
this.entries.set(normalized, entry);
}
return this;
}
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() {}
}