silverbullet/syscall/plugos-syscall/fs.ts

37 lines
862 B
TypeScript
Raw Normal View History

2022-10-04 22:33:29 +08:00
import { syscall } from "./syscall.ts";
export type FileMeta = {
name: string;
lastModified: number;
};
export async function readFile(
2022-09-05 22:15:01 +08:00
path: string,
2022-10-08 22:29:43 +08:00
encoding: "utf8" | "dataurl" = "utf8",
): Promise<{ text: string; meta: FileMeta }> {
2022-09-05 22:15:01 +08:00
return syscall("fs.readFile", path, encoding);
}
export async function getFileMeta(path: string): Promise<FileMeta> {
return syscall("fs.getFileMeta", path);
}
2022-09-05 22:15:01 +08:00
export async function writeFile(
path: string,
text: string,
2022-10-08 22:29:43 +08:00
encoding: "utf8" | "dataurl" = "utf8",
2022-09-05 22:15:01 +08:00
): Promise<FileMeta> {
return syscall("fs.writeFile", path, text, encoding);
}
export async function deleteFile(path: string): Promise<void> {
return syscall("fs.deleteFile", path);
}
export async function listFiles(
dirName: string,
2022-10-08 22:29:43 +08:00
recursive = false,
): Promise<FileMeta[]> {
return syscall("fs.listFiles", dirName, recursive);
}