@kirz/expo-content-blocker
Version:
Apply content blocker rules to Safari
44 lines (38 loc) • 1.17 kB
text/typescript
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);
}
}