@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.
@@ -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
- return __awaiter(this, void 0, void 0, function* () {
30
- path = normalizePath(path);
31
- const { fs, path: resolvedPath } = resolveFS(resolveSymlinks && (yield exists(path)) ? yield realpath(path) : path);
32
- try {
33
- // @ts-expect-error 2556 (since ...args is not correctly picked up as being a tuple)
34
- return fs[name](resolvedPath, ...args);
35
- }
36
- catch (e) {
37
- throw fixError(e, { [resolvedPath]: path });
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
- return __awaiter(this, void 0, void 0, function* () {
49
- oldPath = normalizePath(oldPath);
50
- newPath = normalizePath(newPath);
51
- const _old = resolveFS(oldPath);
52
- const _new = resolveFS(newPath);
53
- const paths = { [_old.path]: oldPath, [_new.path]: newPath };
54
- try {
55
- if (_old === _new) {
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
- catch (e) {
63
- throw fixError(e, paths);
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
- return __awaiter(this, void 0, void 0, function* () {
73
- path = normalizePath(path);
74
- try {
75
- const { fs, path: resolvedPath } = resolveFS(path);
76
- return fs.exists(resolvedPath, cred);
77
- }
78
- catch (e) {
79
- if (e.errno == ErrorCode.ENOENT) {
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
- * `stat`.
88
- * @param path
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
- * `lstat`.
98
- * `lstat()` is identical to `stat()`, except that if path is a symbolic link,
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
- return __awaiter(this, void 0, void 0, function* () {
116
- if (len < 0) {
117
- throw new ApiError(ErrorCode.EINVAL);
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 __awaiter(this, void 0, void 0, function* () {
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
- return __awaiter(this, void 0, void 0, function* () {
140
- const file = yield doOp('open', true, path, FileFlag.getFileFlag(flag), normalizeMode(mode, 0o644), cred);
141
- return getFdForFile(file);
142
- });
143
- }
144
- export function readFile(filename, arg2 = {}) {
145
- return __awaiter(this, void 0, void 0, function* () {
146
- const options = normalizeOptions(arg2, null, 'r', null);
147
- const flag = FileFlag.getFileFlag(options.flag);
148
- if (!flag.isReadable()) {
149
- throw new ApiError(ErrorCode.EINVAL, 'Flag passed to readFile must allow for reading.');
150
- }
151
- const data = yield doOp('readFile', true, filename, flag, cred);
152
- switch (options.encoding) {
153
- case 'utf8':
154
- case 'utf-8':
155
- return decode(data);
156
- default:
157
- return data;
158
- }
159
- });
160
- }
161
- export function writeFile(filename, data, arg3) {
162
- return __awaiter(this, void 0, void 0, function* () {
163
- const options = normalizeOptions(arg3, 'utf8', 'w', 0o644);
164
- const flag = FileFlag.getFileFlag(options.flag);
165
- if (!flag.isWriteable()) {
166
- throw new ApiError(ErrorCode.EINVAL, 'Flag passed to writeFile must allow for writing.');
167
- }
168
- if (typeof data != 'string' && !options.encoding) {
169
- throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
170
- }
171
- const encodedData = typeof data == 'string' ? encode(data) : data;
172
- return doOp('writeFile', true, filename, encodedData, flag, options.mode, cred);
173
- });
174
- }
175
- export function appendFile(filename, data, arg3) {
176
- return __awaiter(this, void 0, void 0, function* () {
177
- const options = normalizeOptions(arg3, 'utf8', 'a', 0o644);
178
- const flag = FileFlag.getFileFlag(options.flag);
179
- if (!flag.isAppendable()) {
180
- throw new ApiError(ErrorCode.EINVAL, 'Flag passed to appendFile must allow for appending.');
181
- }
182
- if (typeof data != 'string' && !options.encoding) {
183
- throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
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
- return __awaiter(this, void 0, void 0, function* () {
208
- yield fd2file(fd).close();
209
- fdMap.delete(fd);
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
- return __awaiter(this, void 0, void 0, function* () {
220
- const file = fd2file(fd);
221
- if (len < 0) {
222
- throw new ApiError(ErrorCode.EINVAL);
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 __awaiter(this, void 0, void 0, function* () {
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 __awaiter(this, void 0, void 0, function* () {
242
- return fd2file(fd).datasync();
243
- });
244
- }
245
- export function write(fd, arg2, arg3, arg4, arg5) {
246
- return __awaiter(this, void 0, void 0, function* () {
247
- let buffer, offset = 0, length, position;
248
- if (typeof arg2 === 'string') {
249
- // Signature 1: (fd, string, [position?, [encoding?]])
250
- position = typeof arg3 === 'number' ? arg3 : null;
251
- const encoding = (typeof arg4 === 'string' ? arg4 : 'utf8');
252
- offset = 0;
253
- buffer = encode(arg2);
254
- length = buffer.length;
255
- }
256
- else {
257
- // Signature 2: (fd, buffer, offset, length, position?)
258
- buffer = arg2;
259
- offset = arg3;
260
- length = arg4;
261
- position = typeof arg5 === 'number' ? arg5 : null;
262
- }
263
- const file = fd2file(fd);
264
- if (position === undefined || position === null) {
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
- return __awaiter(this, void 0, void 0, function* () {
284
- const file = fd2file(fd);
285
- if (isNaN(+position)) {
286
- position = file.getPos();
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 __awaiter(this, void 0, void 0, function* () {
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
- return __awaiter(this, void 0, void 0, function* () {
309
- const numMode = typeof mode === 'string' ? parseInt(mode, 8) : mode;
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 __awaiter(this, void 0, void 0, function* () {
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 __awaiter(this, void 0, void 0, function* () {
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 __awaiter(this, void 0, void 0, function* () {
342
- return doOp('mkdir', true, path, normalizeMode(mode, 0o777), cred);
343
- });
344
- }
345
- /**
346
- * `readdir`. Reads the contents of a directory.
347
- * @param path
348
- * @return [String[]]
349
- */
350
- export function readdir(path) {
351
- return __awaiter(this, void 0, void 0, function* () {
352
- path = normalizePath(path);
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
- return entries;
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
- return __awaiter(this, void 0, void 0, function* () {
376
- dstpath = normalizePath(dstpath);
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
- return __awaiter(this, void 0, void 0, function* () {
388
- if (!['file', 'dir', 'junction'].includes(type)) {
389
- throw new ApiError(ErrorCode.EINVAL, 'Invalid type: ' + type);
390
- }
391
- dstpath = normalizePath(dstpath);
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
- * readlink.
397
- * @param path
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 __awaiter(this, void 0, void 0, function* () {
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 __awaiter(this, void 0, void 0, function* () {
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
- return __awaiter(this, void 0, void 0, function* () {
435
- const numMode = normalizeMode(mode, -1);
436
- if (numMode < 0) {
437
- throw new ApiError(ErrorCode.EINVAL, `Invalid mode.`);
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
- return __awaiter(this, void 0, void 0, function* () {
449
- const numMode = normalizeMode(mode, -1);
450
- if (numMode < 1) {
451
- throw new ApiError(ErrorCode.EINVAL, `Invalid mode.`);
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 __awaiter(this, void 0, void 0, function* () {
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 __awaiter(this, void 0, void 0, function* () {
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 cache An object literal of mapped paths that can be used to
482
- * force a specific path resolution or avoid additional `fs.stat` calls for
483
- * known real paths.
484
- * @return [String]
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, cache = {}) {
487
- return __awaiter(this, void 0, void 0, function* () {
488
- path = normalizePath(path);
489
- const { fs, path: resolvedPath, mountPoint } = resolveFS(path);
490
- try {
491
- const stats = yield fs.stat(resolvedPath, cred);
492
- if (!stats.isSymbolicLink()) {
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
- return __awaiter(this, void 0, void 0, function* () {
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
- return __awaiter(this, void 0, void 0, function* () {
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
- return __awaiter(this, void 0, void 0, function* () {
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 __awaiter(this, void 0, void 0, function* () {
525
- return doOp('access', true, path, mode, cred);
526
- });
527
- }
528
- export function createReadStream(path, options) {
529
- return __awaiter(this, void 0, void 0, function* () {
530
- throw new ApiError(ErrorCode.ENOTSUP);
531
- });
532
- }
533
- export function createWriteStream(path, options) {
534
- return __awaiter(this, void 0, void 0, function* () {
535
- throw new ApiError(ErrorCode.ENOTSUP);
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
  }