1 | "use strict";
|
2 | const fs = require('fs');
|
3 | const pathutil = require('path');
|
4 | const rimraf = require('rimraf');
|
5 | var fs_1 = require('fs');
|
6 | exports.createReadStream = fs_1.createReadStream;
|
7 | exports.createWriteStream = fs_1.createWriteStream;
|
8 | exports.watch = fs_1.watch;
|
9 | exports.watchFile = fs_1.watchFile;
|
10 | exports.unwatchFile = fs_1.unwatchFile;
|
11 | exports.F_OK = fs_1.F_OK;
|
12 | exports.R_OK = fs_1.R_OK;
|
13 | exports.W_OK = fs_1.W_OK;
|
14 | exports.X_OK = fs_1.X_OK;
|
15 | function access(path, mode) { return thunk(fs.access, arguments); }
|
16 | exports.access = access;
|
17 | function appendFile(file, data, options) { return thunk(fs.appendFile, arguments); }
|
18 | exports.appendFile = appendFile;
|
19 | function chmod(path, mode) { return thunk(fs.chmod, arguments); }
|
20 | exports.chmod = chmod;
|
21 | function chown(path, uid, gid) { return thunk(fs.chown, arguments); }
|
22 | exports.chown = chown;
|
23 | function close(fd) { return thunk(fs.close, arguments); }
|
24 | exports.close = close;
|
25 | function fchmod(fd, mode) { return thunk(fs.fchmod, arguments); }
|
26 | exports.fchmod = fchmod;
|
27 | function fchown(fd, uid, gid) { return thunk(fs.fchown, arguments); }
|
28 | exports.fchown = fchown;
|
29 | function fstat(fd) { return thunk(fs.fstat, arguments); }
|
30 | exports.fstat = fstat;
|
31 | function ftruncate(fd, len) { return thunk(fs.ftruncate, arguments); }
|
32 | exports.ftruncate = ftruncate;
|
33 | function futimes(fd, atime, mtime) { return thunk(fs.futimes, arguments); }
|
34 | exports.futimes = futimes;
|
35 | function fsync(fd) { return thunk(fs.fsync, arguments); }
|
36 | exports.fsync = fsync;
|
37 | function lchmod(path, mode) { return thunk(fs.lchmod, arguments); }
|
38 | exports.lchmod = lchmod;
|
39 | function lchown(path, uid, gid) { return thunk(fs.lchown, arguments); }
|
40 | exports.lchown = lchown;
|
41 | function link(srcpath, dstpath) { return thunk(fs.link, arguments); }
|
42 | exports.link = link;
|
43 | function lstat(path) { return thunk(fs.lstat, arguments); }
|
44 | exports.lstat = lstat;
|
45 | function mkdir(path, mode) { return thunk(fs.mkdir, arguments); }
|
46 | exports.mkdir = mkdir;
|
47 | function mkdtemp(path) { return thunk(fs.mkdtemp, arguments); }
|
48 | exports.mkdtemp = mkdtemp;
|
49 | function open(path, flags, mode) { return thunk(fs.open, arguments); }
|
50 | exports.open = open;
|
51 | function read(fd, buffer, offset, length, position) { return thunk(fs.read, arguments, null, function () { return { bytesRead: arguments[1], buffer: arguments[2] }; }); }
|
52 | exports.read = read;
|
53 | function readdir(path) { return thunk(fs.readdir, arguments); }
|
54 | exports.readdir = readdir;
|
55 | function readFile(file, options) { return thunk(fs.readFile, arguments); }
|
56 | exports.readFile = readFile;
|
57 | function readlink(path) { return thunk(fs.readlink, arguments); }
|
58 | exports.readlink = readlink;
|
59 | function realpath(path, cache) { return thunk(fs.realpath, arguments); }
|
60 | exports.realpath = realpath;
|
61 | function rename(oldPath, newPath) { return thunk(fs.rename, arguments); }
|
62 | exports.rename = rename;
|
63 | function rmdir(path) { return thunk(fs.rmdir, arguments); }
|
64 | exports.rmdir = rmdir;
|
65 | function stat(path) { return thunk(fs.stat, arguments); }
|
66 | exports.stat = stat;
|
67 | function symlink(srcpath, dstpath, type) { return thunk(fs.symlink, arguments); }
|
68 | exports.symlink = symlink;
|
69 | function truncate(path, len) { return thunk(fs.truncate, arguments); }
|
70 | exports.truncate = truncate;
|
71 | function unlink(path) { return thunk(fs.unlink, arguments); }
|
72 | exports.unlink = unlink;
|
73 | function utimes(path, atime, mtime) { return thunk(fs.utimes, arguments); }
|
74 | exports.utimes = utimes;
|
75 | function write(fd) { return thunk(fs.write, arguments, null, function () { return { written: arguments[1], buffer: arguments[2] }; }); }
|
76 | exports.write = write;
|
77 | function writeFile(file, data, options) { return thunk(fs.writeFile, arguments); }
|
78 | exports.writeFile = writeFile;
|
79 | function readTextFile(file, encoding, flags) {
|
80 | if (encoding === undefined)
|
81 | encoding = 'utf8';
|
82 | if (flags === undefined || flags === null)
|
83 | flags = 'r';
|
84 | return thunk(fs.readFile, [file, { encoding: encoding, flags: flags }]);
|
85 | }
|
86 | exports.readTextFile = readTextFile;
|
87 | function writeTextFile(file, data, encoding, flags, mode) {
|
88 | if (encoding === undefined)
|
89 | encoding = 'utf8';
|
90 | if (flags === undefined || flags === null || flags === '')
|
91 | flags = 'w';
|
92 | var options = { encoding: encoding, flags: flags, mode: mode };
|
93 | if (flags[0] === 'a')
|
94 | return thunk(fs.appendFile, [file, data, options]);
|
95 | else
|
96 | return thunk(fs.writeFile, [file, data, options]);
|
97 | }
|
98 | exports.writeTextFile = writeTextFile;
|
99 | function createDirectory(path, mode) {
|
100 | return new Promise((resolve, reject) => mkdirp(path, mode, err => !err ? resolve() : reject(err)));
|
101 | }
|
102 | exports.createDirectory = createDirectory;
|
103 | exports.mkdirp = createDirectory;
|
104 | function del(path) {
|
105 | return new Promise((resolve, reject) => rimraf(path, err => !err ? resolve() : reject(err)));
|
106 | }
|
107 | exports.delete = del;
|
108 | exports.rimraf = del;
|
109 | function exists(path) {
|
110 | return new Promise((resolve, reject) => fs.lstat(path, (err) => !err ? resolve(true) : err.code === 'ENOENT' ? resolve(false) : reject(err)));
|
111 | }
|
112 | exports.exists = exists;
|
113 | function mkdirp(path, mode, done) {
|
114 | path = pathutil.resolve(path);
|
115 | fs.mkdir(path, mode, (err) => {
|
116 | if (!err)
|
117 | done(null);
|
118 | else if (err.code === 'ENOENT')
|
119 | mkdirp(pathutil.dirname(path), mode, err => !err ? mkdirp(path, mode, done) : done(err));
|
120 | else
|
121 | fs.stat(path, (err, stat) => err ? done(err) : !stat.isDirectory() ? done(new Error(path + ' is already a file')) : done(null));
|
122 | });
|
123 | }
|
124 | function thunk(target, args, context, resolver) {
|
125 | return new Promise((resolve, reject) => {
|
126 | target.apply(context, Array.prototype.slice.call(args).concat([(err, result) => {
|
127 | if (err)
|
128 | reject(err);
|
129 | else if (resolver)
|
130 | resolver.apply(context, arguments);
|
131 | else
|
132 | resolve(result);
|
133 | }]));
|
134 | });
|
135 | }
|
136 |
|
\ | No newline at end of file |