mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-29 04:44:23 +01:00
44 lines
910 B
TypeScript
44 lines
910 B
TypeScript
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() {}
|
|
}
|