UNPKG

2.14 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var fs_promise_1 = require("fs-promise");
4var fs_1 = require("mz/fs");
5/**
6 *
7 */
8var FileService = (function () {
9 function FileService() {
10 }
11 /**
12 *
13 * @param file
14 */
15 FileService.prototype.exists = function (file) {
16 return __awaiter(this, void 0, void 0, function () {
17 return __generator(this, function (_a) {
18 switch (_a.label) {
19 case 0: return [4 /*yield*/, fs_promise_1.exists(file.path)];
20 case 1: return [2 /*return*/, _a.sent()];
21 }
22 });
23 });
24 };
25 FileService.prototype.read = function (file, encoding) {
26 if (encoding === void 0) { encoding = "UTF-8"; }
27 return __awaiter(this, void 0, void 0, function () {
28 return __generator(this, function (_a) {
29 switch (_a.label) {
30 case 0: return [4 /*yield*/, fs_promise_1.readFile(file.path, { encoding: encoding })];
31 case 1: return [2 /*return*/, _a.sent()];
32 }
33 });
34 });
35 };
36 FileService.prototype.write = function (file, data, encoding) {
37 return __awaiter(this, void 0, void 0, function () {
38 return __generator(this, function (_a) {
39 switch (_a.label) {
40 case 0: return [4 /*yield*/, fs_1.writeFile(file.path, data, encoding)];
41 case 1:
42 _a.sent();
43 return [2 /*return*/];
44 }
45 });
46 });
47 };
48 FileService.prototype.remove = function (file) {
49 return __awaiter(this, void 0, void 0, function () {
50 return __generator(this, function (_a) {
51 switch (_a.label) {
52 case 0: return [4 /*yield*/, fs_promise_1.remove(file.path)];
53 case 1: return [2 /*return*/, _a.sent()];
54 }
55 });
56 });
57 };
58 return FileService;
59}());
60exports.FileService = FileService;
61//# sourceMappingURL=FileService.js.map
\No newline at end of file