UNPKG

@kirz/expo-content-blocker

Version:
44 lines (38 loc) 1.17 kB
import * as fs from "fs"; import { BlockerProviderLog } from "./BlockerProviderLog.ts"; /** * FileManager contains static *awaitable* file-system functions */ export class FileManager { static async readFile(path: string): Promise<string> { return new Promise<string>((resolve, reject) => { fs.readFile(path, "utf8", (err, data) => { if (err || !data) { BlockerProviderLog.error("Couldn't read file:" + path); reject(err); return; } resolve(data); }); }); } static async writeFile(path: string, contents: string): Promise<void> { return new Promise<void>((resolve, reject) => { fs.writeFile(path, contents, "utf8", (err) => { if (err) { BlockerProviderLog.error("Couldn't write file:" + path); reject(err); return; } resolve(); }); }); } static async copyFile(path1: string, path2: string): Promise<void> { const fileContents = await FileManager.readFile(path1); await FileManager.writeFile(path2, fileContents); } static dirExists(path: string): boolean { return fs.existsSync(path); } }