2023-03-18 21:37:34 +00:00
|
|
|
import fs from 'fs';
|
|
|
|
|
|
|
|
export default class LocalFile {
|
2023-10-06 12:41:29 +00:00
|
|
|
public static async makeDirectory(path: string): Promise<void> {
|
|
|
|
return new Promise((resolve: Function, reject: Function) => {
|
|
|
|
fs.mkdir(path, { recursive: true }, (err: unknown) => {
|
|
|
|
if (err) {
|
|
|
|
return reject(err);
|
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public static async write(path: string, data: string): Promise<void> {
|
|
|
|
return new Promise((resolve: Function, reject: Function) => {
|
|
|
|
fs.writeFile(path, data, (err: unknown) => {
|
|
|
|
if (err) {
|
|
|
|
return reject();
|
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-18 21:37:34 +00:00
|
|
|
public static async read(path: string): Promise<string> {
|
2023-03-18 21:48:21 +00:00
|
|
|
return new Promise(
|
|
|
|
(resolve: (data: string) => void, reject: Function) => {
|
2023-03-20 18:06:50 +00:00
|
|
|
fs.readFile(
|
2023-03-18 21:48:21 +00:00
|
|
|
path,
|
|
|
|
{ encoding: 'utf-8' },
|
|
|
|
(err: unknown, data: string) => {
|
|
|
|
if (!err) {
|
|
|
|
return resolve(data);
|
|
|
|
}
|
|
|
|
return reject(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
2023-03-18 21:37:34 +00:00
|
|
|
}
|
2023-03-18 21:48:21 +00:00
|
|
|
}
|