1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | return new (P || (P = Promise))(function (resolve, reject) {
|
4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5 | function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
|
6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
7 | step((generator = generator.apply(thisArg, _arguments)).next());
|
8 | });
|
9 | };
|
10 | var fs = require('fs');
|
11 | function access(path, mode) {
|
12 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.access, arguments); });
|
13 | }
|
14 | exports.access = access;
|
15 | function appendFile(filename, data, options) {
|
16 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.appendFile, arguments); });
|
17 | }
|
18 | exports.appendFile = appendFile;
|
19 | function chmod(path, mode) {
|
20 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.chmod, arguments); });
|
21 | }
|
22 | exports.chmod = chmod;
|
23 | function chown(path, uid, gid) {
|
24 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.chown, arguments); });
|
25 | }
|
26 | exports.chown = chown;
|
27 | function close(fd) {
|
28 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.close, arguments); });
|
29 | }
|
30 | exports.close = close;
|
31 | function fchmod(fd, mode) {
|
32 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.fchmod, arguments); });
|
33 | }
|
34 | exports.fchmod = fchmod;
|
35 | function fchown(fd, uid, gid) {
|
36 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.fchown, arguments); });
|
37 | }
|
38 | exports.fchown = fchown;
|
39 | function fstat(fd) {
|
40 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.fstat, arguments); });
|
41 | }
|
42 | exports.fstat = fstat;
|
43 | function ftruncate(fd, len) {
|
44 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.ftruncate, arguments); });
|
45 | }
|
46 | exports.ftruncate = ftruncate;
|
47 | function futimes(fd, atime, mtime) {
|
48 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.futimes, arguments); });
|
49 | }
|
50 | exports.futimes = futimes;
|
51 | function fsync(fd) {
|
52 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.fsync, arguments); });
|
53 | }
|
54 | exports.fsync = fsync;
|
55 | function lchmod(path, mode) {
|
56 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.lchmod, arguments); });
|
57 | }
|
58 | exports.lchmod = lchmod;
|
59 | function lchown(path, uid, gid) {
|
60 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.lchown, arguments); });
|
61 | }
|
62 | exports.lchown = lchown;
|
63 | function link(srcpath, dstpath) {
|
64 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.link, arguments); });
|
65 | }
|
66 | exports.link = link;
|
67 | function lstat(path) {
|
68 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.lstat, arguments); });
|
69 | }
|
70 | exports.lstat = lstat;
|
71 | function mkdir(path, mode) {
|
72 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.mkdir, arguments); });
|
73 | }
|
74 | exports.mkdir = mkdir;
|
75 | function open(path, flags, mode) {
|
76 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.open, arguments); });
|
77 | }
|
78 | exports.open = open;
|
79 | function read(fd, buffer, offset, length, position) {
|
80 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.read, arguments, null, function () { return { bytesRead: arguments[1], buffer: arguments[2] }; }); });
|
81 | }
|
82 | exports.read = read;
|
83 | function readdir(path) {
|
84 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.readdir, arguments); });
|
85 | }
|
86 | exports.readdir = readdir;
|
87 | function readFile(file, options) {
|
88 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.readFile, arguments); });
|
89 | }
|
90 | exports.readFile = readFile;
|
91 | function readlink(path) {
|
92 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.readlink, arguments); });
|
93 | }
|
94 | exports.readlink = readlink;
|
95 | function realpath(path, cache) {
|
96 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.realpath, arguments); });
|
97 | }
|
98 | exports.realpath = realpath;
|
99 | function rename(oldPath, newPath) {
|
100 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.rename, arguments); });
|
101 | }
|
102 | exports.rename = rename;
|
103 | function rmdir(path) {
|
104 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.rmdir, arguments); });
|
105 | }
|
106 | exports.rmdir = rmdir;
|
107 | function stat(path) {
|
108 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.stat, arguments); });
|
109 | }
|
110 | exports.stat = stat;
|
111 | function symlink(srcpath, dstpath, type) {
|
112 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.symlink, arguments); });
|
113 | }
|
114 | exports.symlink = symlink;
|
115 | function truncate(path, len) {
|
116 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.truncate, arguments); });
|
117 | }
|
118 | exports.truncate = truncate;
|
119 | function unlink(path) {
|
120 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.unlink, arguments); });
|
121 | }
|
122 | exports.unlink = unlink;
|
123 | function utimes(path, atime, mtime) {
|
124 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.utimes, arguments); });
|
125 | }
|
126 | exports.utimes = utimes;
|
127 | function write(fd, buffer, offset, length, position) {
|
128 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.write, arguments, null, function () { return { written: arguments[1], buffer: arguments[2] }; }); });
|
129 | }
|
130 | exports.write = write;
|
131 | function writeFile(file, data, options) {
|
132 | return __awaiter(this, arguments, void 0, function* () { return thunk(fs.writeFile, arguments); });
|
133 | }
|
134 | exports.writeFile = writeFile;
|
135 | (function (Encoding) {
|
136 | Encoding[Encoding["ascii"] = 0] = "ascii";
|
137 | Encoding[Encoding["base64"] = 1] = "base64";
|
138 | Encoding[Encoding["binary"] = 2] = "binary";
|
139 | Encoding[Encoding["hex"] = 3] = "hex";
|
140 | Encoding[Encoding["ucs2"] = 4] = "ucs2";
|
141 | Encoding[Encoding["utf16le"] = 5] = "utf16le";
|
142 | Encoding[Encoding["utf8"] = 6] = "utf8";
|
143 | })(exports.Encoding || (exports.Encoding = {}));
|
144 | var Encoding = exports.Encoding;
|
145 | (function (OpenFlags) {
|
146 | OpenFlags[OpenFlags["read"] = 0] = "read";
|
147 | OpenFlags[OpenFlags["readWrite"] = 1] = "readWrite";
|
148 | OpenFlags[OpenFlags["readSync"] = 2] = "readSync";
|
149 | OpenFlags[OpenFlags["readWriteSync"] = 3] = "readWriteSync";
|
150 | OpenFlags[OpenFlags["write"] = 4] = "write";
|
151 | OpenFlags[OpenFlags["writeNoOverwrite"] = 5] = "writeNoOverwrite";
|
152 | OpenFlags[OpenFlags["create"] = 6] = "create";
|
153 | OpenFlags[OpenFlags["createNoOverwrite"] = 7] = "createNoOverwrite";
|
154 | OpenFlags[OpenFlags["append"] = 8] = "append";
|
155 | OpenFlags[OpenFlags["appendNoOverwrite"] = 9] = "appendNoOverwrite";
|
156 | OpenFlags[OpenFlags["appendRead"] = 10] = "appendRead";
|
157 | OpenFlags[OpenFlags["appendReadNoOverwrite"] = 11] = "appendReadNoOverwrite";
|
158 | })(exports.OpenFlags || (exports.OpenFlags = {}));
|
159 | var OpenFlags = exports.OpenFlags;
|
160 | var openFlags = {};
|
161 | openFlags[OpenFlags.read] = 'r';
|
162 | openFlags[OpenFlags.readWrite] = 'r+';
|
163 | openFlags[OpenFlags.readSync] = 'rs';
|
164 | openFlags[OpenFlags.readWriteSync] = 'rs+';
|
165 | openFlags[OpenFlags.write] = 'w';
|
166 | openFlags[OpenFlags.writeNoOverwrite] = 'wx';
|
167 | openFlags[OpenFlags.create] = 'w+';
|
168 | openFlags[OpenFlags.createNoOverwrite] = 'wx+';
|
169 | openFlags[OpenFlags.append] = 'a';
|
170 | openFlags[OpenFlags.appendNoOverwrite] = 'ax';
|
171 | openFlags[OpenFlags.appendRead] = 'a+';
|
172 | openFlags[OpenFlags.appendReadNoOverwrite] = 'ax+';
|
173 | function readTextFile(file, encoding, flags) {
|
174 | return __awaiter(this, void 0, void 0, function* () {
|
175 | if (flags === undefined || flags === null)
|
176 | flags = OpenFlags.read;
|
177 | return thunk(fs.readFile, [file, createOptions(encoding, flags)]);
|
178 | });
|
179 | }
|
180 | exports.readTextFile = readTextFile;
|
181 | function writeTextFile(file, data, encoding, flags, mode) {
|
182 | return __awaiter(this, void 0, void 0, function* () {
|
183 | if (flags === undefined || flags === null)
|
184 | flags = OpenFlags.write;
|
185 | return thunk(fs.writeFile, [file, data, createOptions(encoding, flags, mode)]);
|
186 | });
|
187 | }
|
188 | exports.writeTextFile = writeTextFile;
|
189 | function createOptions(encoding, flags, mode) {
|
190 | var options = {};
|
191 | if (encoding === undefined || encoding === null)
|
192 | encoding = Encoding.utf8;
|
193 | if (typeof encoding === 'number')
|
194 | options.encoding = Encoding[encoding];
|
195 | else if (typeof encoding === 'string')
|
196 | options.encoding = encoding;
|
197 | if (typeof flags === 'number')
|
198 | options.flags = openFlags[flags];
|
199 | else if (typeof flags === 'string')
|
200 | options.flags = flags;
|
201 | if (mode)
|
202 | options.mode = mode;
|
203 | return options;
|
204 | }
|
205 | function exists(path) {
|
206 | return __awaiter(this, void 0, void 0, function* () {
|
207 | try {
|
208 | yield stat(path);
|
209 | return true;
|
210 | }
|
211 | catch (err) {
|
212 | if (err.code === 'ENOENT')
|
213 | return false;
|
214 | else
|
215 | throw err;
|
216 | }
|
217 | });
|
218 | }
|
219 | exports.exists = exists;
|
220 | function thunk(target, args, context, resolver) {
|
221 | return new Promise((resolve, reject) => {
|
222 | target.apply(context, Array.prototype.slice.call(args).concat([(err, result) => {
|
223 | if (err)
|
224 | reject(err);
|
225 | else if (resolver)
|
226 | resolver.apply(context, arguments);
|
227 | else
|
228 | resolve(result);
|
229 | }]));
|
230 | });
|
231 | }
|
232 | exports.thunk = thunk;
|
233 |
|
\ | No newline at end of file |