this repo has no description
1import type { MoonlightFS } from "@moonlight-mod/types";
2import requireImport from "./util/import";
3
4export default function createFS(): MoonlightFS {
5 const fs = requireImport("fs");
6 const path = requireImport("path");
7
8 return {
9 async readFile(path) {
10 const file = fs.readFileSync(path);
11 return new Uint8Array(file);
12 },
13 async readFileString(path) {
14 return fs.readFileSync(path, "utf8");
15 },
16 async writeFile(path, data) {
17 fs.writeFileSync(path, Buffer.from(data));
18 },
19 async writeFileString(path, data) {
20 fs.writeFileSync(path, data, "utf8");
21 },
22 async unlink(path) {
23 fs.unlinkSync(path);
24 },
25
26 async readdir(path) {
27 return fs.readdirSync(path);
28 },
29 async mkdir(path) {
30 fs.mkdirSync(path, { recursive: true });
31 },
32 async rmdir(path) {
33 fs.rmSync(path, { recursive: true });
34 },
35
36 async exists(path) {
37 return fs.existsSync(path);
38 },
39 async isFile(path) {
40 return fs.statSync(path).isFile();
41 },
42
43 join(...parts) {
44 return path.join(...parts);
45 },
46 dirname(dir) {
47 return path.dirname(dir);
48 }
49 };
50}