2026-08-30 14:36:51 -05:00
|
|
|
import type { readdir } from "node:fs/promises";
|
2026-04-01 21:34:44 -05:00
|
|
|
import { AbstractVFS } from "./abstract";
|
|
|
|
|
|
|
|
|
|
export class LocalVFS extends AbstractVFS {
|
2026-08-30 14:36:51 -05:00
|
|
|
protected readdir?: typeof readdir;
|
|
|
|
|
|
2026-04-01 21:34:44 -05:00
|
|
|
constructor(private base: string) {
|
|
|
|
|
super();
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-30 14:36:51 -05:00
|
|
|
async _init() {
|
|
|
|
|
const path = await import("node:path/posix");
|
2026-08-30 14:56:24 -05:00
|
|
|
const fs = await import("node:fs/promises");
|
|
|
|
|
|
2026-08-30 14:36:51 -05:00
|
|
|
this.normalizePath = path.normalize;
|
2026-08-30 14:56:24 -05:00
|
|
|
this.readdir = fs.readdir;
|
2026-08-30 14:36:51 -05:00
|
|
|
|
2026-04-01 21:34:44 -05:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-11 09:45:17 -05:00
|
|
|
async _dir(path: string) {
|
2026-07-31 11:07:54 -05:00
|
|
|
try {
|
2026-08-30 14:36:51 -05:00
|
|
|
return await this.readdir!(`${this.base}/${path}`);
|
2026-07-31 11:07:54 -05:00
|
|
|
} catch (_) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
2026-04-01 21:34:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dispose() {}
|
|
|
|
|
}
|