2022-10-10 12:50:21 +00:00
|
|
|
import { syscall } from "./syscall.ts";
|
2022-07-06 10:17:42 +00:00
|
|
|
|
|
|
|
export type FileMeta = {
|
|
|
|
name: string;
|
|
|
|
lastModified: number;
|
|
|
|
};
|
|
|
|
|
2022-10-10 12:50:21 +00:00
|
|
|
export function readFile(
|
2022-09-05 14:15:01 +00:00
|
|
|
path: string,
|
2022-10-10 12:50:21 +00:00
|
|
|
encoding: "utf8" | "dataurl" = "utf8",
|
2022-10-14 13:11:33 +00:00
|
|
|
): Promise<string> {
|
2022-09-05 14:15:01 +00:00
|
|
|
return syscall("fs.readFile", path, encoding);
|
2022-07-06 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
2022-10-10 12:50:21 +00:00
|
|
|
export function getFileMeta(path: string): Promise<FileMeta> {
|
2022-07-06 10:17:42 +00:00
|
|
|
return syscall("fs.getFileMeta", path);
|
|
|
|
}
|
|
|
|
|
2022-10-10 12:50:21 +00:00
|
|
|
export function writeFile(
|
2022-09-05 14:15:01 +00:00
|
|
|
path: string,
|
|
|
|
text: string,
|
2022-10-10 12:50:21 +00:00
|
|
|
encoding: "utf8" | "dataurl" = "utf8",
|
2022-09-05 14:15:01 +00:00
|
|
|
): Promise<FileMeta> {
|
|
|
|
return syscall("fs.writeFile", path, text, encoding);
|
2022-07-06 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
2022-10-10 12:50:21 +00:00
|
|
|
export function deleteFile(path: string): Promise<void> {
|
2022-07-06 10:17:42 +00:00
|
|
|
return syscall("fs.deleteFile", path);
|
|
|
|
}
|
|
|
|
|
2022-10-10 12:50:21 +00:00
|
|
|
export function listFiles(
|
2022-07-06 10:17:42 +00:00
|
|
|
dirName: string,
|
2022-10-10 12:50:21 +00:00
|
|
|
recursive = false,
|
2022-07-06 10:17:42 +00:00
|
|
|
): Promise<FileMeta[]> {
|
|
|
|
return syscall("fs.listFiles", dirName, recursive);
|
|
|
|
}
|