memfs 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -24
- package/README.md +21 -92
- package/lib/Dirent.d.ts +2 -1
- package/lib/__tests__/util.d.ts +13 -0
- package/lib/__tests__/util.js +29 -0
- package/lib/consts/AMODE.d.ts +9 -0
- package/lib/consts/FLAG.d.ts +22 -0
- package/lib/consts/FLAG.js +2 -0
- package/lib/fsa/types.d.ts +3 -3
- package/lib/fsa-to-node/FsaNodeCore.d.ts +32 -0
- package/lib/fsa-to-node/FsaNodeCore.js +168 -0
- package/lib/fsa-to-node/FsaNodeDirent.d.ts +13 -0
- package/lib/fsa-to-node/FsaNodeDirent.js +31 -0
- package/lib/fsa-to-node/FsaNodeFs.d.ts +171 -0
- package/lib/fsa-to-node/FsaNodeFs.js +842 -0
- package/lib/fsa-to-node/FsaNodeFsOpenFile.d.ts +24 -0
- package/lib/fsa-to-node/FsaNodeFsOpenFile.js +46 -0
- package/lib/fsa-to-node/FsaNodeReadStream.d.ts +24 -0
- package/lib/fsa-to-node/FsaNodeReadStream.js +100 -0
- package/lib/fsa-to-node/FsaNodeStats.d.ts +30 -0
- package/lib/fsa-to-node/FsaNodeStats.js +52 -0
- package/lib/fsa-to-node/FsaNodeWriteStream.d.ts +48 -0
- package/lib/fsa-to-node/FsaNodeWriteStream.js +162 -0
- package/lib/fsa-to-node/__tests__/FsaNodeFs.test.d.ts +1 -0
- package/lib/fsa-to-node/__tests__/FsaNodeFs.test.js +873 -0
- package/lib/fsa-to-node/__tests__/util.test.d.ts +1 -0
- package/lib/fsa-to-node/__tests__/util.test.js +28 -0
- package/lib/fsa-to-node/constants.d.ts +3 -0
- package/lib/fsa-to-node/constants.js +2 -0
- package/lib/fsa-to-node/index.d.ts +2 -0
- package/lib/fsa-to-node/index.js +7 -0
- package/lib/fsa-to-node/json.d.ts +4 -0
- package/lib/fsa-to-node/json.js +7 -0
- package/lib/fsa-to-node/types.d.ts +37 -0
- package/lib/fsa-to-node/types.js +2 -0
- package/lib/fsa-to-node/util.d.ts +4 -0
- package/lib/fsa-to-node/util.js +40 -0
- package/lib/fsa-to-node/worker/FsaNodeSyncAdapterWorker.d.ts +10 -0
- package/lib/fsa-to-node/worker/FsaNodeSyncAdapterWorker.js +72 -0
- package/lib/fsa-to-node/worker/FsaNodeSyncWorker.d.ts +20 -0
- package/lib/fsa-to-node/worker/FsaNodeSyncWorker.js +190 -0
- package/lib/fsa-to-node/worker/SyncMessenger.d.ts +24 -0
- package/lib/fsa-to-node/worker/SyncMessenger.js +80 -0
- package/lib/fsa-to-node/worker/constants.d.ts +8 -0
- package/lib/fsa-to-node/worker/constants.js +2 -0
- package/lib/fsa-to-node/worker/types.d.ts +17 -0
- package/lib/fsa-to-node/worker/types.js +2 -0
- package/lib/index.d.ts +5 -4
- package/lib/index.js +1 -1
- package/lib/node/constants.d.ts +41 -0
- package/lib/node/constants.js +56 -0
- package/lib/node/options.d.ts +23 -0
- package/lib/node/options.js +94 -0
- package/lib/node/promises.d.ts +1 -1
- package/lib/node/promises.js +1 -3
- package/lib/node/types/FsCommonObjects.d.ts +17 -0
- package/lib/node/types/FsCommonObjects.js +2 -0
- package/lib/node/types/{sync.d.ts → FsSynchronousApi.d.ts} +36 -37
- package/lib/node/types/FsSynchronousApi.js +2 -0
- package/lib/node/types/callback.d.ts +57 -58
- package/lib/node/types/index.d.ts +1 -1
- package/lib/node/types/misc.d.ts +6 -8
- package/lib/node/types/options.d.ts +20 -6
- package/lib/node/types/promises.d.ts +2 -2
- package/lib/node/util.d.ts +19 -0
- package/lib/node/util.js +265 -1
- package/lib/node-to-fsa/NodeFileSystemDirectoryHandle.d.ts +71 -0
- package/lib/node-to-fsa/NodeFileSystemDirectoryHandle.js +264 -0
- package/lib/node-to-fsa/NodeFileSystemFileHandle.d.ts +28 -0
- package/lib/node-to-fsa/NodeFileSystemFileHandle.js +73 -0
- package/lib/node-to-fsa/NodeFileSystemHandle.d.ts +33 -0
- package/lib/node-to-fsa/NodeFileSystemHandle.js +53 -0
- package/lib/node-to-fsa/NodeFileSystemSyncAccessHandle.d.ts +42 -0
- package/lib/node-to-fsa/NodeFileSystemSyncAccessHandle.js +116 -0
- package/lib/node-to-fsa/NodeFileSystemWritableFileStream.d.ts +54 -0
- package/lib/node-to-fsa/NodeFileSystemWritableFileStream.js +195 -0
- package/lib/node-to-fsa/NodePermissionStatus.d.ts +8 -0
- package/lib/node-to-fsa/NodePermissionStatus.js +13 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemDirectoryHandle.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemDirectoryHandle.test.js +627 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemFileHandle.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemFileHandle.test.js +191 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemHandle.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemHandle.test.js +49 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemSyncAccessHandle.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemSyncAccessHandle.test.js +183 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemWritableFileStream.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemWritableFileStream.test.js +106 -0
- package/lib/node-to-fsa/__tests__/scenarios.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/scenarios.test.js +46 -0
- package/lib/node-to-fsa/__tests__/util.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/util.test.js +25 -0
- package/lib/node-to-fsa/index.d.ts +7 -0
- package/lib/node-to-fsa/index.js +26 -0
- package/lib/node-to-fsa/types.d.ts +12 -0
- package/lib/node-to-fsa/types.js +2 -0
- package/lib/node-to-fsa/util.d.ts +11 -0
- package/lib/node-to-fsa/util.js +33 -0
- package/lib/node.d.ts +1 -1
- package/lib/volume.d.ts +45 -126
- package/lib/volume.js +204 -562
- package/lib/webfs/index.d.ts +1 -0
- package/lib/webfs/index.js +22 -0
- package/package.json +28 -5
- /package/lib/{node/types/sync.js → consts/AMODE.js} +0 -0
package/lib/volume.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FSWatcher = exports.StatWatcher = exports.Volume = exports.toUnixTimestamp = exports.
|
|
3
|
+
exports.FSWatcher = exports.StatWatcher = exports.Volume = exports.toUnixTimestamp = exports.dataToStr = exports.pathToSteps = exports.filenameToSteps = void 0;
|
|
4
4
|
const pathModule = require("path");
|
|
5
5
|
const node_1 = require("./node");
|
|
6
6
|
const Stats_1 = require("./Stats");
|
|
@@ -13,41 +13,20 @@ const stream_1 = require("stream");
|
|
|
13
13
|
const constants_1 = require("./constants");
|
|
14
14
|
const events_1 = require("events");
|
|
15
15
|
const encoding_1 = require("./encoding");
|
|
16
|
-
const errors = require("./internal/errors");
|
|
17
16
|
const util = require("util");
|
|
18
17
|
const promises_1 = require("./node/promises");
|
|
18
|
+
const constants_2 = require("./node/constants");
|
|
19
|
+
const options_1 = require("./node/options");
|
|
20
|
+
const util_1 = require("./node/util");
|
|
19
21
|
const resolveCrossPlatform = pathModule.resolve;
|
|
20
|
-
const { O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_TRUNC, O_APPEND,
|
|
22
|
+
const { O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_TRUNC, O_APPEND, O_DIRECTORY, F_OK, COPYFILE_EXCL, COPYFILE_FICLONE_FORCE, } = constants_1.constants;
|
|
21
23
|
const { sep, relative, join, dirname } = pathModule.posix ? pathModule.posix : pathModule;
|
|
22
|
-
|
|
24
|
+
// ---------------------------------------- Constants
|
|
23
25
|
const kMinPoolSpace = 128;
|
|
24
|
-
// const kMaxLength = require('buffer').kMaxLength;
|
|
25
26
|
// ---------------------------------------- Error messages
|
|
26
|
-
// TODO: Use `internal/errors.js` in the future.
|
|
27
|
-
const ERRSTR = {
|
|
28
|
-
PATH_STR: 'path must be a string or Buffer',
|
|
29
|
-
// FD: 'file descriptor must be a unsigned 32-bit integer',
|
|
30
|
-
FD: 'fd must be a file descriptor',
|
|
31
|
-
MODE_INT: 'mode must be an int',
|
|
32
|
-
CB: 'callback must be a function',
|
|
33
|
-
UID: 'uid must be an unsigned int',
|
|
34
|
-
GID: 'gid must be an unsigned int',
|
|
35
|
-
LEN: 'len must be an integer',
|
|
36
|
-
ATIME: 'atime must be an integer',
|
|
37
|
-
MTIME: 'mtime must be an integer',
|
|
38
|
-
PREFIX: 'filename prefix is required',
|
|
39
|
-
BUFFER: 'buffer must be an instance of Buffer or StaticBuffer',
|
|
40
|
-
OFFSET: 'offset must be an integer',
|
|
41
|
-
LENGTH: 'length must be an integer',
|
|
42
|
-
POSITION: 'position must be an integer',
|
|
43
|
-
};
|
|
44
|
-
const ERRSTR_OPTS = tipeof => `Expected options to be either an object or a string, but got ${tipeof} instead`;
|
|
45
|
-
// const ERRSTR_FLAG = flag => `Unknown file open flag: ${flag}`;
|
|
46
27
|
const ENOENT = 'ENOENT';
|
|
47
28
|
const EBADF = 'EBADF';
|
|
48
29
|
const EINVAL = 'EINVAL';
|
|
49
|
-
const EPERM = 'EPERM';
|
|
50
|
-
const EPROTO = 'EPROTO';
|
|
51
30
|
const EEXIST = 'EEXIST';
|
|
52
31
|
const ENOTDIR = 'ENOTDIR';
|
|
53
32
|
const EMFILE = 'EMFILE';
|
|
@@ -56,219 +35,8 @@ const EISDIR = 'EISDIR';
|
|
|
56
35
|
const ENOTEMPTY = 'ENOTEMPTY';
|
|
57
36
|
const ENOSYS = 'ENOSYS';
|
|
58
37
|
const ERR_FS_EISDIR = 'ERR_FS_EISDIR';
|
|
59
|
-
function formatError(errorCode, func = '', path = '', path2 = '') {
|
|
60
|
-
let pathFormatted = '';
|
|
61
|
-
if (path)
|
|
62
|
-
pathFormatted = ` '${path}'`;
|
|
63
|
-
if (path2)
|
|
64
|
-
pathFormatted += ` -> '${path2}'`;
|
|
65
|
-
switch (errorCode) {
|
|
66
|
-
case ENOENT:
|
|
67
|
-
return `ENOENT: no such file or directory, ${func}${pathFormatted}`;
|
|
68
|
-
case EBADF:
|
|
69
|
-
return `EBADF: bad file descriptor, ${func}${pathFormatted}`;
|
|
70
|
-
case EINVAL:
|
|
71
|
-
return `EINVAL: invalid argument, ${func}${pathFormatted}`;
|
|
72
|
-
case EPERM:
|
|
73
|
-
return `EPERM: operation not permitted, ${func}${pathFormatted}`;
|
|
74
|
-
case EPROTO:
|
|
75
|
-
return `EPROTO: protocol error, ${func}${pathFormatted}`;
|
|
76
|
-
case EEXIST:
|
|
77
|
-
return `EEXIST: file already exists, ${func}${pathFormatted}`;
|
|
78
|
-
case ENOTDIR:
|
|
79
|
-
return `ENOTDIR: not a directory, ${func}${pathFormatted}`;
|
|
80
|
-
case EISDIR:
|
|
81
|
-
return `EISDIR: illegal operation on a directory, ${func}${pathFormatted}`;
|
|
82
|
-
case EACCES:
|
|
83
|
-
return `EACCES: permission denied, ${func}${pathFormatted}`;
|
|
84
|
-
case ENOTEMPTY:
|
|
85
|
-
return `ENOTEMPTY: directory not empty, ${func}${pathFormatted}`;
|
|
86
|
-
case EMFILE:
|
|
87
|
-
return `EMFILE: too many open files, ${func}${pathFormatted}`;
|
|
88
|
-
case ENOSYS:
|
|
89
|
-
return `ENOSYS: function not implemented, ${func}${pathFormatted}`;
|
|
90
|
-
case ERR_FS_EISDIR:
|
|
91
|
-
return `[ERR_FS_EISDIR]: Path is a directory: ${func} returned EISDIR (is a directory) ${path}`;
|
|
92
|
-
default:
|
|
93
|
-
return `${errorCode}: error occurred, ${func}${pathFormatted}`;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
function createError(errorCode, func = '', path = '', path2 = '', Constructor = Error) {
|
|
97
|
-
const error = new Constructor(formatError(errorCode, func, path, path2));
|
|
98
|
-
error.code = errorCode;
|
|
99
|
-
if (path) {
|
|
100
|
-
error.path = path;
|
|
101
|
-
}
|
|
102
|
-
return error;
|
|
103
|
-
}
|
|
104
|
-
// ---------------------------------------- Flags
|
|
105
|
-
// List of file `flags` as defined by Node.
|
|
106
|
-
var FLAGS;
|
|
107
|
-
(function (FLAGS) {
|
|
108
|
-
// Open file for reading. An exception occurs if the file does not exist.
|
|
109
|
-
FLAGS[FLAGS["r"] = O_RDONLY] = "r";
|
|
110
|
-
// Open file for reading and writing. An exception occurs if the file does not exist.
|
|
111
|
-
FLAGS[FLAGS["r+"] = O_RDWR] = "r+";
|
|
112
|
-
// Open file for reading in synchronous mode. Instructs the operating system to bypass the local file system cache.
|
|
113
|
-
FLAGS[FLAGS["rs"] = O_RDONLY | O_SYNC] = "rs";
|
|
114
|
-
FLAGS[FLAGS["sr"] = FLAGS.rs] = "sr";
|
|
115
|
-
// Open file for reading and writing, telling the OS to open it synchronously. See notes for 'rs' about using this with caution.
|
|
116
|
-
FLAGS[FLAGS["rs+"] = O_RDWR | O_SYNC] = "rs+";
|
|
117
|
-
FLAGS[FLAGS["sr+"] = FLAGS['rs+']] = "sr+";
|
|
118
|
-
// Open file for writing. The file is created (if it does not exist) or truncated (if it exists).
|
|
119
|
-
FLAGS[FLAGS["w"] = O_WRONLY | O_CREAT | O_TRUNC] = "w";
|
|
120
|
-
// Like 'w' but fails if path exists.
|
|
121
|
-
FLAGS[FLAGS["wx"] = O_WRONLY | O_CREAT | O_TRUNC | O_EXCL] = "wx";
|
|
122
|
-
FLAGS[FLAGS["xw"] = FLAGS.wx] = "xw";
|
|
123
|
-
// Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).
|
|
124
|
-
FLAGS[FLAGS["w+"] = O_RDWR | O_CREAT | O_TRUNC] = "w+";
|
|
125
|
-
// Like 'w+' but fails if path exists.
|
|
126
|
-
FLAGS[FLAGS["wx+"] = O_RDWR | O_CREAT | O_TRUNC | O_EXCL] = "wx+";
|
|
127
|
-
FLAGS[FLAGS["xw+"] = FLAGS['wx+']] = "xw+";
|
|
128
|
-
// Open file for appending. The file is created if it does not exist.
|
|
129
|
-
FLAGS[FLAGS["a"] = O_WRONLY | O_APPEND | O_CREAT] = "a";
|
|
130
|
-
// Like 'a' but fails if path exists.
|
|
131
|
-
FLAGS[FLAGS["ax"] = O_WRONLY | O_APPEND | O_CREAT | O_EXCL] = "ax";
|
|
132
|
-
FLAGS[FLAGS["xa"] = FLAGS.ax] = "xa";
|
|
133
|
-
// Open file for reading and appending. The file is created if it does not exist.
|
|
134
|
-
FLAGS[FLAGS["a+"] = O_RDWR | O_APPEND | O_CREAT] = "a+";
|
|
135
|
-
// Like 'a+' but fails if path exists.
|
|
136
|
-
FLAGS[FLAGS["ax+"] = O_RDWR | O_APPEND | O_CREAT | O_EXCL] = "ax+";
|
|
137
|
-
FLAGS[FLAGS["xa+"] = FLAGS['ax+']] = "xa+";
|
|
138
|
-
})(FLAGS = exports.FLAGS || (exports.FLAGS = {}));
|
|
139
|
-
function flagsToNumber(flags) {
|
|
140
|
-
if (typeof flags === 'number')
|
|
141
|
-
return flags;
|
|
142
|
-
if (typeof flags === 'string') {
|
|
143
|
-
const flagsNum = FLAGS[flags];
|
|
144
|
-
if (typeof flagsNum !== 'undefined')
|
|
145
|
-
return flagsNum;
|
|
146
|
-
}
|
|
147
|
-
// throw new TypeError(formatError(ERRSTR_FLAG(flags)));
|
|
148
|
-
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'flags', flags);
|
|
149
|
-
}
|
|
150
|
-
exports.flagsToNumber = flagsToNumber;
|
|
151
|
-
// ---------------------------------------- Options
|
|
152
|
-
function getOptions(defaults, options) {
|
|
153
|
-
let opts;
|
|
154
|
-
if (!options)
|
|
155
|
-
return defaults;
|
|
156
|
-
else {
|
|
157
|
-
const tipeof = typeof options;
|
|
158
|
-
switch (tipeof) {
|
|
159
|
-
case 'string':
|
|
160
|
-
opts = Object.assign({}, defaults, { encoding: options });
|
|
161
|
-
break;
|
|
162
|
-
case 'object':
|
|
163
|
-
opts = Object.assign({}, defaults, options);
|
|
164
|
-
break;
|
|
165
|
-
default:
|
|
166
|
-
throw TypeError(ERRSTR_OPTS(tipeof));
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (opts.encoding !== 'buffer')
|
|
170
|
-
(0, encoding_1.assertEncoding)(opts.encoding);
|
|
171
|
-
return opts;
|
|
172
|
-
}
|
|
173
|
-
function optsGenerator(defaults) {
|
|
174
|
-
return options => getOptions(defaults, options);
|
|
175
|
-
}
|
|
176
|
-
function validateCallback(callback) {
|
|
177
|
-
if (typeof callback !== 'function')
|
|
178
|
-
throw TypeError(ERRSTR.CB);
|
|
179
|
-
return callback;
|
|
180
|
-
}
|
|
181
|
-
function optsAndCbGenerator(getOpts) {
|
|
182
|
-
return (options, callback) => typeof options === 'function' ? [getOpts(), options] : [getOpts(options), validateCallback(callback)];
|
|
183
|
-
}
|
|
184
|
-
const optsDefaults = {
|
|
185
|
-
encoding: 'utf8',
|
|
186
|
-
};
|
|
187
|
-
const getDefaultOpts = optsGenerator(optsDefaults);
|
|
188
|
-
const getDefaultOptsAndCb = optsAndCbGenerator(getDefaultOpts);
|
|
189
|
-
const readFileOptsDefaults = {
|
|
190
|
-
flag: 'r',
|
|
191
|
-
};
|
|
192
|
-
const getReadFileOptions = optsGenerator(readFileOptsDefaults);
|
|
193
|
-
const writeFileDefaults = {
|
|
194
|
-
encoding: 'utf8',
|
|
195
|
-
mode: 438 /* MODE.DEFAULT */,
|
|
196
|
-
flag: FLAGS[FLAGS.w],
|
|
197
|
-
};
|
|
198
|
-
const getWriteFileOptions = optsGenerator(writeFileDefaults);
|
|
199
|
-
const appendFileDefaults = {
|
|
200
|
-
encoding: 'utf8',
|
|
201
|
-
mode: 438 /* MODE.DEFAULT */,
|
|
202
|
-
flag: FLAGS[FLAGS.a],
|
|
203
|
-
};
|
|
204
|
-
const getAppendFileOpts = optsGenerator(appendFileDefaults);
|
|
205
|
-
const getAppendFileOptsAndCb = optsAndCbGenerator(getAppendFileOpts);
|
|
206
|
-
const realpathDefaults = optsDefaults;
|
|
207
|
-
const getRealpathOptions = optsGenerator(realpathDefaults);
|
|
208
|
-
const getRealpathOptsAndCb = optsAndCbGenerator(getRealpathOptions);
|
|
209
|
-
const mkdirDefaults = {
|
|
210
|
-
mode: 511 /* MODE.DIR */,
|
|
211
|
-
recursive: false,
|
|
212
|
-
};
|
|
213
|
-
const getMkdirOptions = (options) => {
|
|
214
|
-
if (typeof options === 'number')
|
|
215
|
-
return Object.assign({}, mkdirDefaults, { mode: options });
|
|
216
|
-
return Object.assign({}, mkdirDefaults, options);
|
|
217
|
-
};
|
|
218
|
-
const rmdirDefaults = {
|
|
219
|
-
recursive: false,
|
|
220
|
-
};
|
|
221
|
-
const getRmdirOptions = (options) => {
|
|
222
|
-
return Object.assign({}, rmdirDefaults, options);
|
|
223
|
-
};
|
|
224
|
-
const getRmOpts = optsGenerator(optsDefaults);
|
|
225
|
-
const getRmOptsAndCb = optsAndCbGenerator(getRmOpts);
|
|
226
|
-
const readdirDefaults = {
|
|
227
|
-
encoding: 'utf8',
|
|
228
|
-
withFileTypes: false,
|
|
229
|
-
};
|
|
230
|
-
const getReaddirOptions = optsGenerator(readdirDefaults);
|
|
231
|
-
const getReaddirOptsAndCb = optsAndCbGenerator(getReaddirOptions);
|
|
232
|
-
const statDefaults = {
|
|
233
|
-
bigint: false,
|
|
234
|
-
};
|
|
235
|
-
const getStatOptions = (options = {}) => Object.assign({}, statDefaults, options);
|
|
236
|
-
const getStatOptsAndCb = (options, callback) => typeof options === 'function' ? [getStatOptions(), options] : [getStatOptions(options), validateCallback(callback)];
|
|
237
|
-
// ---------------------------------------- Utility functions
|
|
238
|
-
function getPathFromURLPosix(url) {
|
|
239
|
-
if (url.hostname !== '') {
|
|
240
|
-
throw new errors.TypeError('ERR_INVALID_FILE_URL_HOST', process_1.default.platform);
|
|
241
|
-
}
|
|
242
|
-
const pathname = url.pathname;
|
|
243
|
-
for (let n = 0; n < pathname.length; n++) {
|
|
244
|
-
if (pathname[n] === '%') {
|
|
245
|
-
const third = pathname.codePointAt(n + 2) | 0x20;
|
|
246
|
-
if (pathname[n + 1] === '2' && third === 102) {
|
|
247
|
-
throw new errors.TypeError('ERR_INVALID_FILE_URL_PATH', 'must not include encoded / characters');
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
return decodeURIComponent(pathname);
|
|
252
|
-
}
|
|
253
|
-
function pathToFilename(path) {
|
|
254
|
-
if (typeof path !== 'string' && !buffer_1.Buffer.isBuffer(path)) {
|
|
255
|
-
try {
|
|
256
|
-
if (!(path instanceof require('url').URL))
|
|
257
|
-
throw new TypeError(ERRSTR.PATH_STR);
|
|
258
|
-
}
|
|
259
|
-
catch (err) {
|
|
260
|
-
throw new TypeError(ERRSTR.PATH_STR);
|
|
261
|
-
}
|
|
262
|
-
path = getPathFromURLPosix(path);
|
|
263
|
-
}
|
|
264
|
-
const pathString = String(path);
|
|
265
|
-
nullCheck(pathString);
|
|
266
|
-
// return slash(pathString);
|
|
267
|
-
return pathString;
|
|
268
|
-
}
|
|
269
|
-
exports.pathToFilename = pathToFilename;
|
|
270
38
|
let resolve = (filename, base = process_1.default.cwd()) => resolveCrossPlatform(base, filename);
|
|
271
|
-
if (isWin) {
|
|
39
|
+
if (util_1.isWin) {
|
|
272
40
|
const _resolve = resolve;
|
|
273
41
|
const { unixify } = require('fs-monkey/lib/correctPath');
|
|
274
42
|
resolve = (filename, base) => unixify(_resolve(filename, base));
|
|
@@ -282,7 +50,7 @@ function filenameToSteps(filename, base) {
|
|
|
282
50
|
}
|
|
283
51
|
exports.filenameToSteps = filenameToSteps;
|
|
284
52
|
function pathToSteps(path) {
|
|
285
|
-
return filenameToSteps(pathToFilename(path));
|
|
53
|
+
return filenameToSteps((0, util_1.pathToFilename)(path));
|
|
286
54
|
}
|
|
287
55
|
exports.pathToSteps = pathToSteps;
|
|
288
56
|
function dataToStr(data, encoding = encoding_1.ENCODING_UTF8) {
|
|
@@ -294,55 +62,6 @@ function dataToStr(data, encoding = encoding_1.ENCODING_UTF8) {
|
|
|
294
62
|
return String(data);
|
|
295
63
|
}
|
|
296
64
|
exports.dataToStr = dataToStr;
|
|
297
|
-
function dataToBuffer(data, encoding = encoding_1.ENCODING_UTF8) {
|
|
298
|
-
if (buffer_1.Buffer.isBuffer(data))
|
|
299
|
-
return data;
|
|
300
|
-
else if (data instanceof Uint8Array)
|
|
301
|
-
return (0, buffer_1.bufferFrom)(data);
|
|
302
|
-
else
|
|
303
|
-
return (0, buffer_1.bufferFrom)(String(data), encoding);
|
|
304
|
-
}
|
|
305
|
-
exports.dataToBuffer = dataToBuffer;
|
|
306
|
-
function bufferToEncoding(buffer, encoding) {
|
|
307
|
-
if (!encoding || encoding === 'buffer')
|
|
308
|
-
return buffer;
|
|
309
|
-
else
|
|
310
|
-
return buffer.toString(encoding);
|
|
311
|
-
}
|
|
312
|
-
exports.bufferToEncoding = bufferToEncoding;
|
|
313
|
-
function nullCheck(path, callback) {
|
|
314
|
-
if (('' + path).indexOf('\u0000') !== -1) {
|
|
315
|
-
const er = new Error('Path must be a string without null bytes');
|
|
316
|
-
er.code = ENOENT;
|
|
317
|
-
if (typeof callback !== 'function')
|
|
318
|
-
throw er;
|
|
319
|
-
process_1.default.nextTick(callback, er);
|
|
320
|
-
return false;
|
|
321
|
-
}
|
|
322
|
-
return true;
|
|
323
|
-
}
|
|
324
|
-
function _modeToNumber(mode, def) {
|
|
325
|
-
if (typeof mode === 'number')
|
|
326
|
-
return mode;
|
|
327
|
-
if (typeof mode === 'string')
|
|
328
|
-
return parseInt(mode, 8);
|
|
329
|
-
if (def)
|
|
330
|
-
return modeToNumber(def);
|
|
331
|
-
return undefined;
|
|
332
|
-
}
|
|
333
|
-
function modeToNumber(mode, def) {
|
|
334
|
-
const result = _modeToNumber(mode, def);
|
|
335
|
-
if (typeof result !== 'number' || isNaN(result))
|
|
336
|
-
throw new TypeError(ERRSTR.MODE_INT);
|
|
337
|
-
return result;
|
|
338
|
-
}
|
|
339
|
-
function isFd(path) {
|
|
340
|
-
return path >>> 0 === path;
|
|
341
|
-
}
|
|
342
|
-
function validateFd(fd) {
|
|
343
|
-
if (!isFd(fd))
|
|
344
|
-
throw TypeError(ERRSTR.FD);
|
|
345
|
-
}
|
|
346
65
|
// converts Date or number to a fractional UNIX timestamp
|
|
347
66
|
function toUnixTimestamp(time) {
|
|
348
67
|
// tslint:disable-next-line triple-equals
|
|
@@ -363,11 +82,11 @@ function toUnixTimestamp(time) {
|
|
|
363
82
|
exports.toUnixTimestamp = toUnixTimestamp;
|
|
364
83
|
function validateUid(uid) {
|
|
365
84
|
if (typeof uid !== 'number')
|
|
366
|
-
throw TypeError(ERRSTR.UID);
|
|
85
|
+
throw TypeError(constants_2.ERRSTR.UID);
|
|
367
86
|
}
|
|
368
87
|
function validateGid(gid) {
|
|
369
88
|
if (typeof gid !== 'number')
|
|
370
|
-
throw TypeError(ERRSTR.GID);
|
|
89
|
+
throw TypeError(constants_2.ERRSTR.GID);
|
|
371
90
|
}
|
|
372
91
|
function flattenJSON(nestedJSON) {
|
|
373
92
|
const flatJSON = {};
|
|
@@ -498,22 +217,11 @@ class Volume {
|
|
|
498
217
|
this.inodes[node.ino] = node;
|
|
499
218
|
return node;
|
|
500
219
|
}
|
|
501
|
-
getNode(ino) {
|
|
502
|
-
return this.inodes[ino];
|
|
503
|
-
}
|
|
504
220
|
deleteNode(node) {
|
|
505
221
|
node.del();
|
|
506
222
|
delete this.inodes[node.ino];
|
|
507
223
|
this.releasedInos.push(node.ino);
|
|
508
224
|
}
|
|
509
|
-
// Generates 6 character long random string, used by `mkdtemp`.
|
|
510
|
-
genRndStr() {
|
|
511
|
-
const str = (Math.random() + 1).toString(36).substring(2, 8);
|
|
512
|
-
if (str.length === 6)
|
|
513
|
-
return str;
|
|
514
|
-
else
|
|
515
|
-
return this.genRndStr();
|
|
516
|
-
}
|
|
517
225
|
// Returns a `Link` (hard link) referenced by path "split" into steps.
|
|
518
226
|
getLink(steps) {
|
|
519
227
|
return this.root.walk(steps);
|
|
@@ -523,7 +231,7 @@ class Volume {
|
|
|
523
231
|
const steps = filenameToSteps(filename);
|
|
524
232
|
const link = this.getLink(steps);
|
|
525
233
|
if (!link)
|
|
526
|
-
throw createError(ENOENT, funcName, filename);
|
|
234
|
+
throw (0, util_1.createError)(ENOENT, funcName, filename);
|
|
527
235
|
return link;
|
|
528
236
|
}
|
|
529
237
|
// Just like `getLink`, but also dereference/resolves symbolic links.
|
|
@@ -551,7 +259,7 @@ class Volume {
|
|
|
551
259
|
getResolvedLinkOrThrow(filename, funcName) {
|
|
552
260
|
const link = this.getResolvedLink(filename);
|
|
553
261
|
if (!link)
|
|
554
|
-
throw createError(ENOENT, funcName, filename);
|
|
262
|
+
throw (0, util_1.createError)(ENOENT, funcName, filename);
|
|
555
263
|
return link;
|
|
556
264
|
}
|
|
557
265
|
resolveSymlinks(link) {
|
|
@@ -568,7 +276,7 @@ class Volume {
|
|
|
568
276
|
getLinkAsDirOrThrow(filename, funcName) {
|
|
569
277
|
const link = this.getLinkOrThrow(filename, funcName);
|
|
570
278
|
if (!link.getNode().isDirectory())
|
|
571
|
-
throw createError(ENOTDIR, funcName, filename);
|
|
279
|
+
throw (0, util_1.createError)(ENOTDIR, funcName, filename);
|
|
572
280
|
return link;
|
|
573
281
|
}
|
|
574
282
|
// Get the immediate parent directory of the link.
|
|
@@ -579,20 +287,20 @@ class Volume {
|
|
|
579
287
|
const steps = filenameOrSteps instanceof Array ? filenameOrSteps : filenameToSteps(filenameOrSteps);
|
|
580
288
|
const link = this.getLinkParent(steps);
|
|
581
289
|
if (!link)
|
|
582
|
-
throw createError(ENOENT, funcName, sep + steps.join(sep));
|
|
290
|
+
throw (0, util_1.createError)(ENOENT, funcName, sep + steps.join(sep));
|
|
583
291
|
if (!link.getNode().isDirectory())
|
|
584
|
-
throw createError(ENOTDIR, funcName, sep + steps.join(sep));
|
|
292
|
+
throw (0, util_1.createError)(ENOTDIR, funcName, sep + steps.join(sep));
|
|
585
293
|
return link;
|
|
586
294
|
}
|
|
587
295
|
getFileByFd(fd) {
|
|
588
296
|
return this.fds[String(fd)];
|
|
589
297
|
}
|
|
590
298
|
getFileByFdOrThrow(fd, funcName) {
|
|
591
|
-
if (!isFd(fd))
|
|
592
|
-
throw TypeError(ERRSTR.FD);
|
|
299
|
+
if (!(0, util_1.isFd)(fd))
|
|
300
|
+
throw TypeError(constants_2.ERRSTR.FD);
|
|
593
301
|
const file = this.getFileByFd(fd);
|
|
594
302
|
if (!file)
|
|
595
|
-
throw createError(EBADF, funcName);
|
|
303
|
+
throw (0, util_1.createError)(EBADF, funcName);
|
|
596
304
|
return file;
|
|
597
305
|
}
|
|
598
306
|
/**
|
|
@@ -624,7 +332,7 @@ class Volume {
|
|
|
624
332
|
}
|
|
625
333
|
*/
|
|
626
334
|
wrapAsync(method, args, callback) {
|
|
627
|
-
validateCallback(callback);
|
|
335
|
+
(0, util_1.validateCallback)(callback);
|
|
628
336
|
(0, setImmediate_1.default)(() => {
|
|
629
337
|
let result;
|
|
630
338
|
try {
|
|
@@ -678,7 +386,7 @@ class Volume {
|
|
|
678
386
|
if (!(paths instanceof Array))
|
|
679
387
|
paths = [paths];
|
|
680
388
|
for (const path of paths) {
|
|
681
|
-
const filename = pathToFilename(path);
|
|
389
|
+
const filename = (0, util_1.pathToFilename)(path);
|
|
682
390
|
const link = this.getResolvedLink(filename);
|
|
683
391
|
if (!link)
|
|
684
392
|
continue;
|
|
@@ -729,28 +437,28 @@ class Volume {
|
|
|
729
437
|
openLink(link, flagsNum, resolveSymlinks = true) {
|
|
730
438
|
if (this.openFiles >= this.maxFiles) {
|
|
731
439
|
// Too many open files.
|
|
732
|
-
throw createError(EMFILE, 'open', link.getPath());
|
|
440
|
+
throw (0, util_1.createError)(EMFILE, 'open', link.getPath());
|
|
733
441
|
}
|
|
734
442
|
// Resolve symlinks.
|
|
735
443
|
let realLink = link;
|
|
736
444
|
if (resolveSymlinks)
|
|
737
445
|
realLink = this.resolveSymlinks(link);
|
|
738
446
|
if (!realLink)
|
|
739
|
-
throw createError(ENOENT, 'open', link.getPath());
|
|
447
|
+
throw (0, util_1.createError)(ENOENT, 'open', link.getPath());
|
|
740
448
|
const node = realLink.getNode();
|
|
741
449
|
// Check whether node is a directory
|
|
742
450
|
if (node.isDirectory()) {
|
|
743
451
|
if ((flagsNum & (O_RDONLY | O_RDWR | O_WRONLY)) !== O_RDONLY)
|
|
744
|
-
throw createError(EISDIR, 'open', link.getPath());
|
|
452
|
+
throw (0, util_1.createError)(EISDIR, 'open', link.getPath());
|
|
745
453
|
}
|
|
746
454
|
else {
|
|
747
455
|
if (flagsNum & O_DIRECTORY)
|
|
748
|
-
throw createError(ENOTDIR, 'open', link.getPath());
|
|
456
|
+
throw (0, util_1.createError)(ENOTDIR, 'open', link.getPath());
|
|
749
457
|
}
|
|
750
458
|
// Check node permissions
|
|
751
459
|
if (!(flagsNum & O_WRONLY)) {
|
|
752
460
|
if (!node.canRead()) {
|
|
753
|
-
throw createError(EACCES, 'open', link.getPath());
|
|
461
|
+
throw (0, util_1.createError)(EACCES, 'open', link.getPath());
|
|
754
462
|
}
|
|
755
463
|
}
|
|
756
464
|
if (flagsNum & O_RDWR) {
|
|
@@ -766,33 +474,33 @@ class Volume {
|
|
|
766
474
|
const steps = filenameToSteps(filename);
|
|
767
475
|
let link = resolveSymlinks ? this.getResolvedLink(steps) : this.getLink(steps);
|
|
768
476
|
if (link && flagsNum & O_EXCL)
|
|
769
|
-
throw createError(EEXIST, 'open', filename);
|
|
477
|
+
throw (0, util_1.createError)(EEXIST, 'open', filename);
|
|
770
478
|
// Try creating a new file, if it does not exist.
|
|
771
479
|
if (!link && flagsNum & O_CREAT) {
|
|
772
480
|
// const dirLink: Link = this.getLinkParent(steps);
|
|
773
481
|
const dirLink = this.getResolvedLink(steps.slice(0, steps.length - 1));
|
|
774
482
|
// if(!dirLink) throw createError(ENOENT, 'open', filename);
|
|
775
483
|
if (!dirLink)
|
|
776
|
-
throw createError(ENOENT, 'open', sep + steps.join(sep));
|
|
484
|
+
throw (0, util_1.createError)(ENOENT, 'open', sep + steps.join(sep));
|
|
777
485
|
if (flagsNum & O_CREAT && typeof modeNum === 'number') {
|
|
778
486
|
link = this.createLink(dirLink, steps[steps.length - 1], false, modeNum);
|
|
779
487
|
}
|
|
780
488
|
}
|
|
781
489
|
if (link)
|
|
782
490
|
return this.openLink(link, flagsNum, resolveSymlinks);
|
|
783
|
-
throw createError(ENOENT, 'open', filename);
|
|
491
|
+
throw (0, util_1.createError)(ENOENT, 'open', filename);
|
|
784
492
|
}
|
|
785
493
|
openBase(filename, flagsNum, modeNum, resolveSymlinks = true) {
|
|
786
494
|
const file = this.openFile(filename, flagsNum, modeNum, resolveSymlinks);
|
|
787
495
|
if (!file)
|
|
788
|
-
throw createError(ENOENT, 'open', filename);
|
|
496
|
+
throw (0, util_1.createError)(ENOENT, 'open', filename);
|
|
789
497
|
return file.fd;
|
|
790
498
|
}
|
|
791
499
|
openSync(path, flags, mode = 438 /* MODE.DEFAULT */) {
|
|
792
500
|
// Validate (1) mode; (2) path; (3) flags - in that order.
|
|
793
|
-
const modeNum = modeToNumber(mode);
|
|
794
|
-
const fileName = pathToFilename(path);
|
|
795
|
-
const flagsNum = flagsToNumber(flags);
|
|
501
|
+
const modeNum = (0, util_1.modeToNumber)(mode);
|
|
502
|
+
const fileName = (0, util_1.pathToFilename)(path);
|
|
503
|
+
const flagsNum = (0, util_1.flagsToNumber)(flags);
|
|
796
504
|
return this.openBase(fileName, flagsNum, modeNum);
|
|
797
505
|
}
|
|
798
506
|
open(path, flags, a, b) {
|
|
@@ -803,9 +511,9 @@ class Volume {
|
|
|
803
511
|
callback = a;
|
|
804
512
|
}
|
|
805
513
|
mode = mode || 438 /* MODE.DEFAULT */;
|
|
806
|
-
const modeNum = modeToNumber(mode);
|
|
807
|
-
const fileName = pathToFilename(path);
|
|
808
|
-
const flagsNum = flagsToNumber(flags);
|
|
514
|
+
const modeNum = (0, util_1.modeToNumber)(mode);
|
|
515
|
+
const fileName = (0, util_1.pathToFilename)(path);
|
|
516
|
+
const flagsNum = (0, util_1.flagsToNumber)(flags);
|
|
809
517
|
this.wrapAsync(this.openBase, [fileName, flagsNum, modeNum], callback);
|
|
810
518
|
}
|
|
811
519
|
closeFile(file) {
|
|
@@ -816,23 +524,23 @@ class Volume {
|
|
|
816
524
|
this.releasedFds.push(file.fd);
|
|
817
525
|
}
|
|
818
526
|
closeSync(fd) {
|
|
819
|
-
validateFd(fd);
|
|
527
|
+
(0, util_1.validateFd)(fd);
|
|
820
528
|
const file = this.getFileByFdOrThrow(fd, 'close');
|
|
821
529
|
this.closeFile(file);
|
|
822
530
|
}
|
|
823
531
|
close(fd, callback) {
|
|
824
|
-
validateFd(fd);
|
|
532
|
+
(0, util_1.validateFd)(fd);
|
|
825
533
|
this.wrapAsync(this.closeSync, [fd], callback);
|
|
826
534
|
}
|
|
827
535
|
openFileOrGetById(id, flagsNum, modeNum) {
|
|
828
536
|
if (typeof id === 'number') {
|
|
829
537
|
const file = this.fds[id];
|
|
830
538
|
if (!file)
|
|
831
|
-
throw createError(ENOENT);
|
|
539
|
+
throw (0, util_1.createError)(ENOENT);
|
|
832
540
|
return file;
|
|
833
541
|
}
|
|
834
542
|
else {
|
|
835
|
-
return this.openFile(pathToFilename(id), flagsNum, modeNum);
|
|
543
|
+
return this.openFile((0, util_1.pathToFilename)(id), flagsNum, modeNum);
|
|
836
544
|
}
|
|
837
545
|
}
|
|
838
546
|
readBase(fd, buffer, offset, length, position) {
|
|
@@ -840,11 +548,11 @@ class Volume {
|
|
|
840
548
|
return file.read(buffer, Number(offset), Number(length), position);
|
|
841
549
|
}
|
|
842
550
|
readSync(fd, buffer, offset, length, position) {
|
|
843
|
-
validateFd(fd);
|
|
551
|
+
(0, util_1.validateFd)(fd);
|
|
844
552
|
return this.readBase(fd, buffer, offset, length, position);
|
|
845
553
|
}
|
|
846
554
|
read(fd, buffer, offset, length, position, callback) {
|
|
847
|
-
validateCallback(callback);
|
|
555
|
+
(0, util_1.validateCallback)(callback);
|
|
848
556
|
// This `if` branch is from Node.js
|
|
849
557
|
if (length === 0) {
|
|
850
558
|
return process_1.default.nextTick(() => {
|
|
@@ -865,23 +573,23 @@ class Volume {
|
|
|
865
573
|
readFileBase(id, flagsNum, encoding) {
|
|
866
574
|
let result;
|
|
867
575
|
const isUserFd = typeof id === 'number';
|
|
868
|
-
const userOwnsFd = isUserFd && isFd(id);
|
|
576
|
+
const userOwnsFd = isUserFd && (0, util_1.isFd)(id);
|
|
869
577
|
let fd;
|
|
870
578
|
if (userOwnsFd)
|
|
871
579
|
fd = id;
|
|
872
580
|
else {
|
|
873
|
-
const filename = pathToFilename(id);
|
|
581
|
+
const filename = (0, util_1.pathToFilename)(id);
|
|
874
582
|
const steps = filenameToSteps(filename);
|
|
875
583
|
const link = this.getResolvedLink(steps);
|
|
876
584
|
if (link) {
|
|
877
585
|
const node = link.getNode();
|
|
878
586
|
if (node.isDirectory())
|
|
879
|
-
throw createError(EISDIR, 'open', link.getPath());
|
|
587
|
+
throw (0, util_1.createError)(EISDIR, 'open', link.getPath());
|
|
880
588
|
}
|
|
881
589
|
fd = this.openSync(id, flagsNum);
|
|
882
590
|
}
|
|
883
591
|
try {
|
|
884
|
-
result = bufferToEncoding(this.getFileByFdOrThrow(fd).getBuffer(), encoding);
|
|
592
|
+
result = (0, util_1.bufferToEncoding)(this.getFileByFdOrThrow(fd).getBuffer(), encoding);
|
|
885
593
|
}
|
|
886
594
|
finally {
|
|
887
595
|
if (!userOwnsFd) {
|
|
@@ -891,13 +599,13 @@ class Volume {
|
|
|
891
599
|
return result;
|
|
892
600
|
}
|
|
893
601
|
readFileSync(file, options) {
|
|
894
|
-
const opts = getReadFileOptions(options);
|
|
895
|
-
const flagsNum = flagsToNumber(opts.flag);
|
|
602
|
+
const opts = (0, options_1.getReadFileOptions)(options);
|
|
603
|
+
const flagsNum = (0, util_1.flagsToNumber)(opts.flag);
|
|
896
604
|
return this.readFileBase(file, flagsNum, opts.encoding);
|
|
897
605
|
}
|
|
898
606
|
readFile(id, a, b) {
|
|
899
|
-
const [opts, callback] = optsAndCbGenerator(getReadFileOptions)(a, b);
|
|
900
|
-
const flagsNum = flagsToNumber(opts.flag);
|
|
607
|
+
const [opts, callback] = (0, options_1.optsAndCbGenerator)(options_1.getReadFileOptions)(a, b);
|
|
608
|
+
const flagsNum = (0, util_1.flagsToNumber)(opts.flag);
|
|
901
609
|
this.wrapAsync(this.readFileBase, [id, flagsNum, opts.encoding], callback);
|
|
902
610
|
}
|
|
903
611
|
writeBase(fd, buf, offset, length, position) {
|
|
@@ -905,92 +613,15 @@ class Volume {
|
|
|
905
613
|
return file.write(buf, offset, length, position);
|
|
906
614
|
}
|
|
907
615
|
writeSync(fd, a, b, c, d) {
|
|
908
|
-
|
|
909
|
-
let encoding;
|
|
910
|
-
let offset;
|
|
911
|
-
let length;
|
|
912
|
-
let position;
|
|
913
|
-
const isBuffer = typeof a !== 'string';
|
|
914
|
-
if (isBuffer) {
|
|
915
|
-
offset = (b || 0) | 0;
|
|
916
|
-
length = c;
|
|
917
|
-
position = d;
|
|
918
|
-
}
|
|
919
|
-
else {
|
|
920
|
-
position = b;
|
|
921
|
-
encoding = c;
|
|
922
|
-
}
|
|
923
|
-
const buf = dataToBuffer(a, encoding);
|
|
924
|
-
if (isBuffer) {
|
|
925
|
-
if (typeof length === 'undefined') {
|
|
926
|
-
length = buf.length;
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
else {
|
|
930
|
-
offset = 0;
|
|
931
|
-
length = buf.length;
|
|
932
|
-
}
|
|
616
|
+
const [, buf, offset, length, position] = (0, util_1.getWriteSyncArgs)(fd, a, b, c, d);
|
|
933
617
|
return this.writeBase(fd, buf, offset, length, position);
|
|
934
618
|
}
|
|
935
619
|
write(fd, a, b, c, d, e) {
|
|
936
|
-
|
|
937
|
-
let offset;
|
|
938
|
-
let length;
|
|
939
|
-
let position;
|
|
940
|
-
let encoding;
|
|
941
|
-
let callback;
|
|
942
|
-
const tipa = typeof a;
|
|
943
|
-
const tipb = typeof b;
|
|
944
|
-
const tipc = typeof c;
|
|
945
|
-
const tipd = typeof d;
|
|
946
|
-
if (tipa !== 'string') {
|
|
947
|
-
if (tipb === 'function') {
|
|
948
|
-
callback = b;
|
|
949
|
-
}
|
|
950
|
-
else if (tipc === 'function') {
|
|
951
|
-
offset = b | 0;
|
|
952
|
-
callback = c;
|
|
953
|
-
}
|
|
954
|
-
else if (tipd === 'function') {
|
|
955
|
-
offset = b | 0;
|
|
956
|
-
length = c;
|
|
957
|
-
callback = d;
|
|
958
|
-
}
|
|
959
|
-
else {
|
|
960
|
-
offset = b | 0;
|
|
961
|
-
length = c;
|
|
962
|
-
position = d;
|
|
963
|
-
callback = e;
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
else {
|
|
967
|
-
if (tipb === 'function') {
|
|
968
|
-
callback = b;
|
|
969
|
-
}
|
|
970
|
-
else if (tipc === 'function') {
|
|
971
|
-
position = b;
|
|
972
|
-
callback = c;
|
|
973
|
-
}
|
|
974
|
-
else if (tipd === 'function') {
|
|
975
|
-
position = b;
|
|
976
|
-
encoding = c;
|
|
977
|
-
callback = d;
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
const buf = dataToBuffer(a, encoding);
|
|
981
|
-
if (tipa !== 'string') {
|
|
982
|
-
if (typeof length === 'undefined')
|
|
983
|
-
length = buf.length;
|
|
984
|
-
}
|
|
985
|
-
else {
|
|
986
|
-
offset = 0;
|
|
987
|
-
length = buf.length;
|
|
988
|
-
}
|
|
989
|
-
const cb = validateCallback(callback);
|
|
620
|
+
const [, asStr, buf, offset, length, position, cb] = (0, util_1.getWriteArgs)(fd, a, b, c, d, e);
|
|
990
621
|
(0, setImmediate_1.default)(() => {
|
|
991
622
|
try {
|
|
992
623
|
const bytes = this.writeBase(fd, buf, offset, length, position);
|
|
993
|
-
if (
|
|
624
|
+
if (!asStr) {
|
|
994
625
|
cb(null, bytes, buf);
|
|
995
626
|
}
|
|
996
627
|
else {
|
|
@@ -1002,6 +633,9 @@ class Volume {
|
|
|
1002
633
|
}
|
|
1003
634
|
});
|
|
1004
635
|
}
|
|
636
|
+
writev(fd, buffers, a, b) {
|
|
637
|
+
throw new Error('not implemented');
|
|
638
|
+
}
|
|
1005
639
|
writeFileBase(id, buf, flagsNum, modeNum) {
|
|
1006
640
|
// console.log('writeFileBase', id, buf, flagsNum, modeNum);
|
|
1007
641
|
// const node = this.getNodeByIdOrCreate(id, flagsNum, modeNum);
|
|
@@ -1011,7 +645,7 @@ class Volume {
|
|
|
1011
645
|
if (isUserFd)
|
|
1012
646
|
fd = id;
|
|
1013
647
|
else {
|
|
1014
|
-
fd = this.openBase(pathToFilename(id), flagsNum, modeNum);
|
|
648
|
+
fd = this.openBase((0, util_1.pathToFilename)(id), flagsNum, modeNum);
|
|
1015
649
|
// fd = this.openSync(id as PathLike, flagsNum, modeNum);
|
|
1016
650
|
}
|
|
1017
651
|
let offset = 0;
|
|
@@ -1032,40 +666,40 @@ class Volume {
|
|
|
1032
666
|
}
|
|
1033
667
|
}
|
|
1034
668
|
writeFileSync(id, data, options) {
|
|
1035
|
-
const opts = getWriteFileOptions(options);
|
|
1036
|
-
const flagsNum = flagsToNumber(opts.flag);
|
|
1037
|
-
const modeNum = modeToNumber(opts.mode);
|
|
1038
|
-
const buf = dataToBuffer(data, opts.encoding);
|
|
669
|
+
const opts = (0, options_1.getWriteFileOptions)(options);
|
|
670
|
+
const flagsNum = (0, util_1.flagsToNumber)(opts.flag);
|
|
671
|
+
const modeNum = (0, util_1.modeToNumber)(opts.mode);
|
|
672
|
+
const buf = (0, util_1.dataToBuffer)(data, opts.encoding);
|
|
1039
673
|
this.writeFileBase(id, buf, flagsNum, modeNum);
|
|
1040
674
|
}
|
|
1041
675
|
writeFile(id, data, a, b) {
|
|
1042
676
|
let options = a;
|
|
1043
677
|
let callback = b;
|
|
1044
678
|
if (typeof a === 'function') {
|
|
1045
|
-
options = writeFileDefaults;
|
|
679
|
+
options = options_1.writeFileDefaults;
|
|
1046
680
|
callback = a;
|
|
1047
681
|
}
|
|
1048
|
-
const cb = validateCallback(callback);
|
|
1049
|
-
const opts = getWriteFileOptions(options);
|
|
1050
|
-
const flagsNum = flagsToNumber(opts.flag);
|
|
1051
|
-
const modeNum = modeToNumber(opts.mode);
|
|
1052
|
-
const buf = dataToBuffer(data, opts.encoding);
|
|
682
|
+
const cb = (0, util_1.validateCallback)(callback);
|
|
683
|
+
const opts = (0, options_1.getWriteFileOptions)(options);
|
|
684
|
+
const flagsNum = (0, util_1.flagsToNumber)(opts.flag);
|
|
685
|
+
const modeNum = (0, util_1.modeToNumber)(opts.mode);
|
|
686
|
+
const buf = (0, util_1.dataToBuffer)(data, opts.encoding);
|
|
1053
687
|
this.wrapAsync(this.writeFileBase, [id, buf, flagsNum, modeNum], cb);
|
|
1054
688
|
}
|
|
1055
689
|
linkBase(filename1, filename2) {
|
|
1056
690
|
const steps1 = filenameToSteps(filename1);
|
|
1057
691
|
const link1 = this.getLink(steps1);
|
|
1058
692
|
if (!link1)
|
|
1059
|
-
throw createError(ENOENT, 'link', filename1, filename2);
|
|
693
|
+
throw (0, util_1.createError)(ENOENT, 'link', filename1, filename2);
|
|
1060
694
|
const steps2 = filenameToSteps(filename2);
|
|
1061
695
|
// Check new link directory exists.
|
|
1062
696
|
const dir2 = this.getLinkParent(steps2);
|
|
1063
697
|
if (!dir2)
|
|
1064
|
-
throw createError(ENOENT, 'link', filename1, filename2);
|
|
698
|
+
throw (0, util_1.createError)(ENOENT, 'link', filename1, filename2);
|
|
1065
699
|
const name = steps2[steps2.length - 1];
|
|
1066
700
|
// Check if new file already exists.
|
|
1067
701
|
if (dir2.getChild(name))
|
|
1068
|
-
throw createError(EEXIST, 'link', filename1, filename2);
|
|
702
|
+
throw (0, util_1.createError)(EEXIST, 'link', filename1, filename2);
|
|
1069
703
|
const node = link1.getNode();
|
|
1070
704
|
node.nlink++;
|
|
1071
705
|
dir2.createChild(name, node);
|
|
@@ -1074,22 +708,22 @@ class Volume {
|
|
|
1074
708
|
const buf = this.readFileSync(src);
|
|
1075
709
|
if (flags & COPYFILE_EXCL) {
|
|
1076
710
|
if (this.existsSync(dest)) {
|
|
1077
|
-
throw createError(EEXIST, 'copyFile', src, dest);
|
|
711
|
+
throw (0, util_1.createError)(EEXIST, 'copyFile', src, dest);
|
|
1078
712
|
}
|
|
1079
713
|
}
|
|
1080
714
|
if (flags & COPYFILE_FICLONE_FORCE) {
|
|
1081
|
-
throw createError(ENOSYS, 'copyFile', src, dest);
|
|
715
|
+
throw (0, util_1.createError)(ENOSYS, 'copyFile', src, dest);
|
|
1082
716
|
}
|
|
1083
|
-
this.writeFileBase(dest, buf, FLAGS.w, 438 /* MODE.DEFAULT */);
|
|
717
|
+
this.writeFileBase(dest, buf, constants_2.FLAGS.w, 438 /* MODE.DEFAULT */);
|
|
1084
718
|
}
|
|
1085
719
|
copyFileSync(src, dest, flags) {
|
|
1086
|
-
const srcFilename = pathToFilename(src);
|
|
1087
|
-
const destFilename = pathToFilename(dest);
|
|
720
|
+
const srcFilename = (0, util_1.pathToFilename)(src);
|
|
721
|
+
const destFilename = (0, util_1.pathToFilename)(dest);
|
|
1088
722
|
return this.copyFileBase(srcFilename, destFilename, (flags || 0) | 0);
|
|
1089
723
|
}
|
|
1090
724
|
copyFile(src, dest, a, b) {
|
|
1091
|
-
const srcFilename = pathToFilename(src);
|
|
1092
|
-
const destFilename = pathToFilename(dest);
|
|
725
|
+
const srcFilename = (0, util_1.pathToFilename)(src);
|
|
726
|
+
const destFilename = (0, util_1.pathToFilename)(dest);
|
|
1093
727
|
let flags;
|
|
1094
728
|
let callback;
|
|
1095
729
|
if (typeof a === 'function') {
|
|
@@ -1100,24 +734,24 @@ class Volume {
|
|
|
1100
734
|
flags = a;
|
|
1101
735
|
callback = b;
|
|
1102
736
|
}
|
|
1103
|
-
validateCallback(callback);
|
|
737
|
+
(0, util_1.validateCallback)(callback);
|
|
1104
738
|
this.wrapAsync(this.copyFileBase, [srcFilename, destFilename, flags], callback);
|
|
1105
739
|
}
|
|
1106
740
|
linkSync(existingPath, newPath) {
|
|
1107
|
-
const existingPathFilename = pathToFilename(existingPath);
|
|
1108
|
-
const newPathFilename = pathToFilename(newPath);
|
|
741
|
+
const existingPathFilename = (0, util_1.pathToFilename)(existingPath);
|
|
742
|
+
const newPathFilename = (0, util_1.pathToFilename)(newPath);
|
|
1109
743
|
this.linkBase(existingPathFilename, newPathFilename);
|
|
1110
744
|
}
|
|
1111
745
|
link(existingPath, newPath, callback) {
|
|
1112
|
-
const existingPathFilename = pathToFilename(existingPath);
|
|
1113
|
-
const newPathFilename = pathToFilename(newPath);
|
|
746
|
+
const existingPathFilename = (0, util_1.pathToFilename)(existingPath);
|
|
747
|
+
const newPathFilename = (0, util_1.pathToFilename)(newPath);
|
|
1114
748
|
this.wrapAsync(this.linkBase, [existingPathFilename, newPathFilename], callback);
|
|
1115
749
|
}
|
|
1116
750
|
unlinkBase(filename) {
|
|
1117
751
|
const steps = filenameToSteps(filename);
|
|
1118
752
|
const link = this.getLink(steps);
|
|
1119
753
|
if (!link)
|
|
1120
|
-
throw createError(ENOENT, 'unlink', filename);
|
|
754
|
+
throw (0, util_1.createError)(ENOENT, 'unlink', filename);
|
|
1121
755
|
// TODO: Check if it is file, dir, other...
|
|
1122
756
|
if (link.length)
|
|
1123
757
|
throw Error('Dir not empty...');
|
|
@@ -1130,11 +764,11 @@ class Volume {
|
|
|
1130
764
|
}
|
|
1131
765
|
}
|
|
1132
766
|
unlinkSync(path) {
|
|
1133
|
-
const filename = pathToFilename(path);
|
|
767
|
+
const filename = (0, util_1.pathToFilename)(path);
|
|
1134
768
|
this.unlinkBase(filename);
|
|
1135
769
|
}
|
|
1136
770
|
unlink(path, callback) {
|
|
1137
|
-
const filename = pathToFilename(path);
|
|
771
|
+
const filename = (0, util_1.pathToFilename)(path);
|
|
1138
772
|
this.wrapAsync(this.unlinkBase, [filename], callback);
|
|
1139
773
|
}
|
|
1140
774
|
symlinkBase(targetFilename, pathFilename) {
|
|
@@ -1142,11 +776,11 @@ class Volume {
|
|
|
1142
776
|
// Check if directory exists, where we about to create a symlink.
|
|
1143
777
|
const dirLink = this.getLinkParent(pathSteps);
|
|
1144
778
|
if (!dirLink)
|
|
1145
|
-
throw createError(ENOENT, 'symlink', targetFilename, pathFilename);
|
|
779
|
+
throw (0, util_1.createError)(ENOENT, 'symlink', targetFilename, pathFilename);
|
|
1146
780
|
const name = pathSteps[pathSteps.length - 1];
|
|
1147
781
|
// Check if new file already exists.
|
|
1148
782
|
if (dirLink.getChild(name))
|
|
1149
|
-
throw createError(EEXIST, 'symlink', targetFilename, pathFilename);
|
|
783
|
+
throw (0, util_1.createError)(EEXIST, 'symlink', targetFilename, pathFilename);
|
|
1150
784
|
// Create symlink.
|
|
1151
785
|
const symlink = dirLink.createChild(name);
|
|
1152
786
|
symlink.getNode().makeSymlink(filenameToSteps(targetFilename));
|
|
@@ -1154,29 +788,29 @@ class Volume {
|
|
|
1154
788
|
}
|
|
1155
789
|
// `type` argument works only on Windows.
|
|
1156
790
|
symlinkSync(target, path, type) {
|
|
1157
|
-
const targetFilename = pathToFilename(target);
|
|
1158
|
-
const pathFilename = pathToFilename(path);
|
|
791
|
+
const targetFilename = (0, util_1.pathToFilename)(target);
|
|
792
|
+
const pathFilename = (0, util_1.pathToFilename)(path);
|
|
1159
793
|
this.symlinkBase(targetFilename, pathFilename);
|
|
1160
794
|
}
|
|
1161
795
|
symlink(target, path, a, b) {
|
|
1162
|
-
const callback = validateCallback(typeof a === 'function' ? a : b);
|
|
1163
|
-
const targetFilename = pathToFilename(target);
|
|
1164
|
-
const pathFilename = pathToFilename(path);
|
|
796
|
+
const callback = (0, util_1.validateCallback)(typeof a === 'function' ? a : b);
|
|
797
|
+
const targetFilename = (0, util_1.pathToFilename)(target);
|
|
798
|
+
const pathFilename = (0, util_1.pathToFilename)(path);
|
|
1165
799
|
this.wrapAsync(this.symlinkBase, [targetFilename, pathFilename], callback);
|
|
1166
800
|
}
|
|
1167
801
|
realpathBase(filename, encoding) {
|
|
1168
802
|
const steps = filenameToSteps(filename);
|
|
1169
803
|
const realLink = this.getResolvedLink(steps);
|
|
1170
804
|
if (!realLink)
|
|
1171
|
-
throw createError(ENOENT, 'realpath', filename);
|
|
805
|
+
throw (0, util_1.createError)(ENOENT, 'realpath', filename);
|
|
1172
806
|
return (0, encoding_1.strToEncoding)(realLink.getPath() || '/', encoding);
|
|
1173
807
|
}
|
|
1174
808
|
realpathSync(path, options) {
|
|
1175
|
-
return this.realpathBase(pathToFilename(path), getRealpathOptions(options).encoding);
|
|
809
|
+
return this.realpathBase((0, util_1.pathToFilename)(path), (0, options_1.getRealpathOptions)(options).encoding);
|
|
1176
810
|
}
|
|
1177
811
|
realpath(path, a, b) {
|
|
1178
|
-
const [opts, callback] = getRealpathOptsAndCb(a, b);
|
|
1179
|
-
const pathFilename = pathToFilename(path);
|
|
812
|
+
const [opts, callback] = (0, options_1.getRealpathOptsAndCb)(a, b);
|
|
813
|
+
const pathFilename = (0, util_1.pathToFilename)(path);
|
|
1180
814
|
this.wrapAsync(this.realpathBase, [pathFilename, opts.encoding], callback);
|
|
1181
815
|
}
|
|
1182
816
|
lstatBase(filename, bigint = false, throwIfNoEntry = false) {
|
|
@@ -1188,16 +822,16 @@ class Volume {
|
|
|
1188
822
|
return undefined;
|
|
1189
823
|
}
|
|
1190
824
|
else {
|
|
1191
|
-
throw createError(ENOENT, 'lstat', filename);
|
|
825
|
+
throw (0, util_1.createError)(ENOENT, 'lstat', filename);
|
|
1192
826
|
}
|
|
1193
827
|
}
|
|
1194
828
|
lstatSync(path, options) {
|
|
1195
|
-
const { throwIfNoEntry = true, bigint = false } = getStatOptions(options);
|
|
1196
|
-
return this.lstatBase(pathToFilename(path), bigint, throwIfNoEntry);
|
|
829
|
+
const { throwIfNoEntry = true, bigint = false } = (0, options_1.getStatOptions)(options);
|
|
830
|
+
return this.lstatBase((0, util_1.pathToFilename)(path), bigint, throwIfNoEntry);
|
|
1197
831
|
}
|
|
1198
832
|
lstat(path, a, b) {
|
|
1199
|
-
const [{ throwIfNoEntry = true, bigint = false }, callback] = getStatOptsAndCb(a, b);
|
|
1200
|
-
this.wrapAsync(this.lstatBase, [pathToFilename(path), bigint, throwIfNoEntry], callback);
|
|
833
|
+
const [{ throwIfNoEntry = true, bigint = false }, callback] = (0, options_1.getStatOptsAndCb)(a, b);
|
|
834
|
+
this.wrapAsync(this.lstatBase, [(0, util_1.pathToFilename)(path), bigint, throwIfNoEntry], callback);
|
|
1201
835
|
}
|
|
1202
836
|
statBase(filename, bigint = false, throwIfNoEntry = true) {
|
|
1203
837
|
const link = this.getResolvedLink(filenameToSteps(filename));
|
|
@@ -1208,40 +842,40 @@ class Volume {
|
|
|
1208
842
|
return undefined;
|
|
1209
843
|
}
|
|
1210
844
|
else {
|
|
1211
|
-
throw createError(ENOENT, 'stat', filename);
|
|
845
|
+
throw (0, util_1.createError)(ENOENT, 'stat', filename);
|
|
1212
846
|
}
|
|
1213
847
|
}
|
|
1214
848
|
statSync(path, options) {
|
|
1215
|
-
const { bigint = true, throwIfNoEntry = true } = getStatOptions(options);
|
|
1216
|
-
return this.statBase(pathToFilename(path), bigint, throwIfNoEntry);
|
|
849
|
+
const { bigint = true, throwIfNoEntry = true } = (0, options_1.getStatOptions)(options);
|
|
850
|
+
return this.statBase((0, util_1.pathToFilename)(path), bigint, throwIfNoEntry);
|
|
1217
851
|
}
|
|
1218
852
|
stat(path, a, b) {
|
|
1219
|
-
const [{ bigint = false, throwIfNoEntry = true }, callback] = getStatOptsAndCb(a, b);
|
|
1220
|
-
this.wrapAsync(this.statBase, [pathToFilename(path), bigint, throwIfNoEntry], callback);
|
|
853
|
+
const [{ bigint = false, throwIfNoEntry = true }, callback] = (0, options_1.getStatOptsAndCb)(a, b);
|
|
854
|
+
this.wrapAsync(this.statBase, [(0, util_1.pathToFilename)(path), bigint, throwIfNoEntry], callback);
|
|
1221
855
|
}
|
|
1222
856
|
fstatBase(fd, bigint = false) {
|
|
1223
857
|
const file = this.getFileByFd(fd);
|
|
1224
858
|
if (!file)
|
|
1225
|
-
throw createError(EBADF, 'fstat');
|
|
859
|
+
throw (0, util_1.createError)(EBADF, 'fstat');
|
|
1226
860
|
return Stats_1.default.build(file.node, bigint);
|
|
1227
861
|
}
|
|
1228
862
|
fstatSync(fd, options) {
|
|
1229
|
-
return this.fstatBase(fd, getStatOptions(options).bigint);
|
|
863
|
+
return this.fstatBase(fd, (0, options_1.getStatOptions)(options).bigint);
|
|
1230
864
|
}
|
|
1231
865
|
fstat(fd, a, b) {
|
|
1232
|
-
const [opts, callback] = getStatOptsAndCb(a, b);
|
|
866
|
+
const [opts, callback] = (0, options_1.getStatOptsAndCb)(a, b);
|
|
1233
867
|
this.wrapAsync(this.fstatBase, [fd, opts.bigint], callback);
|
|
1234
868
|
}
|
|
1235
869
|
renameBase(oldPathFilename, newPathFilename) {
|
|
1236
870
|
const link = this.getLink(filenameToSteps(oldPathFilename));
|
|
1237
871
|
if (!link)
|
|
1238
|
-
throw createError(ENOENT, 'rename', oldPathFilename, newPathFilename);
|
|
872
|
+
throw (0, util_1.createError)(ENOENT, 'rename', oldPathFilename, newPathFilename);
|
|
1239
873
|
// TODO: Check if it is directory, if non-empty, we cannot move it, right?
|
|
1240
874
|
const newPathSteps = filenameToSteps(newPathFilename);
|
|
1241
875
|
// Check directory exists for the new location.
|
|
1242
876
|
const newPathDirLink = this.getLinkParent(newPathSteps);
|
|
1243
877
|
if (!newPathDirLink)
|
|
1244
|
-
throw createError(ENOENT, 'rename', oldPathFilename, newPathFilename);
|
|
878
|
+
throw (0, util_1.createError)(ENOENT, 'rename', oldPathFilename, newPathFilename);
|
|
1245
879
|
// TODO: Also treat cases with directories and symbolic links.
|
|
1246
880
|
// TODO: See: http://man7.org/linux/man-pages/man2/rename.2.html
|
|
1247
881
|
// Remove hard link from old folder.
|
|
@@ -1256,13 +890,13 @@ class Volume {
|
|
|
1256
890
|
newPathDirLink.setChild(link.getName(), link);
|
|
1257
891
|
}
|
|
1258
892
|
renameSync(oldPath, newPath) {
|
|
1259
|
-
const oldPathFilename = pathToFilename(oldPath);
|
|
1260
|
-
const newPathFilename = pathToFilename(newPath);
|
|
893
|
+
const oldPathFilename = (0, util_1.pathToFilename)(oldPath);
|
|
894
|
+
const newPathFilename = (0, util_1.pathToFilename)(newPath);
|
|
1261
895
|
this.renameBase(oldPathFilename, newPathFilename);
|
|
1262
896
|
}
|
|
1263
897
|
rename(oldPath, newPath, callback) {
|
|
1264
|
-
const oldPathFilename = pathToFilename(oldPath);
|
|
1265
|
-
const newPathFilename = pathToFilename(newPath);
|
|
898
|
+
const oldPathFilename = (0, util_1.pathToFilename)(oldPath);
|
|
899
|
+
const newPathFilename = (0, util_1.pathToFilename)(newPath);
|
|
1266
900
|
this.wrapAsync(this.renameBase, [oldPathFilename, newPathFilename], callback);
|
|
1267
901
|
}
|
|
1268
902
|
existsBase(filename) {
|
|
@@ -1270,16 +904,16 @@ class Volume {
|
|
|
1270
904
|
}
|
|
1271
905
|
existsSync(path) {
|
|
1272
906
|
try {
|
|
1273
|
-
return this.existsBase(pathToFilename(path));
|
|
907
|
+
return this.existsBase((0, util_1.pathToFilename)(path));
|
|
1274
908
|
}
|
|
1275
909
|
catch (err) {
|
|
1276
910
|
return false;
|
|
1277
911
|
}
|
|
1278
912
|
}
|
|
1279
913
|
exists(path, callback) {
|
|
1280
|
-
const filename = pathToFilename(path);
|
|
914
|
+
const filename = (0, util_1.pathToFilename)(path);
|
|
1281
915
|
if (typeof callback !== 'function')
|
|
1282
|
-
throw Error(ERRSTR.CB);
|
|
916
|
+
throw Error(constants_2.ERRSTR.CB);
|
|
1283
917
|
(0, setImmediate_1.default)(() => {
|
|
1284
918
|
try {
|
|
1285
919
|
callback(this.existsBase(filename));
|
|
@@ -1294,7 +928,7 @@ class Volume {
|
|
|
1294
928
|
// TODO: Verify permissions
|
|
1295
929
|
}
|
|
1296
930
|
accessSync(path, mode = F_OK) {
|
|
1297
|
-
const filename = pathToFilename(path);
|
|
931
|
+
const filename = (0, util_1.pathToFilename)(path);
|
|
1298
932
|
mode = mode | 0;
|
|
1299
933
|
this.accessBase(filename, mode);
|
|
1300
934
|
}
|
|
@@ -1303,25 +937,25 @@ class Volume {
|
|
|
1303
937
|
let callback;
|
|
1304
938
|
if (typeof a !== 'function') {
|
|
1305
939
|
mode = a | 0; // cast to number
|
|
1306
|
-
callback = validateCallback(b);
|
|
940
|
+
callback = (0, util_1.validateCallback)(b);
|
|
1307
941
|
}
|
|
1308
942
|
else {
|
|
1309
943
|
callback = a;
|
|
1310
944
|
}
|
|
1311
|
-
const filename = pathToFilename(path);
|
|
945
|
+
const filename = (0, util_1.pathToFilename)(path);
|
|
1312
946
|
this.wrapAsync(this.accessBase, [filename, mode], callback);
|
|
1313
947
|
}
|
|
1314
|
-
appendFileSync(id, data, options
|
|
1315
|
-
const opts = getAppendFileOpts(options);
|
|
948
|
+
appendFileSync(id, data, options) {
|
|
949
|
+
const opts = (0, options_1.getAppendFileOpts)(options);
|
|
1316
950
|
// force append behavior when using a supplied file descriptor
|
|
1317
|
-
if (!opts.flag || isFd(id))
|
|
951
|
+
if (!opts.flag || (0, util_1.isFd)(id))
|
|
1318
952
|
opts.flag = 'a';
|
|
1319
953
|
this.writeFileSync(id, data, opts);
|
|
1320
954
|
}
|
|
1321
955
|
appendFile(id, data, a, b) {
|
|
1322
|
-
const [opts, callback] = getAppendFileOptsAndCb(a, b);
|
|
956
|
+
const [opts, callback] = (0, options_1.getAppendFileOptsAndCb)(a, b);
|
|
1323
957
|
// force append behavior when using a supplied file descriptor
|
|
1324
|
-
if (!opts.flag || isFd(id))
|
|
958
|
+
if (!opts.flag || (0, util_1.isFd)(id))
|
|
1325
959
|
opts.flag = 'a';
|
|
1326
960
|
this.writeFile(id, data, opts, callback);
|
|
1327
961
|
}
|
|
@@ -1329,10 +963,10 @@ class Volume {
|
|
|
1329
963
|
const steps = filenameToSteps(filename);
|
|
1330
964
|
const link = this.getResolvedLink(steps);
|
|
1331
965
|
if (!link)
|
|
1332
|
-
throw createError(ENOENT, 'readdir', filename);
|
|
966
|
+
throw (0, util_1.createError)(ENOENT, 'readdir', filename);
|
|
1333
967
|
const node = link.getNode();
|
|
1334
968
|
if (!node.isDirectory())
|
|
1335
|
-
throw createError(ENOTDIR, 'scandir', filename);
|
|
969
|
+
throw (0, util_1.createError)(ENOTDIR, 'scandir', filename);
|
|
1336
970
|
if (options.withFileTypes) {
|
|
1337
971
|
const list = [];
|
|
1338
972
|
for (const name in link.children) {
|
|
@@ -1342,7 +976,7 @@ class Volume {
|
|
|
1342
976
|
}
|
|
1343
977
|
list.push(Dirent_1.default.build(child, options.encoding));
|
|
1344
978
|
}
|
|
1345
|
-
if (!isWin && options.encoding !== 'buffer')
|
|
979
|
+
if (!util_1.isWin && options.encoding !== 'buffer')
|
|
1346
980
|
list.sort((a, b) => {
|
|
1347
981
|
if (a.name < b.name)
|
|
1348
982
|
return -1;
|
|
@@ -1359,36 +993,36 @@ class Volume {
|
|
|
1359
993
|
}
|
|
1360
994
|
list.push((0, encoding_1.strToEncoding)(name, options.encoding));
|
|
1361
995
|
}
|
|
1362
|
-
if (!isWin && options.encoding !== 'buffer')
|
|
996
|
+
if (!util_1.isWin && options.encoding !== 'buffer')
|
|
1363
997
|
list.sort();
|
|
1364
998
|
return list;
|
|
1365
999
|
}
|
|
1366
1000
|
readdirSync(path, options) {
|
|
1367
|
-
const opts = getReaddirOptions(options);
|
|
1368
|
-
const filename = pathToFilename(path);
|
|
1001
|
+
const opts = (0, options_1.getReaddirOptions)(options);
|
|
1002
|
+
const filename = (0, util_1.pathToFilename)(path);
|
|
1369
1003
|
return this.readdirBase(filename, opts);
|
|
1370
1004
|
}
|
|
1371
1005
|
readdir(path, a, b) {
|
|
1372
|
-
const [options, callback] = getReaddirOptsAndCb(a, b);
|
|
1373
|
-
const filename = pathToFilename(path);
|
|
1006
|
+
const [options, callback] = (0, options_1.getReaddirOptsAndCb)(a, b);
|
|
1007
|
+
const filename = (0, util_1.pathToFilename)(path);
|
|
1374
1008
|
this.wrapAsync(this.readdirBase, [filename, options], callback);
|
|
1375
1009
|
}
|
|
1376
1010
|
readlinkBase(filename, encoding) {
|
|
1377
1011
|
const link = this.getLinkOrThrow(filename, 'readlink');
|
|
1378
1012
|
const node = link.getNode();
|
|
1379
1013
|
if (!node.isSymlink())
|
|
1380
|
-
throw createError(EINVAL, 'readlink', filename);
|
|
1014
|
+
throw (0, util_1.createError)(EINVAL, 'readlink', filename);
|
|
1381
1015
|
const str = sep + node.symlink.join(sep);
|
|
1382
1016
|
return (0, encoding_1.strToEncoding)(str, encoding);
|
|
1383
1017
|
}
|
|
1384
1018
|
readlinkSync(path, options) {
|
|
1385
|
-
const opts = getDefaultOpts(options);
|
|
1386
|
-
const filename = pathToFilename(path);
|
|
1019
|
+
const opts = (0, options_1.getDefaultOpts)(options);
|
|
1020
|
+
const filename = (0, util_1.pathToFilename)(path);
|
|
1387
1021
|
return this.readlinkBase(filename, opts.encoding);
|
|
1388
1022
|
}
|
|
1389
1023
|
readlink(path, a, b) {
|
|
1390
|
-
const [opts, callback] = getDefaultOptsAndCb(a, b);
|
|
1391
|
-
const filename = pathToFilename(path);
|
|
1024
|
+
const [opts, callback] = (0, options_1.getDefaultOptsAndCb)(a, b);
|
|
1025
|
+
const filename = (0, util_1.pathToFilename)(path);
|
|
1392
1026
|
this.wrapAsync(this.readlinkBase, [filename, opts.encoding], callback);
|
|
1393
1027
|
}
|
|
1394
1028
|
fsyncBase(fd) {
|
|
@@ -1418,7 +1052,7 @@ class Volume {
|
|
|
1418
1052
|
}
|
|
1419
1053
|
ftruncate(fd, a, b) {
|
|
1420
1054
|
const len = typeof a === 'number' ? a : 0;
|
|
1421
|
-
const callback = validateCallback(typeof a === 'number' ? b : a);
|
|
1055
|
+
const callback = (0, util_1.validateCallback)(typeof a === 'number' ? b : a);
|
|
1422
1056
|
this.wrapAsync(this.ftruncateBase, [fd, len], callback);
|
|
1423
1057
|
}
|
|
1424
1058
|
truncateBase(path, len) {
|
|
@@ -1430,15 +1064,19 @@ class Volume {
|
|
|
1430
1064
|
this.closeSync(fd);
|
|
1431
1065
|
}
|
|
1432
1066
|
}
|
|
1067
|
+
/**
|
|
1068
|
+
* `id` should be a file descriptor or a path. `id` as file descriptor will
|
|
1069
|
+
* not be supported soon.
|
|
1070
|
+
*/
|
|
1433
1071
|
truncateSync(id, len) {
|
|
1434
|
-
if (isFd(id))
|
|
1072
|
+
if ((0, util_1.isFd)(id))
|
|
1435
1073
|
return this.ftruncateSync(id, len);
|
|
1436
1074
|
this.truncateBase(id, len);
|
|
1437
1075
|
}
|
|
1438
1076
|
truncate(id, a, b) {
|
|
1439
1077
|
const len = typeof a === 'number' ? a : 0;
|
|
1440
|
-
const callback = validateCallback(typeof a === 'number' ? b : a);
|
|
1441
|
-
if (isFd(id))
|
|
1078
|
+
const callback = (0, util_1.validateCallback)(typeof a === 'number' ? b : a);
|
|
1079
|
+
if ((0, util_1.isFd)(id))
|
|
1442
1080
|
return this.ftruncate(id, len, callback);
|
|
1443
1081
|
this.wrapAsync(this.truncateBase, [id, len], callback);
|
|
1444
1082
|
}
|
|
@@ -1464,22 +1102,22 @@ class Volume {
|
|
|
1464
1102
|
}
|
|
1465
1103
|
}
|
|
1466
1104
|
utimesSync(path, atime, mtime) {
|
|
1467
|
-
this.utimesBase(pathToFilename(path), toUnixTimestamp(atime), toUnixTimestamp(mtime));
|
|
1105
|
+
this.utimesBase((0, util_1.pathToFilename)(path), toUnixTimestamp(atime), toUnixTimestamp(mtime));
|
|
1468
1106
|
}
|
|
1469
1107
|
utimes(path, atime, mtime, callback) {
|
|
1470
|
-
this.wrapAsync(this.utimesBase, [pathToFilename(path), toUnixTimestamp(atime), toUnixTimestamp(mtime)], callback);
|
|
1108
|
+
this.wrapAsync(this.utimesBase, [(0, util_1.pathToFilename)(path), toUnixTimestamp(atime), toUnixTimestamp(mtime)], callback);
|
|
1471
1109
|
}
|
|
1472
1110
|
mkdirBase(filename, modeNum) {
|
|
1473
1111
|
const steps = filenameToSteps(filename);
|
|
1474
1112
|
// This will throw if user tries to create root dir `fs.mkdirSync('/')`.
|
|
1475
1113
|
if (!steps.length) {
|
|
1476
|
-
throw createError(EEXIST, 'mkdir', filename);
|
|
1114
|
+
throw (0, util_1.createError)(EEXIST, 'mkdir', filename);
|
|
1477
1115
|
}
|
|
1478
1116
|
const dir = this.getLinkParentAsDirOrThrow(filename, 'mkdir');
|
|
1479
1117
|
// Check path already exists.
|
|
1480
1118
|
const name = steps[steps.length - 1];
|
|
1481
1119
|
if (dir.getChild(name))
|
|
1482
|
-
throw createError(EEXIST, 'mkdir', filename);
|
|
1120
|
+
throw (0, util_1.createError)(EEXIST, 'mkdir', filename);
|
|
1483
1121
|
dir.createChild(name, this.createNode(true, modeNum));
|
|
1484
1122
|
}
|
|
1485
1123
|
/**
|
|
@@ -1496,13 +1134,13 @@ class Volume {
|
|
|
1496
1134
|
for (let i = 0; i < steps.length; i++) {
|
|
1497
1135
|
const step = steps[i];
|
|
1498
1136
|
if (!link.getNode().isDirectory())
|
|
1499
|
-
throw createError(ENOTDIR, 'mkdir', link.getPath());
|
|
1137
|
+
throw (0, util_1.createError)(ENOTDIR, 'mkdir', link.getPath());
|
|
1500
1138
|
const child = link.getChild(step);
|
|
1501
1139
|
if (child) {
|
|
1502
1140
|
if (child.getNode().isDirectory())
|
|
1503
1141
|
link = child;
|
|
1504
1142
|
else
|
|
1505
|
-
throw createError(ENOTDIR, 'mkdir', child.getPath());
|
|
1143
|
+
throw (0, util_1.createError)(ENOTDIR, 'mkdir', child.getPath());
|
|
1506
1144
|
}
|
|
1507
1145
|
else {
|
|
1508
1146
|
link = link.createChild(step, this.createNode(true, modeNum));
|
|
@@ -1512,18 +1150,18 @@ class Volume {
|
|
|
1512
1150
|
return created ? fullPath : undefined;
|
|
1513
1151
|
}
|
|
1514
1152
|
mkdirSync(path, options) {
|
|
1515
|
-
const opts = getMkdirOptions(options);
|
|
1516
|
-
const modeNum = modeToNumber(opts.mode, 0o777);
|
|
1517
|
-
const filename = pathToFilename(path);
|
|
1153
|
+
const opts = (0, options_1.getMkdirOptions)(options);
|
|
1154
|
+
const modeNum = (0, util_1.modeToNumber)(opts.mode, 0o777);
|
|
1155
|
+
const filename = (0, util_1.pathToFilename)(path);
|
|
1518
1156
|
if (opts.recursive)
|
|
1519
1157
|
return this.mkdirpBase(filename, modeNum);
|
|
1520
1158
|
this.mkdirBase(filename, modeNum);
|
|
1521
1159
|
}
|
|
1522
1160
|
mkdir(path, a, b) {
|
|
1523
|
-
const opts = getMkdirOptions(a);
|
|
1524
|
-
const callback = validateCallback(typeof a === 'function' ? a : b);
|
|
1525
|
-
const modeNum = modeToNumber(opts.mode, 0o777);
|
|
1526
|
-
const filename = pathToFilename(path);
|
|
1161
|
+
const opts = (0, options_1.getMkdirOptions)(a);
|
|
1162
|
+
const callback = (0, util_1.validateCallback)(typeof a === 'function' ? a : b);
|
|
1163
|
+
const modeNum = (0, util_1.modeToNumber)(opts.mode, 0o777);
|
|
1164
|
+
const filename = (0, util_1.pathToFilename)(path);
|
|
1527
1165
|
if (opts.recursive)
|
|
1528
1166
|
this.wrapAsync(this.mkdirpBase, [filename, modeNum], callback);
|
|
1529
1167
|
else
|
|
@@ -1535,11 +1173,11 @@ class Volume {
|
|
|
1535
1173
|
}
|
|
1536
1174
|
mkdirp(path, a, b) {
|
|
1537
1175
|
const mode = typeof a === 'function' ? undefined : a;
|
|
1538
|
-
const callback = validateCallback(typeof a === 'function' ? a : b);
|
|
1176
|
+
const callback = (0, util_1.validateCallback)(typeof a === 'function' ? a : b);
|
|
1539
1177
|
this.mkdir(path, { mode, recursive: true }, callback);
|
|
1540
1178
|
}
|
|
1541
1179
|
mkdtempBase(prefix, encoding, retry = 5) {
|
|
1542
|
-
const filename = prefix +
|
|
1180
|
+
const filename = prefix + (0, util_1.genRndStr6)();
|
|
1543
1181
|
try {
|
|
1544
1182
|
this.mkdirBase(filename, 511 /* MODE.DIR */);
|
|
1545
1183
|
return (0, encoding_1.strToEncoding)(filename, encoding);
|
|
@@ -1556,67 +1194,67 @@ class Volume {
|
|
|
1556
1194
|
}
|
|
1557
1195
|
}
|
|
1558
1196
|
mkdtempSync(prefix, options) {
|
|
1559
|
-
const { encoding } = getDefaultOpts(options);
|
|
1197
|
+
const { encoding } = (0, options_1.getDefaultOpts)(options);
|
|
1560
1198
|
if (!prefix || typeof prefix !== 'string')
|
|
1561
1199
|
throw new TypeError('filename prefix is required');
|
|
1562
|
-
nullCheck(prefix);
|
|
1200
|
+
(0, util_1.nullCheck)(prefix);
|
|
1563
1201
|
return this.mkdtempBase(prefix, encoding);
|
|
1564
1202
|
}
|
|
1565
1203
|
mkdtemp(prefix, a, b) {
|
|
1566
|
-
const [{ encoding }, callback] = getDefaultOptsAndCb(a, b);
|
|
1204
|
+
const [{ encoding }, callback] = (0, options_1.getDefaultOptsAndCb)(a, b);
|
|
1567
1205
|
if (!prefix || typeof prefix !== 'string')
|
|
1568
1206
|
throw new TypeError('filename prefix is required');
|
|
1569
|
-
if (!nullCheck(prefix))
|
|
1207
|
+
if (!(0, util_1.nullCheck)(prefix))
|
|
1570
1208
|
return;
|
|
1571
1209
|
this.wrapAsync(this.mkdtempBase, [prefix, encoding], callback);
|
|
1572
1210
|
}
|
|
1573
1211
|
rmdirBase(filename, options) {
|
|
1574
|
-
const opts = getRmdirOptions(options);
|
|
1212
|
+
const opts = (0, options_1.getRmdirOptions)(options);
|
|
1575
1213
|
const link = this.getLinkAsDirOrThrow(filename, 'rmdir');
|
|
1576
1214
|
// Check directory is empty.
|
|
1577
1215
|
if (link.length && !opts.recursive)
|
|
1578
|
-
throw createError(ENOTEMPTY, 'rmdir', filename);
|
|
1216
|
+
throw (0, util_1.createError)(ENOTEMPTY, 'rmdir', filename);
|
|
1579
1217
|
this.deleteLink(link);
|
|
1580
1218
|
}
|
|
1581
1219
|
rmdirSync(path, options) {
|
|
1582
|
-
this.rmdirBase(pathToFilename(path), options);
|
|
1220
|
+
this.rmdirBase((0, util_1.pathToFilename)(path), options);
|
|
1583
1221
|
}
|
|
1584
1222
|
rmdir(path, a, b) {
|
|
1585
|
-
const opts = getRmdirOptions(a);
|
|
1586
|
-
const callback = validateCallback(typeof a === 'function' ? a : b);
|
|
1587
|
-
this.wrapAsync(this.rmdirBase, [pathToFilename(path), opts], callback);
|
|
1223
|
+
const opts = (0, options_1.getRmdirOptions)(a);
|
|
1224
|
+
const callback = (0, util_1.validateCallback)(typeof a === 'function' ? a : b);
|
|
1225
|
+
this.wrapAsync(this.rmdirBase, [(0, util_1.pathToFilename)(path), opts], callback);
|
|
1588
1226
|
}
|
|
1589
1227
|
rmBase(filename, options = {}) {
|
|
1590
1228
|
const link = this.getResolvedLink(filename);
|
|
1591
1229
|
if (!link) {
|
|
1592
1230
|
// "stat" is used to match Node's native error message.
|
|
1593
1231
|
if (!options.force)
|
|
1594
|
-
throw createError(ENOENT, 'stat', filename);
|
|
1232
|
+
throw (0, util_1.createError)(ENOENT, 'stat', filename);
|
|
1595
1233
|
return;
|
|
1596
1234
|
}
|
|
1597
1235
|
if (link.getNode().isDirectory()) {
|
|
1598
1236
|
if (!options.recursive) {
|
|
1599
|
-
throw createError(ERR_FS_EISDIR, 'rm', filename);
|
|
1237
|
+
throw (0, util_1.createError)(ERR_FS_EISDIR, 'rm', filename);
|
|
1600
1238
|
}
|
|
1601
1239
|
}
|
|
1602
1240
|
this.deleteLink(link);
|
|
1603
1241
|
}
|
|
1604
1242
|
rmSync(path, options) {
|
|
1605
|
-
this.rmBase(pathToFilename(path), options);
|
|
1243
|
+
this.rmBase((0, util_1.pathToFilename)(path), options);
|
|
1606
1244
|
}
|
|
1607
1245
|
rm(path, a, b) {
|
|
1608
|
-
const [opts, callback] = getRmOptsAndCb(a, b);
|
|
1609
|
-
this.wrapAsync(this.rmBase, [pathToFilename(path), opts], callback);
|
|
1246
|
+
const [opts, callback] = (0, options_1.getRmOptsAndCb)(a, b);
|
|
1247
|
+
this.wrapAsync(this.rmBase, [(0, util_1.pathToFilename)(path), opts], callback);
|
|
1610
1248
|
}
|
|
1611
1249
|
fchmodBase(fd, modeNum) {
|
|
1612
1250
|
const file = this.getFileByFdOrThrow(fd, 'fchmod');
|
|
1613
1251
|
file.chmod(modeNum);
|
|
1614
1252
|
}
|
|
1615
1253
|
fchmodSync(fd, mode) {
|
|
1616
|
-
this.fchmodBase(fd, modeToNumber(mode));
|
|
1254
|
+
this.fchmodBase(fd, (0, util_1.modeToNumber)(mode));
|
|
1617
1255
|
}
|
|
1618
1256
|
fchmod(fd, mode, callback) {
|
|
1619
|
-
this.wrapAsync(this.fchmodBase, [fd, modeToNumber(mode)], callback);
|
|
1257
|
+
this.wrapAsync(this.fchmodBase, [fd, (0, util_1.modeToNumber)(mode)], callback);
|
|
1620
1258
|
}
|
|
1621
1259
|
chmodBase(filename, modeNum) {
|
|
1622
1260
|
const fd = this.openSync(filename, 'r');
|
|
@@ -1628,13 +1266,13 @@ class Volume {
|
|
|
1628
1266
|
}
|
|
1629
1267
|
}
|
|
1630
1268
|
chmodSync(path, mode) {
|
|
1631
|
-
const modeNum = modeToNumber(mode);
|
|
1632
|
-
const filename = pathToFilename(path);
|
|
1269
|
+
const modeNum = (0, util_1.modeToNumber)(mode);
|
|
1270
|
+
const filename = (0, util_1.pathToFilename)(path);
|
|
1633
1271
|
this.chmodBase(filename, modeNum);
|
|
1634
1272
|
}
|
|
1635
1273
|
chmod(path, mode, callback) {
|
|
1636
|
-
const modeNum = modeToNumber(mode);
|
|
1637
|
-
const filename = pathToFilename(path);
|
|
1274
|
+
const modeNum = (0, util_1.modeToNumber)(mode);
|
|
1275
|
+
const filename = (0, util_1.pathToFilename)(path);
|
|
1638
1276
|
this.wrapAsync(this.chmodBase, [filename, modeNum], callback);
|
|
1639
1277
|
}
|
|
1640
1278
|
lchmodBase(filename, modeNum) {
|
|
@@ -1647,13 +1285,13 @@ class Volume {
|
|
|
1647
1285
|
}
|
|
1648
1286
|
}
|
|
1649
1287
|
lchmodSync(path, mode) {
|
|
1650
|
-
const modeNum = modeToNumber(mode);
|
|
1651
|
-
const filename = pathToFilename(path);
|
|
1288
|
+
const modeNum = (0, util_1.modeToNumber)(mode);
|
|
1289
|
+
const filename = (0, util_1.pathToFilename)(path);
|
|
1652
1290
|
this.lchmodBase(filename, modeNum);
|
|
1653
1291
|
}
|
|
1654
1292
|
lchmod(path, mode, callback) {
|
|
1655
|
-
const modeNum = modeToNumber(mode);
|
|
1656
|
-
const filename = pathToFilename(path);
|
|
1293
|
+
const modeNum = (0, util_1.modeToNumber)(mode);
|
|
1294
|
+
const filename = (0, util_1.pathToFilename)(path);
|
|
1657
1295
|
this.wrapAsync(this.lchmodBase, [filename, modeNum], callback);
|
|
1658
1296
|
}
|
|
1659
1297
|
fchownBase(fd, uid, gid) {
|
|
@@ -1684,12 +1322,12 @@ class Volume {
|
|
|
1684
1322
|
chownSync(path, uid, gid) {
|
|
1685
1323
|
validateUid(uid);
|
|
1686
1324
|
validateGid(gid);
|
|
1687
|
-
this.chownBase(pathToFilename(path), uid, gid);
|
|
1325
|
+
this.chownBase((0, util_1.pathToFilename)(path), uid, gid);
|
|
1688
1326
|
}
|
|
1689
1327
|
chown(path, uid, gid, callback) {
|
|
1690
1328
|
validateUid(uid);
|
|
1691
1329
|
validateGid(gid);
|
|
1692
|
-
this.wrapAsync(this.chownBase, [pathToFilename(path), uid, gid], callback);
|
|
1330
|
+
this.wrapAsync(this.chownBase, [(0, util_1.pathToFilename)(path), uid, gid], callback);
|
|
1693
1331
|
}
|
|
1694
1332
|
lchownBase(filename, uid, gid) {
|
|
1695
1333
|
this.getLinkOrThrow(filename, 'lchown').getNode().chown(uid, gid);
|
|
@@ -1697,15 +1335,15 @@ class Volume {
|
|
|
1697
1335
|
lchownSync(path, uid, gid) {
|
|
1698
1336
|
validateUid(uid);
|
|
1699
1337
|
validateGid(gid);
|
|
1700
|
-
this.lchownBase(pathToFilename(path), uid, gid);
|
|
1338
|
+
this.lchownBase((0, util_1.pathToFilename)(path), uid, gid);
|
|
1701
1339
|
}
|
|
1702
1340
|
lchown(path, uid, gid, callback) {
|
|
1703
1341
|
validateUid(uid);
|
|
1704
1342
|
validateGid(gid);
|
|
1705
|
-
this.wrapAsync(this.lchownBase, [pathToFilename(path), uid, gid], callback);
|
|
1343
|
+
this.wrapAsync(this.lchownBase, [(0, util_1.pathToFilename)(path), uid, gid], callback);
|
|
1706
1344
|
}
|
|
1707
1345
|
watchFile(path, a, b) {
|
|
1708
|
-
const filename = pathToFilename(path);
|
|
1346
|
+
const filename = (0, util_1.pathToFilename)(path);
|
|
1709
1347
|
let options = a;
|
|
1710
1348
|
let listener = b;
|
|
1711
1349
|
if (typeof options === 'function') {
|
|
@@ -1733,7 +1371,7 @@ class Volume {
|
|
|
1733
1371
|
return watcher;
|
|
1734
1372
|
}
|
|
1735
1373
|
unwatchFile(path, listener) {
|
|
1736
|
-
const filename = pathToFilename(path);
|
|
1374
|
+
const filename = (0, util_1.pathToFilename)(path);
|
|
1737
1375
|
const watcher = this.statWatchers[filename];
|
|
1738
1376
|
if (!watcher)
|
|
1739
1377
|
return;
|
|
@@ -1757,14 +1395,14 @@ class Volume {
|
|
|
1757
1395
|
// watch(path: PathLike): FSWatcher;
|
|
1758
1396
|
// watch(path: PathLike, options?: IWatchOptions | string): FSWatcher;
|
|
1759
1397
|
watch(path, options, listener) {
|
|
1760
|
-
const filename = pathToFilename(path);
|
|
1398
|
+
const filename = (0, util_1.pathToFilename)(path);
|
|
1761
1399
|
let givenOptions = options;
|
|
1762
1400
|
if (typeof options === 'function') {
|
|
1763
1401
|
listener = options;
|
|
1764
1402
|
givenOptions = null;
|
|
1765
1403
|
}
|
|
1766
1404
|
// tslint:disable-next-line prefer-const
|
|
1767
|
-
let { persistent, recursive, encoding } = getDefaultOpts(givenOptions);
|
|
1405
|
+
let { persistent, recursive, encoding } = (0, options_1.getDefaultOpts)(givenOptions);
|
|
1768
1406
|
if (persistent === undefined)
|
|
1769
1407
|
persistent = true;
|
|
1770
1408
|
if (recursive === undefined)
|
|
@@ -1818,7 +1456,7 @@ class StatWatcher extends events_1.EventEmitter {
|
|
|
1818
1456
|
return false;
|
|
1819
1457
|
}
|
|
1820
1458
|
start(path, persistent = true, interval = 5007) {
|
|
1821
|
-
this.filename = pathToFilename(path);
|
|
1459
|
+
this.filename = (0, util_1.pathToFilename)(path);
|
|
1822
1460
|
this.setTimeout = persistent
|
|
1823
1461
|
? setTimeout.bind(typeof globalThis !== 'undefined' ? globalThis : global)
|
|
1824
1462
|
: setTimeoutUnref_1.default;
|
|
@@ -1832,6 +1470,8 @@ class StatWatcher extends events_1.EventEmitter {
|
|
|
1832
1470
|
}
|
|
1833
1471
|
}
|
|
1834
1472
|
exports.StatWatcher = StatWatcher;
|
|
1473
|
+
/* tslint:disable no-var-keyword prefer-const */
|
|
1474
|
+
// ---------------------------------------- ReadStream
|
|
1835
1475
|
var pool;
|
|
1836
1476
|
function allocNewPool(poolSize) {
|
|
1837
1477
|
pool = (0, buffer_1.bufferAllocUnsafe)(poolSize);
|
|
@@ -1844,11 +1484,11 @@ function FsReadStream(vol, path, options) {
|
|
|
1844
1484
|
return new FsReadStream(vol, path, options);
|
|
1845
1485
|
this._vol = vol;
|
|
1846
1486
|
// a little bit bigger buffer and water marks by default
|
|
1847
|
-
options = Object.assign({}, getOptions(options, {}));
|
|
1487
|
+
options = Object.assign({}, (0, options_1.getOptions)(options, {}));
|
|
1848
1488
|
if (options.highWaterMark === undefined)
|
|
1849
1489
|
options.highWaterMark = 64 * 1024;
|
|
1850
1490
|
stream_1.Readable.call(this, options);
|
|
1851
|
-
this.path = pathToFilename(path);
|
|
1491
|
+
this.path = (0, util_1.pathToFilename)(path);
|
|
1852
1492
|
this.fd = options.fd === undefined ? null : options.fd;
|
|
1853
1493
|
this.flags = options.flags === undefined ? 'r' : options.flags;
|
|
1854
1494
|
this.mode = options.mode === undefined ? 0o666 : options.mode;
|
|
@@ -1990,9 +1630,9 @@ function FsWriteStream(vol, path, options) {
|
|
|
1990
1630
|
if (!(this instanceof FsWriteStream))
|
|
1991
1631
|
return new FsWriteStream(vol, path, options);
|
|
1992
1632
|
this._vol = vol;
|
|
1993
|
-
options = Object.assign({}, getOptions(options, {}));
|
|
1633
|
+
options = Object.assign({}, (0, options_1.getOptions)(options, {}));
|
|
1994
1634
|
stream_1.Writable.call(this, options);
|
|
1995
|
-
this.path = pathToFilename(path);
|
|
1635
|
+
this.path = (0, util_1.pathToFilename)(path);
|
|
1996
1636
|
this.fd = options.fd === undefined ? null : options.fd;
|
|
1997
1637
|
this.flags = options.flags === undefined ? 'w' : options.flags;
|
|
1998
1638
|
this.mode = options.mode === undefined ? 0o666 : options.mode;
|
|
@@ -2000,6 +1640,7 @@ function FsWriteStream(vol, path, options) {
|
|
|
2000
1640
|
this.autoClose = options.autoClose === undefined ? true : !!options.autoClose;
|
|
2001
1641
|
this.pos = undefined;
|
|
2002
1642
|
this.bytesWritten = 0;
|
|
1643
|
+
this.pending = true;
|
|
2003
1644
|
if (this.start !== undefined) {
|
|
2004
1645
|
if (typeof this.start !== 'number') {
|
|
2005
1646
|
throw new TypeError('"start" option must be a Number');
|
|
@@ -2030,6 +1671,7 @@ FsWriteStream.prototype.open = function () {
|
|
|
2030
1671
|
return;
|
|
2031
1672
|
}
|
|
2032
1673
|
this.fd = fd;
|
|
1674
|
+
this.pending = false;
|
|
2033
1675
|
this.emit('open', fd);
|
|
2034
1676
|
}.bind(this));
|
|
2035
1677
|
};
|
|
@@ -2155,7 +1797,7 @@ class FSWatcher extends events_1.EventEmitter {
|
|
|
2155
1797
|
return this._steps[this._steps.length - 1];
|
|
2156
1798
|
}
|
|
2157
1799
|
start(path, persistent = true, recursive = false, encoding = encoding_1.ENCODING_UTF8) {
|
|
2158
|
-
this._filename = pathToFilename(path);
|
|
1800
|
+
this._filename = (0, util_1.pathToFilename)(path);
|
|
2159
1801
|
this._steps = filenameToSteps(this._filename);
|
|
2160
1802
|
this._filenameEncoded = (0, encoding_1.strToEncoding)(this._filename);
|
|
2161
1803
|
// this._persistent = persistent;
|