UNPKG

@metamask/snaps-utils

Version:
26 lines 895 B
import { promises as fsPromises } from "fs"; import { VirtualFile } from "./VirtualFile.mjs"; /** * Reads a file from filesystem and creates a vfile. * * @param path - Filesystem path to load the contents from. * @param encoding - Optional encoding to pass down to fs.readFile. * @returns Promise returning VFile with loaded file contents. */ export async function readVirtualFile(path, encoding = null) { return new VirtualFile({ path, value: await fsPromises.readFile(path, { encoding }), }); } /** * Writes vfile to filesystem. * * @param vfile - The vfile to write. * @param options - Options to pass down to fs.writeFile. * @returns A promise that resolves when the file is written. */ export async function writeVirtualFile(vfile, options) { return fsPromises.writeFile(vfile.path, vfile.value, options); } //# sourceMappingURL=toVirtualFile.mjs.map