mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-29 04:44:23 +01:00
move to vfs package
This commit is contained in:
49 files changed
+125
-96
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import type { readdir } from "node:fs/promises";
|
||||
import { AbstractVFS } from "./abstract";
|
||||
|
||||
export class LocalVFS extends AbstractVFS {
|
||||
protected readdir?: typeof readdir;
|
||||
|
||||
constructor(private base: string) {
|
||||
super();
|
||||
}
|
||||
|
||||
async _init() {
|
||||
const path = await import("node:path/posix");
|
||||
const fs = await import("node:fs/promises");
|
||||
|
||||
this.normalizePath = path.normalize;
|
||||
this.readdir = fs.readdir;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
async has(path: string) {
|
||||
const file = Bun.file(`${this.base}/${path}`);
|
||||
return await file.exists();
|
||||
}
|
||||
|
||||
async raw(path: string) {
|
||||
const file = Bun.file(`${this.base}/${path}`);
|
||||
const buffer = await file.arrayBuffer();
|
||||
const array = new Uint8Array(buffer);
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
async _dir(path: string) {
|
||||
try {
|
||||
return await this.readdir!(`${this.base}/${path}`);
|
||||
} catch (_) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
dispose() {}
|
||||
}
|
||||
Reference in new issue
Block a user