@zenfs/core 0.0.12 → 0.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/dist/ApiError.d.ts +1 -1
- package/dist/ApiError.js +17 -16
- package/dist/backends/AsyncMirror.js +40 -46
- package/dist/backends/AsyncStore.js +326 -383
- package/dist/backends/FolderAdapter.js +8 -19
- package/dist/backends/Locked.js +91 -137
- package/dist/backends/OverlayFS.js +234 -279
- package/dist/backends/SyncStore.js +2 -2
- package/dist/backends/backend.d.ts +6 -6
- package/dist/browser.min.js +23 -6
- package/dist/browser.min.js.map +4 -4
- package/dist/emulation/callbacks.d.ts +109 -72
- package/dist/emulation/callbacks.js +40 -47
- package/dist/emulation/dir.d.ts +55 -0
- package/dist/emulation/dir.js +104 -0
- package/dist/emulation/fs.d.ts +1 -2
- package/dist/emulation/fs.js +0 -1
- package/dist/emulation/index.d.ts +3 -0
- package/dist/emulation/index.js +3 -0
- package/dist/emulation/promises.d.ts +71 -50
- package/dist/emulation/promises.js +243 -342
- package/dist/emulation/shared.d.ts +14 -0
- package/dist/emulation/shared.js +4 -3
- package/dist/emulation/streams.d.ts +102 -0
- package/dist/emulation/streams.js +55 -0
- package/dist/emulation/sync.d.ts +81 -52
- package/dist/emulation/sync.js +98 -65
- package/dist/file.d.ts +11 -5
- package/dist/file.js +79 -76
- package/dist/filesystem.d.ts +3 -3
- package/dist/filesystem.js +181 -262
- package/dist/index.d.ts +3 -3
- package/dist/index.js +39 -53
- package/dist/stats.d.ts +80 -27
- package/dist/stats.js +142 -93
- package/dist/utils.d.ts +2 -6
- package/dist/utils.js +79 -78
- package/package.json +4 -2
- package/readme.md +2 -40
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
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) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { ApiError, ErrorCode } from '../ApiError.js';
|
|
11
2
|
import * as constants from './constants.js';
|
|
12
3
|
export { constants };
|
|
13
4
|
import { FileFlag } from '../file.js';
|
|
14
5
|
import { normalizePath, normalizeMode, getFdForFile, normalizeOptions, fd2file, fdMap, normalizeTime, cred, nop, resolveFS, fixError, mounts } from './shared.js';
|
|
6
|
+
import { BigIntStats } from '../stats.js';
|
|
15
7
|
import { decode, encode } from '../utils.js';
|
|
8
|
+
import { Dirent } from './dir.js';
|
|
9
|
+
import { join } from './path.js';
|
|
16
10
|
/**
|
|
17
11
|
* Utility for FS ops. It handles
|
|
18
12
|
* - path normalization (for the first parameter to the FS op)
|
|
@@ -25,18 +19,16 @@ import { decode, encode } from '../utils.js';
|
|
|
25
19
|
* @param args the rest of the parameters are passed to the FS function. Note that the first parameter is required to be a path
|
|
26
20
|
* @returns
|
|
27
21
|
*/
|
|
28
|
-
function doOp(...[name, resolveSymlinks, path, ...args]) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
});
|
|
22
|
+
async function doOp(...[name, resolveSymlinks, path, ...args]) {
|
|
23
|
+
path = normalizePath(path);
|
|
24
|
+
const { fs, path: resolvedPath } = resolveFS(resolveSymlinks && (await exists(path)) ? await realpath(path) : path);
|
|
25
|
+
try {
|
|
26
|
+
// @ts-expect-error 2556 (since ...args is not correctly picked up as being a tuple)
|
|
27
|
+
return fs[name](resolvedPath, ...args);
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
throw fixError(e, { [resolvedPath]: path });
|
|
31
|
+
}
|
|
40
32
|
}
|
|
41
33
|
// fs.promises
|
|
42
34
|
/**
|
|
@@ -44,66 +36,48 @@ function doOp(...[name, resolveSymlinks, path, ...args]) {
|
|
|
44
36
|
* @param oldPath
|
|
45
37
|
* @param newPath
|
|
46
38
|
*/
|
|
47
|
-
export function rename(oldPath, newPath) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return _old.fs.rename(_old.path, _new.path, cred);
|
|
57
|
-
}
|
|
58
|
-
const data = yield readFile(oldPath);
|
|
59
|
-
yield writeFile(newPath, data);
|
|
60
|
-
yield unlink(oldPath);
|
|
39
|
+
export async function rename(oldPath, newPath) {
|
|
40
|
+
oldPath = normalizePath(oldPath);
|
|
41
|
+
newPath = normalizePath(newPath);
|
|
42
|
+
const _old = resolveFS(oldPath);
|
|
43
|
+
const _new = resolveFS(newPath);
|
|
44
|
+
const paths = { [_old.path]: oldPath, [_new.path]: newPath };
|
|
45
|
+
try {
|
|
46
|
+
if (_old === _new) {
|
|
47
|
+
return _old.fs.rename(_old.path, _new.path, cred);
|
|
61
48
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
49
|
+
const data = await readFile(oldPath);
|
|
50
|
+
await writeFile(newPath, data);
|
|
51
|
+
await unlink(oldPath);
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
throw fixError(e, paths);
|
|
55
|
+
}
|
|
66
56
|
}
|
|
67
57
|
/**
|
|
68
58
|
* Test whether or not the given path exists by checking with the file system.
|
|
69
59
|
* @param path
|
|
70
60
|
*/
|
|
71
|
-
export function exists(path) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
throw e;
|
|
61
|
+
export async function exists(path) {
|
|
62
|
+
path = normalizePath(path);
|
|
63
|
+
try {
|
|
64
|
+
const { fs, path: resolvedPath } = resolveFS(path);
|
|
65
|
+
return fs.exists(resolvedPath, cred);
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
if (e.errno == ErrorCode.ENOENT) {
|
|
69
|
+
return false;
|
|
83
70
|
}
|
|
84
|
-
|
|
71
|
+
throw e;
|
|
72
|
+
}
|
|
85
73
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
* @returns Stats
|
|
90
|
-
*/
|
|
91
|
-
export function stat(path) {
|
|
92
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
return doOp('stat', true, path, cred);
|
|
94
|
-
});
|
|
74
|
+
export async function stat(path, options) {
|
|
75
|
+
const stats = await doOp('stat', true, path, cred);
|
|
76
|
+
return options?.bigint ? BigIntStats.clone(stats) : stats;
|
|
95
77
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* then the link itself is stat-ed, not the file that it refers to.
|
|
100
|
-
* @param path
|
|
101
|
-
* @return [ZenFS.node.fs.Stats]
|
|
102
|
-
*/
|
|
103
|
-
export function lstat(path) {
|
|
104
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
return doOp('stat', false, path, cred);
|
|
106
|
-
});
|
|
78
|
+
export async function lstat(path, options) {
|
|
79
|
+
const stats = await doOp('stat', false, path, cred);
|
|
80
|
+
return options?.bigint ? BigIntStats.clone(stats) : stats;
|
|
107
81
|
}
|
|
108
82
|
// FILE-ONLY METHODS
|
|
109
83
|
/**
|
|
@@ -111,22 +85,18 @@ export function lstat(path) {
|
|
|
111
85
|
* @param path
|
|
112
86
|
* @param len
|
|
113
87
|
*/
|
|
114
|
-
export function truncate(path, len = 0) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return doOp('truncate', true, path, len, cred);
|
|
120
|
-
});
|
|
88
|
+
export async function truncate(path, len = 0) {
|
|
89
|
+
if (len < 0) {
|
|
90
|
+
throw new ApiError(ErrorCode.EINVAL);
|
|
91
|
+
}
|
|
92
|
+
return doOp('truncate', true, path, len, cred);
|
|
121
93
|
}
|
|
122
94
|
/**
|
|
123
95
|
* `unlink`.
|
|
124
96
|
* @param path
|
|
125
97
|
*/
|
|
126
|
-
export function unlink(path) {
|
|
127
|
-
return
|
|
128
|
-
return doOp('unlink', false, path, cred);
|
|
129
|
-
});
|
|
98
|
+
export async function unlink(path) {
|
|
99
|
+
return doOp('unlink', false, path, cred);
|
|
130
100
|
}
|
|
131
101
|
/**
|
|
132
102
|
* file open.
|
|
@@ -135,137 +105,110 @@ export function unlink(path) {
|
|
|
135
105
|
* @param flags
|
|
136
106
|
* @param mode defaults to `0644`
|
|
137
107
|
*/
|
|
138
|
-
export function open(path, flag, mode = 0o644) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
const encodedData = typeof data == 'string' ? encode(data) : data;
|
|
186
|
-
return doOp('appendFile', true, filename, encodedData, flag, options.mode, cred);
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
// FILE DESCRIPTOR METHODS
|
|
190
|
-
/**
|
|
191
|
-
* `fstat`.
|
|
192
|
-
* `fstat()` is identical to `stat()`, except that the file to be stat-ed is
|
|
193
|
-
* specified by the file descriptor `fd`.
|
|
194
|
-
* @param fd
|
|
195
|
-
* @return [ZenFS.node.fs.Stats]
|
|
196
|
-
*/
|
|
197
|
-
export function fstat(fd) {
|
|
198
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
-
return fd2file(fd).stat();
|
|
200
|
-
});
|
|
108
|
+
export async function open(path, flag, mode = 0o644) {
|
|
109
|
+
const file = await doOp('open', true, path, FileFlag.getFileFlag(flag), normalizeMode(mode, 0o644), cred);
|
|
110
|
+
return getFdForFile(file);
|
|
111
|
+
}
|
|
112
|
+
export async function readFile(filename, arg2 = {}) {
|
|
113
|
+
const options = normalizeOptions(arg2, null, 'r', null);
|
|
114
|
+
const flag = FileFlag.getFileFlag(options.flag);
|
|
115
|
+
if (!flag.isReadable()) {
|
|
116
|
+
throw new ApiError(ErrorCode.EINVAL, 'Flag passed to readFile must allow for reading.');
|
|
117
|
+
}
|
|
118
|
+
const data = await doOp('readFile', true, filename, flag, cred);
|
|
119
|
+
switch (options.encoding) {
|
|
120
|
+
case 'utf8':
|
|
121
|
+
case 'utf-8':
|
|
122
|
+
return decode(data);
|
|
123
|
+
default:
|
|
124
|
+
return data;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export async function writeFile(filename, data, arg3) {
|
|
128
|
+
const options = normalizeOptions(arg3, 'utf8', 'w', 0o644);
|
|
129
|
+
const flag = FileFlag.getFileFlag(options.flag);
|
|
130
|
+
if (!flag.isWriteable()) {
|
|
131
|
+
throw new ApiError(ErrorCode.EINVAL, 'Flag passed to writeFile must allow for writing.');
|
|
132
|
+
}
|
|
133
|
+
if (typeof data != 'string' && !options.encoding) {
|
|
134
|
+
throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
|
|
135
|
+
}
|
|
136
|
+
const encodedData = typeof data == 'string' ? encode(data) : data;
|
|
137
|
+
return doOp('writeFile', true, filename, encodedData, flag, options.mode, cred);
|
|
138
|
+
}
|
|
139
|
+
export async function appendFile(filename, data, arg3) {
|
|
140
|
+
const options = normalizeOptions(arg3, 'utf8', 'a', 0o644);
|
|
141
|
+
const flag = FileFlag.getFileFlag(options.flag);
|
|
142
|
+
if (!flag.isAppendable()) {
|
|
143
|
+
throw new ApiError(ErrorCode.EINVAL, 'Flag passed to appendFile must allow for appending.');
|
|
144
|
+
}
|
|
145
|
+
if (typeof data != 'string' && !options.encoding) {
|
|
146
|
+
throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
|
|
147
|
+
}
|
|
148
|
+
const encodedData = typeof data == 'string' ? encode(data) : data;
|
|
149
|
+
return doOp('appendFile', true, filename, encodedData, flag, options.mode, cred);
|
|
150
|
+
}
|
|
151
|
+
export async function fstat(fd, options) {
|
|
152
|
+
const stats = await fd2file(fd).stat();
|
|
153
|
+
return options?.bigint ? BigIntStats.clone(stats) : stats;
|
|
201
154
|
}
|
|
202
155
|
/**
|
|
203
156
|
* close.
|
|
204
157
|
* @param fd
|
|
205
158
|
*/
|
|
206
|
-
export function close(fd) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
return;
|
|
211
|
-
});
|
|
159
|
+
export async function close(fd) {
|
|
160
|
+
await fd2file(fd).close();
|
|
161
|
+
fdMap.delete(fd);
|
|
162
|
+
return;
|
|
212
163
|
}
|
|
213
164
|
/**
|
|
214
165
|
* ftruncate.
|
|
215
166
|
* @param fd
|
|
216
167
|
* @param len
|
|
217
168
|
*/
|
|
218
|
-
export function ftruncate(fd, len = 0) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
return file.truncate(len);
|
|
225
|
-
});
|
|
169
|
+
export async function ftruncate(fd, len = 0) {
|
|
170
|
+
const file = fd2file(fd);
|
|
171
|
+
if (len < 0) {
|
|
172
|
+
throw new ApiError(ErrorCode.EINVAL);
|
|
173
|
+
}
|
|
174
|
+
return file.truncate(len);
|
|
226
175
|
}
|
|
227
176
|
/**
|
|
228
177
|
* fsync.
|
|
229
178
|
* @param fd
|
|
230
179
|
*/
|
|
231
|
-
export function fsync(fd) {
|
|
232
|
-
return
|
|
233
|
-
return fd2file(fd).sync();
|
|
234
|
-
});
|
|
180
|
+
export async function fsync(fd) {
|
|
181
|
+
return fd2file(fd).sync();
|
|
235
182
|
}
|
|
236
183
|
/**
|
|
237
184
|
* fdatasync.
|
|
238
185
|
* @param fd
|
|
239
186
|
*/
|
|
240
|
-
export function fdatasync(fd) {
|
|
241
|
-
return
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
position = file.getPos();
|
|
266
|
-
}
|
|
267
|
-
return file.write(buffer, offset, length, position);
|
|
268
|
-
});
|
|
187
|
+
export async function fdatasync(fd) {
|
|
188
|
+
return fd2file(fd).datasync();
|
|
189
|
+
}
|
|
190
|
+
export async function write(fd, arg2, arg3, arg4, arg5) {
|
|
191
|
+
let buffer, offset = 0, length, position;
|
|
192
|
+
if (typeof arg2 === 'string') {
|
|
193
|
+
// Signature 1: (fd, string, [position?, [encoding?]])
|
|
194
|
+
position = typeof arg3 === 'number' ? arg3 : null;
|
|
195
|
+
const encoding = (typeof arg4 === 'string' ? arg4 : 'utf8');
|
|
196
|
+
offset = 0;
|
|
197
|
+
buffer = encode(arg2, encoding);
|
|
198
|
+
length = buffer.length;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
// Signature 2: (fd, buffer, offset, length, position?)
|
|
202
|
+
buffer = arg2;
|
|
203
|
+
offset = arg3;
|
|
204
|
+
length = arg4;
|
|
205
|
+
position = typeof arg5 === 'number' ? arg5 : null;
|
|
206
|
+
}
|
|
207
|
+
const file = fd2file(fd);
|
|
208
|
+
if (position === undefined || position === null) {
|
|
209
|
+
position = file.getPos();
|
|
210
|
+
}
|
|
211
|
+
return file.write(buffer, offset, length, position);
|
|
269
212
|
}
|
|
270
213
|
/**
|
|
271
214
|
* Read data from the file specified by `fd`.
|
|
@@ -279,14 +222,12 @@ export function write(fd, arg2, arg3, arg4, arg5) {
|
|
|
279
222
|
* in the file. If position is null, data will be read from the current file
|
|
280
223
|
* position.
|
|
281
224
|
*/
|
|
282
|
-
export function read(fd, buffer, offset, length, position) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
return file.read(buffer, offset, length, position);
|
|
289
|
-
});
|
|
225
|
+
export async function read(fd, buffer, offset, length, position) {
|
|
226
|
+
const file = fd2file(fd);
|
|
227
|
+
if (isNaN(+position)) {
|
|
228
|
+
position = file.getPos();
|
|
229
|
+
}
|
|
230
|
+
return file.read(buffer, offset, length, position);
|
|
290
231
|
}
|
|
291
232
|
/**
|
|
292
233
|
* `fchown`.
|
|
@@ -294,21 +235,17 @@ export function read(fd, buffer, offset, length, position) {
|
|
|
294
235
|
* @param uid
|
|
295
236
|
* @param gid
|
|
296
237
|
*/
|
|
297
|
-
export function fchown(fd, uid, gid) {
|
|
298
|
-
return
|
|
299
|
-
return fd2file(fd).chown(uid, gid);
|
|
300
|
-
});
|
|
238
|
+
export async function fchown(fd, uid, gid) {
|
|
239
|
+
return fd2file(fd).chown(uid, gid);
|
|
301
240
|
}
|
|
302
241
|
/**
|
|
303
242
|
* `fchmod`.
|
|
304
243
|
* @param fd
|
|
305
244
|
* @param mode
|
|
306
245
|
*/
|
|
307
|
-
export function fchmod(fd, mode) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
return fd2file(fd).chmod(numMode);
|
|
311
|
-
});
|
|
246
|
+
export async function fchmod(fd, mode) {
|
|
247
|
+
const numMode = typeof mode === 'string' ? parseInt(mode, 8) : mode;
|
|
248
|
+
return fd2file(fd).chmod(numMode);
|
|
312
249
|
}
|
|
313
250
|
/**
|
|
314
251
|
* Change the file timestamps of a file referenced by the supplied file
|
|
@@ -317,53 +254,44 @@ export function fchmod(fd, mode) {
|
|
|
317
254
|
* @param atime
|
|
318
255
|
* @param mtime
|
|
319
256
|
*/
|
|
320
|
-
export function futimes(fd, atime, mtime) {
|
|
321
|
-
return
|
|
322
|
-
return fd2file(fd).utimes(normalizeTime(atime), normalizeTime(mtime));
|
|
323
|
-
});
|
|
257
|
+
export async function futimes(fd, atime, mtime) {
|
|
258
|
+
return fd2file(fd).utimes(normalizeTime(atime), normalizeTime(mtime));
|
|
324
259
|
}
|
|
325
260
|
// DIRECTORY-ONLY METHODS
|
|
326
261
|
/**
|
|
327
262
|
* `rmdir`.
|
|
328
263
|
* @param path
|
|
329
264
|
*/
|
|
330
|
-
export function rmdir(path) {
|
|
331
|
-
return
|
|
332
|
-
return doOp('rmdir', true, path, cred);
|
|
333
|
-
});
|
|
265
|
+
export async function rmdir(path) {
|
|
266
|
+
return doOp('rmdir', true, path, cred);
|
|
334
267
|
}
|
|
335
268
|
/**
|
|
336
269
|
* `mkdir`.
|
|
337
270
|
* @param path
|
|
338
271
|
* @param mode defaults to `0777`
|
|
339
272
|
*/
|
|
340
|
-
export function mkdir(path, mode) {
|
|
341
|
-
return
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const entries = yield doOp('readdir', true, path, cred);
|
|
354
|
-
const points = [...mounts.keys()];
|
|
355
|
-
for (const point of points) {
|
|
356
|
-
if (point.startsWith(path)) {
|
|
357
|
-
const entry = point.slice(path.length);
|
|
358
|
-
if (entry.includes('/') || entry.length == 0) {
|
|
359
|
-
// ignore FSs mounted in subdirectories and any FS mounted to `path`.
|
|
360
|
-
continue;
|
|
361
|
-
}
|
|
362
|
-
entries.push(entry);
|
|
273
|
+
export async function mkdir(path, mode) {
|
|
274
|
+
return doOp('mkdir', true, path, normalizeMode(mode, 0o777), cred);
|
|
275
|
+
}
|
|
276
|
+
export async function readdir(path, options) {
|
|
277
|
+
path = normalizePath(path);
|
|
278
|
+
const entries = await doOp('readdir', true, path, cred);
|
|
279
|
+
const points = [...mounts.keys()];
|
|
280
|
+
for (const point of points) {
|
|
281
|
+
if (point.startsWith(path)) {
|
|
282
|
+
const entry = point.slice(path.length);
|
|
283
|
+
if (entry.includes('/') || entry.length == 0) {
|
|
284
|
+
// ignore FSs mounted in subdirectories and any FS mounted to `path`.
|
|
285
|
+
continue;
|
|
363
286
|
}
|
|
287
|
+
entries.push(entry);
|
|
364
288
|
}
|
|
365
|
-
|
|
366
|
-
|
|
289
|
+
}
|
|
290
|
+
const values = [];
|
|
291
|
+
for (const entry of entries) {
|
|
292
|
+
values.push(options?.withFileTypes ? new Dirent(entry, await stat(join(path, entry))) : entry);
|
|
293
|
+
}
|
|
294
|
+
return values;
|
|
367
295
|
}
|
|
368
296
|
// SYMLINK METHODS
|
|
369
297
|
/**
|
|
@@ -371,11 +299,9 @@ export function readdir(path) {
|
|
|
371
299
|
* @param srcpath
|
|
372
300
|
* @param dstpath
|
|
373
301
|
*/
|
|
374
|
-
export function link(srcpath, dstpath) {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
return doOp('link', false, srcpath, dstpath, cred);
|
|
378
|
-
});
|
|
302
|
+
export async function link(srcpath, dstpath) {
|
|
303
|
+
dstpath = normalizePath(dstpath);
|
|
304
|
+
return doOp('link', false, srcpath, dstpath, cred);
|
|
379
305
|
}
|
|
380
306
|
/**
|
|
381
307
|
* `symlink`.
|
|
@@ -383,24 +309,16 @@ export function link(srcpath, dstpath) {
|
|
|
383
309
|
* @param dstpath
|
|
384
310
|
* @param type can be either `'dir'` or `'file'` (default is `'file'`)
|
|
385
311
|
*/
|
|
386
|
-
export function symlink(srcpath, dstpath, type = 'file') {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
return doOp('symlink', false, srcpath, dstpath, type, cred);
|
|
393
|
-
});
|
|
312
|
+
export async function symlink(srcpath, dstpath, type = 'file') {
|
|
313
|
+
if (!['file', 'dir', 'junction'].includes(type)) {
|
|
314
|
+
throw new ApiError(ErrorCode.EINVAL, 'Invalid type: ' + type);
|
|
315
|
+
}
|
|
316
|
+
dstpath = normalizePath(dstpath);
|
|
317
|
+
return doOp('symlink', false, srcpath, dstpath, type, cred);
|
|
394
318
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
* @return [String]
|
|
399
|
-
*/
|
|
400
|
-
export function readlink(path) {
|
|
401
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
402
|
-
return doOp('readlink', false, path, cred);
|
|
403
|
-
});
|
|
319
|
+
export async function readlink(path, options) {
|
|
320
|
+
const value = await doOp('readlink', false, path, cred);
|
|
321
|
+
return encode(value, typeof options == 'object' ? options.encoding : options);
|
|
404
322
|
}
|
|
405
323
|
// PROPERTY OPERATIONS
|
|
406
324
|
/**
|
|
@@ -409,10 +327,8 @@ export function readlink(path) {
|
|
|
409
327
|
* @param uid
|
|
410
328
|
* @param gid
|
|
411
329
|
*/
|
|
412
|
-
export function chown(path, uid, gid) {
|
|
413
|
-
return
|
|
414
|
-
return doOp('chown', true, path, uid, gid, cred);
|
|
415
|
-
});
|
|
330
|
+
export async function chown(path, uid, gid) {
|
|
331
|
+
return doOp('chown', true, path, uid, gid, cred);
|
|
416
332
|
}
|
|
417
333
|
/**
|
|
418
334
|
* `lchown`.
|
|
@@ -420,38 +336,32 @@ export function chown(path, uid, gid) {
|
|
|
420
336
|
* @param uid
|
|
421
337
|
* @param gid
|
|
422
338
|
*/
|
|
423
|
-
export function lchown(path, uid, gid) {
|
|
424
|
-
return
|
|
425
|
-
return doOp('chown', false, path, uid, gid, cred);
|
|
426
|
-
});
|
|
339
|
+
export async function lchown(path, uid, gid) {
|
|
340
|
+
return doOp('chown', false, path, uid, gid, cred);
|
|
427
341
|
}
|
|
428
342
|
/**
|
|
429
343
|
* `chmod`.
|
|
430
344
|
* @param path
|
|
431
345
|
* @param mode
|
|
432
346
|
*/
|
|
433
|
-
export function chmod(path, mode) {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
return doOp('chmod', true, path, numMode, cred);
|
|
440
|
-
});
|
|
347
|
+
export async function chmod(path, mode) {
|
|
348
|
+
const numMode = normalizeMode(mode, -1);
|
|
349
|
+
if (numMode < 0) {
|
|
350
|
+
throw new ApiError(ErrorCode.EINVAL, `Invalid mode.`);
|
|
351
|
+
}
|
|
352
|
+
return doOp('chmod', true, path, numMode, cred);
|
|
441
353
|
}
|
|
442
354
|
/**
|
|
443
355
|
* `lchmod`.
|
|
444
356
|
* @param path
|
|
445
357
|
* @param mode
|
|
446
358
|
*/
|
|
447
|
-
export function lchmod(path, mode) {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
return doOp('chmod', false, normalizePath(path), numMode, cred);
|
|
454
|
-
});
|
|
359
|
+
export async function lchmod(path, mode) {
|
|
360
|
+
const numMode = normalizeMode(mode, -1);
|
|
361
|
+
if (numMode < 1) {
|
|
362
|
+
throw new ApiError(ErrorCode.EINVAL, `Invalid mode.`);
|
|
363
|
+
}
|
|
364
|
+
return doOp('chmod', false, normalizePath(path), numMode, cred);
|
|
455
365
|
}
|
|
456
366
|
/**
|
|
457
367
|
* Change file timestamps of the file referenced by the supplied path.
|
|
@@ -459,10 +369,8 @@ export function lchmod(path, mode) {
|
|
|
459
369
|
* @param atime
|
|
460
370
|
* @param mtime
|
|
461
371
|
*/
|
|
462
|
-
export function utimes(path, atime, mtime) {
|
|
463
|
-
return
|
|
464
|
-
return doOp('utimes', true, path, normalizeTime(atime), normalizeTime(mtime), cred);
|
|
465
|
-
});
|
|
372
|
+
export async function utimes(path, atime, mtime) {
|
|
373
|
+
return doOp('utimes', true, path, normalizeTime(atime), normalizeTime(mtime), cred);
|
|
466
374
|
}
|
|
467
375
|
/**
|
|
468
376
|
* Change file timestamps of the file referenced by the supplied path.
|
|
@@ -470,68 +378,61 @@ export function utimes(path, atime, mtime) {
|
|
|
470
378
|
* @param atime
|
|
471
379
|
* @param mtime
|
|
472
380
|
*/
|
|
473
|
-
export function lutimes(path, atime, mtime) {
|
|
474
|
-
return
|
|
475
|
-
return doOp('utimes', false, path, normalizeTime(atime), normalizeTime(mtime), cred);
|
|
476
|
-
});
|
|
381
|
+
export async function lutimes(path, atime, mtime) {
|
|
382
|
+
return doOp('utimes', false, path, normalizeTime(atime), normalizeTime(mtime), cred);
|
|
477
383
|
}
|
|
478
384
|
/**
|
|
479
385
|
* `realpath`.
|
|
480
386
|
* @param path
|
|
481
|
-
* @param
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
387
|
+
* @param options
|
|
388
|
+
* @return resolved path
|
|
389
|
+
*
|
|
390
|
+
* Note: This *Can not* use doOp since doOp depends on it
|
|
485
391
|
*/
|
|
486
|
-
export function realpath(path,
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
return path;
|
|
494
|
-
}
|
|
495
|
-
const dst = mountPoint + normalizePath(yield fs.readlink(resolvedPath, cred));
|
|
496
|
-
return realpath(dst);
|
|
497
|
-
}
|
|
498
|
-
catch (e) {
|
|
499
|
-
throw fixError(e, { [resolvedPath]: path });
|
|
392
|
+
export async function realpath(path, options) {
|
|
393
|
+
path = normalizePath(path);
|
|
394
|
+
const { fs, path: resolvedPath, mountPoint } = resolveFS(path);
|
|
395
|
+
try {
|
|
396
|
+
const stats = await fs.stat(resolvedPath, cred);
|
|
397
|
+
if (!stats.isSymbolicLink()) {
|
|
398
|
+
return path;
|
|
500
399
|
}
|
|
501
|
-
|
|
400
|
+
const dst = mountPoint + normalizePath(await fs.readlink(resolvedPath, cred));
|
|
401
|
+
return realpath(dst);
|
|
402
|
+
}
|
|
403
|
+
catch (e) {
|
|
404
|
+
throw fixError(e, { [resolvedPath]: path });
|
|
405
|
+
}
|
|
502
406
|
}
|
|
503
|
-
export function watchFile(filename, arg2, listener = nop) {
|
|
504
|
-
|
|
505
|
-
throw new ApiError(ErrorCode.ENOTSUP);
|
|
506
|
-
});
|
|
407
|
+
export async function watchFile(filename, arg2, listener = nop) {
|
|
408
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
507
409
|
}
|
|
508
|
-
export function unwatchFile(filename, listener = nop) {
|
|
509
|
-
|
|
510
|
-
throw new ApiError(ErrorCode.ENOTSUP);
|
|
511
|
-
});
|
|
410
|
+
export async function unwatchFile(filename, listener = nop) {
|
|
411
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
512
412
|
}
|
|
513
|
-
export function watch(filename, arg2, listener = nop) {
|
|
514
|
-
|
|
515
|
-
throw new ApiError(ErrorCode.ENOTSUP);
|
|
516
|
-
});
|
|
413
|
+
export async function watch(filename, arg2, listener = nop) {
|
|
414
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
517
415
|
}
|
|
518
416
|
/**
|
|
519
417
|
* `access`.
|
|
520
418
|
* @param path
|
|
521
419
|
* @param mode
|
|
522
420
|
*/
|
|
523
|
-
export function access(path, mode = 0o600) {
|
|
524
|
-
return
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
421
|
+
export async function access(path, mode = 0o600) {
|
|
422
|
+
return doOp('access', true, path, mode, cred);
|
|
423
|
+
}
|
|
424
|
+
export async function createReadStream(path, options) {
|
|
425
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
426
|
+
}
|
|
427
|
+
export async function createWriteStream(path, options) {
|
|
428
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
429
|
+
}
|
|
430
|
+
export async function rm(path) {
|
|
431
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
432
|
+
}
|
|
433
|
+
export async function mkdtemp(path) {
|
|
434
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
435
|
+
}
|
|
436
|
+
export async function copyFile(path) {
|
|
437
|
+
throw new ApiError(ErrorCode.ENOTSUP);
|
|
537
438
|
}
|