UNPKG

6.01 kBJavaScriptView Raw
1"use strict";
2const fs = require('fs');
3const pathutil = require('path');
4const rimraf = require('rimraf');
5var fs_1 = require('fs');
6exports.createReadStream = fs_1.createReadStream;
7exports.createWriteStream = fs_1.createWriteStream;
8exports.watch = fs_1.watch;
9exports.watchFile = fs_1.watchFile;
10exports.unwatchFile = fs_1.unwatchFile;
11exports.F_OK = fs_1.F_OK;
12exports.R_OK = fs_1.R_OK;
13exports.W_OK = fs_1.W_OK;
14exports.X_OK = fs_1.X_OK;
15function access(path, mode) { return thunk(fs.access, arguments); }
16exports.access = access;
17function appendFile(file, data, options) { return thunk(fs.appendFile, arguments); }
18exports.appendFile = appendFile;
19function chmod(path, mode) { return thunk(fs.chmod, arguments); }
20exports.chmod = chmod;
21function chown(path, uid, gid) { return thunk(fs.chown, arguments); }
22exports.chown = chown;
23function close(fd) { return thunk(fs.close, arguments); }
24exports.close = close;
25function fchmod(fd, mode) { return thunk(fs.fchmod, arguments); }
26exports.fchmod = fchmod;
27function fchown(fd, uid, gid) { return thunk(fs.fchown, arguments); }
28exports.fchown = fchown;
29function fstat(fd) { return thunk(fs.fstat, arguments); }
30exports.fstat = fstat;
31function ftruncate(fd, len) { return thunk(fs.ftruncate, arguments); }
32exports.ftruncate = ftruncate;
33function futimes(fd, atime, mtime) { return thunk(fs.futimes, arguments); }
34exports.futimes = futimes;
35function fsync(fd) { return thunk(fs.fsync, arguments); }
36exports.fsync = fsync;
37function lchmod(path, mode) { return thunk(fs.lchmod, arguments); }
38exports.lchmod = lchmod;
39function lchown(path, uid, gid) { return thunk(fs.lchown, arguments); }
40exports.lchown = lchown;
41function link(srcpath, dstpath) { return thunk(fs.link, arguments); }
42exports.link = link;
43function lstat(path) { return thunk(fs.lstat, arguments); }
44exports.lstat = lstat;
45function mkdir(path, mode) { return thunk(fs.mkdir, arguments); }
46exports.mkdir = mkdir;
47function mkdtemp(path) { return thunk(fs.mkdtemp, arguments); }
48exports.mkdtemp = mkdtemp;
49function open(path, flags, mode) { return thunk(fs.open, arguments); }
50exports.open = open;
51function read(fd, buffer, offset, length, position) { return thunk(fs.read, arguments, null, function () { return { bytesRead: arguments[1], buffer: arguments[2] }; }); }
52exports.read = read;
53function readdir(path) { return thunk(fs.readdir, arguments); }
54exports.readdir = readdir;
55function readFile(file, options) { return thunk(fs.readFile, arguments); }
56exports.readFile = readFile;
57function readlink(path) { return thunk(fs.readlink, arguments); }
58exports.readlink = readlink;
59function realpath(path, cache) { return thunk(fs.realpath, arguments); }
60exports.realpath = realpath;
61function rename(oldPath, newPath) { return thunk(fs.rename, arguments); }
62exports.rename = rename;
63function rmdir(path) { return thunk(fs.rmdir, arguments); }
64exports.rmdir = rmdir;
65function stat(path) { return thunk(fs.stat, arguments); }
66exports.stat = stat;
67function symlink(srcpath, dstpath, type) { return thunk(fs.symlink, arguments); }
68exports.symlink = symlink;
69function truncate(path, len) { return thunk(fs.truncate, arguments); }
70exports.truncate = truncate;
71function unlink(path) { return thunk(fs.unlink, arguments); }
72exports.unlink = unlink;
73function utimes(path, atime, mtime) { return thunk(fs.utimes, arguments); }
74exports.utimes = utimes;
75function write(fd) { return thunk(fs.write, arguments, null, function () { return { written: arguments[1], buffer: arguments[2] }; }); }
76exports.write = write;
77function writeFile(file, data, options) { return thunk(fs.writeFile, arguments); }
78exports.writeFile = writeFile;
79function 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}
86exports.readTextFile = readTextFile;
87function 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}
98exports.writeTextFile = writeTextFile;
99function createDirectory(path, mode) {
100 return new Promise((resolve, reject) => mkdirp(path, mode, err => !err ? resolve() : reject(err)));
101}
102exports.createDirectory = createDirectory;
103exports.mkdirp = createDirectory;
104function del(path) {
105 return new Promise((resolve, reject) => rimraf(path, err => !err ? resolve() : reject(err)));
106}
107exports.delete = del;
108exports.rimraf = del;
109function exists(path) {
110 return new Promise((resolve, reject) => fs.lstat(path, (err) => !err ? resolve(true) : err.code === 'ENOENT' ? resolve(false) : reject(err)));
111}
112exports.exists = exists;
113function 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}
124function 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//# sourceMappingURL=index.js.map
\No newline at end of file