53 lines
1.2 kB
1
import type { MoonlightFS } from "@moonlight-mod/types";
2
import requireImport from "./util/import";
3
4
export 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
async isDir(path) {
43
return fs.statSync(path).isDirectory();
44
},
45
46
join(...parts) {
47
return path.join(...parts);
48
},
49
dirname(dir) {
50
return path.dirname(dir);
51
}
52
};
53
}
54