mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-13 04:36:12 +01:00
feat: implement all methods
This commit is contained in:
1 parent
f33a73e1bb
commit
9ffc040723
5 files changed
+134
-102
No files matched your search
@@ -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() {}
|
||||
}
|
||||
Reference in new issue
Block a user