UNPKG

634 BPlain TextView Raw
1import { exists, readFile, remove } from "fs-promise";
2import { writeFile } from "mz/fs";
3import { IFile } from "./interfaces";
4
5/**
6 *
7 */
8export class FileService {
9
10 /**
11 *
12 * @param file
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}