1 | import { exists, readFile, remove } from "fs-promise";
|
2 | import { writeFile } from "mz/fs";
|
3 | import { IFile } from "./interfaces";
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export class FileService {
|
9 |
|
10 | |
11 |
|
12 |
|
13 |
|
14 | public async exists(file: IFile): Promise<boolean> {
|
15 | return await exists(file.path);
|
16 | }
|
17 |
|
18 | public async read(file: IFile, encoding: string = "UTF-8"): Promise<string> {
|
19 | return await readFile(file.path, {encoding});
|
20 | }
|
21 |
|
22 | public async write(file: IFile, data: string, encoding?: string) {
|
23 | await writeFile(file.path, data, encoding);
|
24 | }
|
25 |
|
26 | public async remove(file: IFile) {
|
27 | return await remove(file.path);
|
28 | }
|
29 | }
|