@zenfs/core 0.5.4 → 0.5.6
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 +5 -12
- package/dist/ApiError.js +6 -27
- package/dist/FileIndex.js +10 -10
- package/dist/backends/AsyncMirror.d.ts +1 -1
- package/dist/backends/AsyncMirror.js +2 -0
- package/dist/backends/AsyncStore.js +24 -24
- package/dist/backends/InMemory.d.ts +2 -2
- package/dist/backends/InMemory.js +1 -0
- package/dist/backends/Overlay.d.ts +1 -1
- package/dist/backends/Overlay.js +17 -17
- package/dist/backends/SyncStore.js +23 -23
- package/dist/backends/backend.d.ts +4 -4
- package/dist/browser.min.js +4 -4
- package/dist/browser.min.js.map +4 -4
- package/dist/emulation/{callbacks.d.ts → async.d.ts} +52 -15
- package/dist/emulation/{callbacks.js → async.js} +99 -35
- package/dist/emulation/constants.d.ts +5 -0
- package/dist/emulation/constants.js +5 -0
- package/dist/emulation/dir.d.ts +3 -2
- package/dist/emulation/dir.js +6 -2
- package/dist/emulation/index.d.ts +2 -2
- package/dist/emulation/index.js +2 -2
- package/dist/emulation/promises.d.ts +88 -115
- package/dist/emulation/promises.js +112 -110
- package/dist/emulation/shared.d.ts +9 -10
- package/dist/emulation/shared.js +28 -40
- package/dist/emulation/streams.d.ts +5 -0
- package/dist/emulation/sync.d.ts +50 -18
- package/dist/emulation/sync.js +65 -29
- package/dist/file.d.ts +11 -7
- package/dist/file.js +11 -15
- package/dist/stats.d.ts +34 -19
- package/dist/stats.js +8 -51
- package/dist/utils.d.ts +2 -3
- package/dist/utils.js +6 -88
- package/package.json +3 -2
package/dist/emulation/sync.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
3
|
import { FileContents } from '../filesystem.js';
|
|
4
|
-
import { BigIntStats, type Stats } from '../stats.js';
|
|
5
|
-
import type { symlink, ReadSyncOptions,
|
|
4
|
+
import { BigIntStats, type BigIntStatsFs, type Stats, type StatsFs } from '../stats.js';
|
|
5
|
+
import type { symlink, ReadSyncOptions, EncodingOption, BufferEncodingOption } from 'fs';
|
|
6
6
|
import type * as Node from 'fs';
|
|
7
7
|
import { PathLike } from './shared.js';
|
|
8
8
|
import { Dir, Dirent } from './dir.js';
|
|
@@ -23,7 +23,7 @@ export declare function existsSync(path: PathLike): boolean;
|
|
|
23
23
|
* @returns Stats
|
|
24
24
|
*/
|
|
25
25
|
export declare function statSync(path: PathLike, options?: {
|
|
26
|
-
bigint
|
|
26
|
+
bigint?: false;
|
|
27
27
|
}): Stats;
|
|
28
28
|
export declare function statSync(path: PathLike, options: {
|
|
29
29
|
bigint: true;
|
|
@@ -35,7 +35,7 @@ export declare function statSync(path: PathLike, options: {
|
|
|
35
35
|
* @param path
|
|
36
36
|
*/
|
|
37
37
|
export declare function lstatSync(path: PathLike, options?: {
|
|
38
|
-
bigint
|
|
38
|
+
bigint?: false;
|
|
39
39
|
}): Stats;
|
|
40
40
|
export declare function lstatSync(path: PathLike, options: {
|
|
41
41
|
bigint: true;
|
|
@@ -75,12 +75,10 @@ export declare function lopenSync(path: PathLike, flag: string, mode?: Node.Mode
|
|
|
75
75
|
*/
|
|
76
76
|
export declare function readFileSync(filename: string, options?: {
|
|
77
77
|
flag?: string;
|
|
78
|
-
}):
|
|
79
|
-
export declare function readFileSync(filename: string, options: {
|
|
80
|
-
encoding: string;
|
|
78
|
+
}): Buffer;
|
|
79
|
+
export declare function readFileSync(filename: string, options: (Node.EncodingOption & {
|
|
81
80
|
flag?: string;
|
|
82
|
-
}): string;
|
|
83
|
-
export declare function readFileSync(filename: string, encoding: string): string;
|
|
81
|
+
}) | BufferEncoding): string;
|
|
84
82
|
/**
|
|
85
83
|
* Synchronously writes data to a file, replacing the file if it already
|
|
86
84
|
* exists.
|
|
@@ -106,8 +104,7 @@ export declare function writeFileSync(filename: string, data: FileContents, enco
|
|
|
106
104
|
* @option options mode Defaults to `0644`.
|
|
107
105
|
* @option options flag Defaults to `'a'`.
|
|
108
106
|
*/
|
|
109
|
-
export declare function appendFileSync(filename: string, data: FileContents,
|
|
110
|
-
export declare function appendFileSync(filename: string, data: FileContents, encoding?: string): void;
|
|
107
|
+
export declare function appendFileSync(filename: string, data: FileContents, _options?: Node.WriteFileOptions): void;
|
|
111
108
|
/**
|
|
112
109
|
* Synchronous `fstat`.
|
|
113
110
|
* `fstat()` is identical to `stat()`, except that the file to be stat-ed is
|
|
@@ -219,7 +216,7 @@ export declare function readdirSync(path: PathLike, options?: {
|
|
|
219
216
|
export declare function readdirSync(path: PathLike, options: {
|
|
220
217
|
encoding: 'buffer';
|
|
221
218
|
withFileTypes?: false;
|
|
222
|
-
} | 'buffer'):
|
|
219
|
+
} | 'buffer'): Buffer[];
|
|
223
220
|
export declare function readdirSync(path: PathLike, options: {
|
|
224
221
|
withFileTypes: true;
|
|
225
222
|
}): Dirent[];
|
|
@@ -240,8 +237,8 @@ export declare function symlinkSync(target: PathLike, path: PathLike, type?: sym
|
|
|
240
237
|
* Synchronous readlink.
|
|
241
238
|
* @param path
|
|
242
239
|
*/
|
|
243
|
-
export declare function readlinkSync(path: PathLike, options?: BufferEncodingOption):
|
|
244
|
-
export declare function readlinkSync(path: PathLike, options:
|
|
240
|
+
export declare function readlinkSync(path: PathLike, options?: BufferEncodingOption): Buffer;
|
|
241
|
+
export declare function readlinkSync(path: PathLike, options: EncodingOption | BufferEncoding): string;
|
|
245
242
|
/**
|
|
246
243
|
* Synchronous `chown`.
|
|
247
244
|
* @param path
|
|
@@ -290,18 +287,53 @@ export declare function lutimesSync(path: PathLike, atime: string | number | Dat
|
|
|
290
287
|
* known real paths.
|
|
291
288
|
* @returns the real path
|
|
292
289
|
*/
|
|
293
|
-
export declare function realpathSync(path: PathLike, options: BufferEncodingOption):
|
|
294
|
-
export declare function realpathSync(path: PathLike, options?:
|
|
290
|
+
export declare function realpathSync(path: PathLike, options: BufferEncodingOption): Buffer;
|
|
291
|
+
export declare function realpathSync(path: PathLike, options?: EncodingOption): string;
|
|
295
292
|
/**
|
|
296
293
|
* Synchronous `access`.
|
|
297
294
|
* @param path
|
|
298
295
|
* @param mode
|
|
299
296
|
*/
|
|
300
297
|
export declare function accessSync(path: PathLike, mode?: number): void;
|
|
298
|
+
/**
|
|
299
|
+
* @todo Implement
|
|
300
|
+
*/
|
|
301
301
|
export declare function rmSync(path: PathLike): void;
|
|
302
|
-
|
|
303
|
-
|
|
302
|
+
/**
|
|
303
|
+
* @todo Implement
|
|
304
|
+
*/
|
|
305
|
+
export declare function mkdtempSync(prefix: string, options: BufferEncodingOption): Buffer;
|
|
306
|
+
export declare function mkdtempSync(prefix: string, options?: EncodingOption): string;
|
|
307
|
+
/**
|
|
308
|
+
* @todo Implement
|
|
309
|
+
*/
|
|
304
310
|
export declare function copyFileSync(src: string, dest: string, flags?: number): void;
|
|
311
|
+
/**
|
|
312
|
+
* @todo Implement
|
|
313
|
+
*/
|
|
305
314
|
export declare function readvSync(fd: number, buffers: readonly Uint8Array[], position?: number): number;
|
|
315
|
+
/**
|
|
316
|
+
* @todo Implement
|
|
317
|
+
*/
|
|
306
318
|
export declare function writevSync(fd: number, buffers: readonly Uint8Array[], position?: number): number;
|
|
319
|
+
/**
|
|
320
|
+
* @todo Implement
|
|
321
|
+
*/
|
|
307
322
|
export declare function opendirSync(path: PathLike, options?: Node.OpenDirOptions): Dir;
|
|
323
|
+
/**
|
|
324
|
+
* @todo Implement
|
|
325
|
+
*/
|
|
326
|
+
export declare function cpSync(source: PathLike, destination: PathLike, opts?: Node.CopySyncOptions): void;
|
|
327
|
+
/**
|
|
328
|
+
* Synchronous statfs(2). Returns information about the mounted file system which contains path. The callback gets two arguments (err, stats) where stats is an <fs.StatFs> object.
|
|
329
|
+
* In case of an error, the err.code will be one of Common System Errors.
|
|
330
|
+
* @param path A path to an existing file or directory on the file system to be queried.
|
|
331
|
+
* @param callback
|
|
332
|
+
*/
|
|
333
|
+
export declare function statfsSync(path: PathLike, options?: Node.StatFsOptions & {
|
|
334
|
+
bigint?: false;
|
|
335
|
+
}): StatsFs;
|
|
336
|
+
export declare function statfsSync(path: PathLike, options: Node.StatFsOptions & {
|
|
337
|
+
bigint: true;
|
|
338
|
+
}): BigIntStatsFs;
|
|
339
|
+
export declare function statfsSync(path: PathLike, options?: Node.StatFsOptions): StatsFs | BigIntStatsFs;
|
package/dist/emulation/sync.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { ApiError, ErrorCode } from '../ApiError.js';
|
|
2
2
|
import { ActionType, isAppendable, isReadable, isWriteable, parseFlag, pathExistsAction, pathNotExistsAction } from '../file.js';
|
|
3
3
|
import { BigIntStats, FileType } from '../stats.js';
|
|
4
|
-
import { normalizePath, cred, getFdForFile, normalizeMode, normalizeOptions, fdMap, fd2file, normalizeTime, resolveFS, fixError, mounts
|
|
5
|
-
import { decode, encode } from '../utils.js';
|
|
4
|
+
import { normalizePath, cred, getFdForFile, normalizeMode, normalizeOptions, fdMap, fd2file, normalizeTime, resolveFS, fixError, mounts } from './shared.js';
|
|
6
5
|
import { Dirent } from './dir.js';
|
|
7
6
|
import { dirname, join } from './path.js';
|
|
8
7
|
function doOp(...[name, resolveSymlinks, path, ...args]) {
|
|
@@ -31,8 +30,7 @@ export function renameSync(oldPath, newPath) {
|
|
|
31
30
|
if (_old === _new) {
|
|
32
31
|
return _old.fs.renameSync(_old.path, _new.path, cred);
|
|
33
32
|
}
|
|
34
|
-
|
|
35
|
-
writeFileSync(newPath, data);
|
|
33
|
+
writeFileSync(newPath, readFileSync(oldPath));
|
|
36
34
|
unlinkSync(oldPath);
|
|
37
35
|
}
|
|
38
36
|
catch (e) {
|
|
@@ -105,22 +103,22 @@ function _openSync(_path, _flag, _mode, resolveSymlinks) {
|
|
|
105
103
|
// Ensure parent exists.
|
|
106
104
|
const parentStats = doOp('statSync', resolveSymlinks, dirname(path), cred);
|
|
107
105
|
if (!parentStats.isDirectory()) {
|
|
108
|
-
throw ApiError.ENOTDIR
|
|
106
|
+
throw ApiError.With('ENOTDIR', dirname(path), '_openSync');
|
|
109
107
|
}
|
|
110
108
|
return doOp('createFileSync', resolveSymlinks, path, flag, mode, cred);
|
|
111
109
|
case ActionType.THROW:
|
|
112
|
-
throw ApiError.ENOENT
|
|
110
|
+
throw ApiError.With('ENOENT', path, '_openSync');
|
|
113
111
|
default:
|
|
114
112
|
throw new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.');
|
|
115
113
|
}
|
|
116
114
|
}
|
|
117
115
|
if (!stats.hasAccess(mode, cred)) {
|
|
118
|
-
throw ApiError.EACCES
|
|
116
|
+
throw ApiError.With('EACCES', path, '_openSync');
|
|
119
117
|
}
|
|
120
118
|
// File exists.
|
|
121
119
|
switch (pathExistsAction(flag)) {
|
|
122
120
|
case ActionType.THROW:
|
|
123
|
-
throw ApiError.EEXIST
|
|
121
|
+
throw ApiError.With('EEXIST', path, '_openSync');
|
|
124
122
|
case ActionType.TRUNCATE:
|
|
125
123
|
// Delete file.
|
|
126
124
|
doOp('unlinkSync', resolveSymlinks, path, cred);
|
|
@@ -180,8 +178,8 @@ export function readFileSync(filename, arg2 = {}) {
|
|
|
180
178
|
if (!isReadable(flag)) {
|
|
181
179
|
throw new ApiError(ErrorCode.EINVAL, 'Flag passed to readFile must allow for reading.');
|
|
182
180
|
}
|
|
183
|
-
const data = _readFileSync(filename, options.flag, true);
|
|
184
|
-
return options.encoding ?
|
|
181
|
+
const data = Buffer.from(_readFileSync(filename, options.flag, true));
|
|
182
|
+
return options.encoding ? data.toString(options.encoding) : data;
|
|
185
183
|
}
|
|
186
184
|
readFileSync;
|
|
187
185
|
/**
|
|
@@ -208,7 +206,7 @@ export function writeFileSync(filename, data, _options) {
|
|
|
208
206
|
if (typeof data != 'string' && !options.encoding) {
|
|
209
207
|
throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
|
|
210
208
|
}
|
|
211
|
-
const encodedData = typeof data == 'string' ?
|
|
209
|
+
const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : data;
|
|
212
210
|
if (encodedData === undefined) {
|
|
213
211
|
throw new ApiError(ErrorCode.EINVAL, 'Data not specified');
|
|
214
212
|
}
|
|
@@ -228,8 +226,19 @@ function _appendFileSync(fname, data, flag, mode, resolveSymlinks) {
|
|
|
228
226
|
file.closeSync();
|
|
229
227
|
}
|
|
230
228
|
}
|
|
231
|
-
|
|
232
|
-
|
|
229
|
+
/**
|
|
230
|
+
* Asynchronously append data to a file, creating the file if it not yet
|
|
231
|
+
* exists.
|
|
232
|
+
*
|
|
233
|
+
* @param filename
|
|
234
|
+
* @param data
|
|
235
|
+
* @param options
|
|
236
|
+
* @option options encoding Defaults to `'utf8'`.
|
|
237
|
+
* @option options mode Defaults to `0644`.
|
|
238
|
+
* @option options flag Defaults to `'a'`.
|
|
239
|
+
*/
|
|
240
|
+
export function appendFileSync(filename, data, _options) {
|
|
241
|
+
const options = normalizeOptions(_options, 'utf8', 'a', 0o644);
|
|
233
242
|
const flag = parseFlag(options.flag);
|
|
234
243
|
if (!isAppendable(flag)) {
|
|
235
244
|
throw new ApiError(ErrorCode.EINVAL, 'Flag passed to appendFile must allow for appending.');
|
|
@@ -237,7 +246,7 @@ export function appendFileSync(filename, data, arg3) {
|
|
|
237
246
|
if (typeof data != 'string' && !options.encoding) {
|
|
238
247
|
throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
|
|
239
248
|
}
|
|
240
|
-
const encodedData = typeof data == 'string' ?
|
|
249
|
+
const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : data;
|
|
241
250
|
_appendFileSync(filename, encodedData, options.flag, options.mode, true);
|
|
242
251
|
}
|
|
243
252
|
appendFileSync;
|
|
@@ -290,7 +299,7 @@ export function writeSync(fd, data, posOrOff, lenOrEnc, pos) {
|
|
|
290
299
|
position = typeof posOrOff === 'number' ? posOrOff : null;
|
|
291
300
|
const encoding = (typeof lenOrEnc === 'string' ? lenOrEnc : 'utf8');
|
|
292
301
|
offset = 0;
|
|
293
|
-
buffer =
|
|
302
|
+
buffer = Buffer.from(data, encoding);
|
|
294
303
|
length = buffer.length;
|
|
295
304
|
}
|
|
296
305
|
else {
|
|
@@ -309,11 +318,13 @@ export function writeSync(fd, data, posOrOff, lenOrEnc, pos) {
|
|
|
309
318
|
writeSync;
|
|
310
319
|
export function readSync(fd, buffer, opts, length, position) {
|
|
311
320
|
const file = fd2file(fd);
|
|
312
|
-
|
|
321
|
+
const offset = typeof opts == 'object' ? opts.offset : opts;
|
|
313
322
|
if (typeof opts == 'object') {
|
|
314
|
-
|
|
323
|
+
length = opts.length;
|
|
324
|
+
position = opts.position;
|
|
315
325
|
}
|
|
316
|
-
|
|
326
|
+
position = Number(position);
|
|
327
|
+
if (isNaN(position)) {
|
|
317
328
|
position = file.position;
|
|
318
329
|
}
|
|
319
330
|
return file.readSync(buffer, offset, length, position);
|
|
@@ -386,7 +397,7 @@ export function readdirSync(path, options) {
|
|
|
386
397
|
return new Dirent(entry, statSync(join(path, entry)));
|
|
387
398
|
}
|
|
388
399
|
if (options == 'buffer' || (typeof options == 'object' && options.encoding == 'buffer')) {
|
|
389
|
-
return
|
|
400
|
+
return Buffer.from(entry);
|
|
390
401
|
}
|
|
391
402
|
return entry;
|
|
392
403
|
});
|
|
@@ -414,7 +425,7 @@ export function symlinkSync(target, path, type = 'file') {
|
|
|
414
425
|
throw new ApiError(ErrorCode.EINVAL, 'Invalid type: ' + type);
|
|
415
426
|
}
|
|
416
427
|
if (existsSync(path)) {
|
|
417
|
-
throw ApiError.EEXIST
|
|
428
|
+
throw ApiError.With('EEXIST', path, 'symlinkSync');
|
|
418
429
|
}
|
|
419
430
|
writeFileSync(path, target);
|
|
420
431
|
const file = _openSync(path, 'r+', 0o644, false);
|
|
@@ -422,12 +433,12 @@ export function symlinkSync(target, path, type = 'file') {
|
|
|
422
433
|
}
|
|
423
434
|
symlinkSync;
|
|
424
435
|
export function readlinkSync(path, options) {
|
|
425
|
-
const value = _readFileSync(path, 'r', false);
|
|
436
|
+
const value = Buffer.from(_readFileSync(path, 'r', false));
|
|
426
437
|
const encoding = typeof options == 'object' ? options.encoding : options;
|
|
427
438
|
if (encoding == 'buffer') {
|
|
428
439
|
return value;
|
|
429
440
|
}
|
|
430
|
-
return
|
|
441
|
+
return value.toString(encoding);
|
|
431
442
|
}
|
|
432
443
|
readlinkSync;
|
|
433
444
|
// PROPERTY OPERATIONS
|
|
@@ -509,7 +520,7 @@ export function realpathSync(path, options) {
|
|
|
509
520
|
if (!stats.isSymbolicLink()) {
|
|
510
521
|
return path;
|
|
511
522
|
}
|
|
512
|
-
const dst = normalizePath(mountPoint +
|
|
523
|
+
const dst = normalizePath(mountPoint + Buffer.from(_readFileSync(resolvedPath, 'r+', false)).toString());
|
|
513
524
|
return realpathSync(dst);
|
|
514
525
|
}
|
|
515
526
|
catch (e) {
|
|
@@ -529,27 +540,52 @@ export function accessSync(path, mode = 0o600) {
|
|
|
529
540
|
}
|
|
530
541
|
}
|
|
531
542
|
accessSync;
|
|
543
|
+
/**
|
|
544
|
+
* @todo Implement
|
|
545
|
+
*/
|
|
532
546
|
export function rmSync(path) {
|
|
533
|
-
throw
|
|
547
|
+
throw ApiError.With('ENOTSUP', path, 'rmSync');
|
|
534
548
|
}
|
|
535
549
|
rmSync;
|
|
536
550
|
export function mkdtempSync(prefix, options) {
|
|
537
|
-
throw
|
|
551
|
+
throw ApiError.With('ENOTSUP', prefix, 'mkdtempSync');
|
|
538
552
|
}
|
|
539
553
|
mkdtempSync;
|
|
554
|
+
/**
|
|
555
|
+
* @todo Implement
|
|
556
|
+
*/
|
|
540
557
|
export function copyFileSync(src, dest, flags) {
|
|
541
|
-
throw
|
|
558
|
+
throw ApiError.With('ENOTSUP', src, 'copyFileSync');
|
|
542
559
|
}
|
|
543
560
|
copyFileSync;
|
|
561
|
+
/**
|
|
562
|
+
* @todo Implement
|
|
563
|
+
*/
|
|
544
564
|
export function readvSync(fd, buffers, position) {
|
|
545
|
-
throw
|
|
565
|
+
throw ApiError.With('ENOTSUP', fd2file(fd).path, 'readvSync');
|
|
546
566
|
}
|
|
547
567
|
readvSync;
|
|
568
|
+
/**
|
|
569
|
+
* @todo Implement
|
|
570
|
+
*/
|
|
548
571
|
export function writevSync(fd, buffers, position) {
|
|
549
|
-
throw
|
|
572
|
+
throw ApiError.With('ENOTSUP', fd2file(fd).path, 'writevSync');
|
|
550
573
|
}
|
|
551
574
|
writevSync;
|
|
575
|
+
/**
|
|
576
|
+
* @todo Implement
|
|
577
|
+
*/
|
|
552
578
|
export function opendirSync(path, options) {
|
|
553
|
-
throw
|
|
579
|
+
throw ApiError.With('ENOTSUP', path, 'opendirSync');
|
|
554
580
|
}
|
|
555
581
|
opendirSync;
|
|
582
|
+
/**
|
|
583
|
+
* @todo Implement
|
|
584
|
+
*/
|
|
585
|
+
export function cpSync(source, destination, opts) {
|
|
586
|
+
throw ApiError.With('ENOTSUP', source, 'cpSync');
|
|
587
|
+
}
|
|
588
|
+
cpSync;
|
|
589
|
+
export function statfsSync(path, options) {
|
|
590
|
+
throw ApiError.With('ENOTSUP', path, 'statfsSync');
|
|
591
|
+
}
|
package/dist/file.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import type { FileReadResult } from 'node:fs/promises';
|
|
1
4
|
import type { FileSystem } from './filesystem.js';
|
|
2
5
|
import { Stats, type FileType } from './stats.js';
|
|
3
6
|
declare global {
|
|
@@ -29,6 +32,10 @@ export declare enum ActionType {
|
|
|
29
32
|
export declare function parseFlag(flag: string | number): string;
|
|
30
33
|
export declare function flagToString(flag: number): string;
|
|
31
34
|
export declare function flagToNumber(flag: string): number;
|
|
35
|
+
/**
|
|
36
|
+
* Parses a flag as a mode (W_OK, R_OK, and/or X_OK)
|
|
37
|
+
* @param flag the flag to parse
|
|
38
|
+
*/
|
|
32
39
|
export declare function flagToMode(flag: string): number;
|
|
33
40
|
export declare function isReadable(flag: string): boolean;
|
|
34
41
|
export declare function isWriteable(flag: string): boolean;
|
|
@@ -118,10 +125,7 @@ export declare abstract class File {
|
|
|
118
125
|
* position.
|
|
119
126
|
* @returns Promise resolving to the new length of the buffer
|
|
120
127
|
*/
|
|
121
|
-
abstract read<TBuffer extends
|
|
122
|
-
bytesRead: number;
|
|
123
|
-
buffer: TBuffer;
|
|
124
|
-
}>;
|
|
128
|
+
abstract read<TBuffer extends NodeJS.ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<FileReadResult<TBuffer>>;
|
|
125
129
|
/**
|
|
126
130
|
* Read data from the file.
|
|
127
131
|
* @param buffer The buffer that the data will be written to.
|
|
@@ -131,7 +135,7 @@ export declare abstract class File {
|
|
|
131
135
|
* in the file. If position is null, data will be read from the current file
|
|
132
136
|
* position.
|
|
133
137
|
*/
|
|
134
|
-
abstract readSync(buffer:
|
|
138
|
+
abstract readSync(buffer: ArrayBufferView, offset?: number, length?: number, position?: number): number;
|
|
135
139
|
/**
|
|
136
140
|
* Asynchronous `datasync`.
|
|
137
141
|
*
|
|
@@ -298,7 +302,7 @@ export declare abstract class PreloadFile<FS extends FileSystem> extends File {
|
|
|
298
302
|
* in the file. If position is null, data will be read from the current file
|
|
299
303
|
* position.
|
|
300
304
|
*/
|
|
301
|
-
read<TBuffer extends
|
|
305
|
+
read<TBuffer extends ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<{
|
|
302
306
|
bytesRead: number;
|
|
303
307
|
buffer: TBuffer;
|
|
304
308
|
}>;
|
|
@@ -313,7 +317,7 @@ export declare abstract class PreloadFile<FS extends FileSystem> extends File {
|
|
|
313
317
|
* position.
|
|
314
318
|
* @returns number of bytes written
|
|
315
319
|
*/
|
|
316
|
-
readSync(buffer:
|
|
320
|
+
readSync(buffer: ArrayBufferView, offset?: number, length?: number, position?: number): number;
|
|
317
321
|
/**
|
|
318
322
|
* Asynchronous `fchmod`.
|
|
319
323
|
* @param mode the mode
|
package/dist/file.js
CHANGED
|
@@ -86,6 +86,10 @@ export function flagToNumber(flag) {
|
|
|
86
86
|
throw new Error('Invalid flag string: ' + flag);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Parses a flag as a mode (W_OK, R_OK, and/or X_OK)
|
|
91
|
+
* @param flag the flag to parse
|
|
92
|
+
*/
|
|
89
93
|
export function flagToMode(flag) {
|
|
90
94
|
let mode = 0;
|
|
91
95
|
mode <<= 1;
|
|
@@ -323,15 +327,16 @@ export class PreloadFile extends File {
|
|
|
323
327
|
}
|
|
324
328
|
}
|
|
325
329
|
}
|
|
326
|
-
|
|
327
|
-
|
|
330
|
+
const slice = buffer.slice(offset, offset + length);
|
|
331
|
+
this._buffer.set(slice, position);
|
|
332
|
+
const bytesWritten = slice.byteLength;
|
|
328
333
|
this.stats.mtimeMs = Date.now();
|
|
329
334
|
if (isSynchronous(this.flag)) {
|
|
330
335
|
this.syncSync();
|
|
331
|
-
return
|
|
336
|
+
return bytesWritten;
|
|
332
337
|
}
|
|
333
|
-
this.position = position +
|
|
334
|
-
return
|
|
338
|
+
this.position = position + bytesWritten;
|
|
339
|
+
return bytesWritten;
|
|
335
340
|
}
|
|
336
341
|
/**
|
|
337
342
|
* Read data from the file.
|
|
@@ -374,7 +379,7 @@ export class PreloadFile extends File {
|
|
|
374
379
|
// No copy/read. Return immediatly for better performance
|
|
375
380
|
return bytesRead;
|
|
376
381
|
}
|
|
377
|
-
buffer.set(this._buffer.slice(position, end), offset);
|
|
382
|
+
new Uint8Array(buffer.buffer).set(this._buffer.slice(position, end), offset);
|
|
378
383
|
return bytesRead;
|
|
379
384
|
}
|
|
380
385
|
/**
|
|
@@ -389,9 +394,6 @@ export class PreloadFile extends File {
|
|
|
389
394
|
* @param mode
|
|
390
395
|
*/
|
|
391
396
|
chmodSync(mode) {
|
|
392
|
-
if (!this.fs.metadata().supportsProperties) {
|
|
393
|
-
throw new ApiError(ErrorCode.ENOTSUP);
|
|
394
|
-
}
|
|
395
397
|
this._dirty = true;
|
|
396
398
|
this.stats.chmod(mode);
|
|
397
399
|
this.syncSync();
|
|
@@ -410,9 +412,6 @@ export class PreloadFile extends File {
|
|
|
410
412
|
* @param gid
|
|
411
413
|
*/
|
|
412
414
|
chownSync(uid, gid) {
|
|
413
|
-
if (!this.fs.metadata().supportsProperties) {
|
|
414
|
-
throw new ApiError(ErrorCode.ENOTSUP);
|
|
415
|
-
}
|
|
416
415
|
this._dirty = true;
|
|
417
416
|
this.stats.chown(uid, gid);
|
|
418
417
|
this.syncSync();
|
|
@@ -421,9 +420,6 @@ export class PreloadFile extends File {
|
|
|
421
420
|
this.utimesSync(atime, mtime);
|
|
422
421
|
}
|
|
423
422
|
utimesSync(atime, mtime) {
|
|
424
|
-
if (!this.fs.metadata().supportsProperties) {
|
|
425
|
-
throw new ApiError(ErrorCode.ENOTSUP);
|
|
426
|
-
}
|
|
427
423
|
this._dirty = true;
|
|
428
424
|
this.stats.atime = atime;
|
|
429
425
|
this.stats.mtime = mtime;
|
package/dist/stats.d.ts
CHANGED
|
@@ -146,9 +146,8 @@ export declare abstract class StatsCommon<T extends number | bigint> implements
|
|
|
146
146
|
isFIFO(): boolean;
|
|
147
147
|
/**
|
|
148
148
|
* Checks if a given user/group has access to this item
|
|
149
|
-
* @param mode The
|
|
150
|
-
* @param
|
|
151
|
-
* @param gid The requesting GID
|
|
149
|
+
* @param mode The requested access, combination of W_OK, R_OK, and X_OK
|
|
150
|
+
* @param cred The requesting credentials
|
|
152
151
|
* @returns True if the request has access, false if the request does not
|
|
153
152
|
* @internal
|
|
154
153
|
*/
|
|
@@ -202,19 +201,35 @@ export declare class BigIntStats extends StatsCommon<bigint> implements Node.Big
|
|
|
202
201
|
*/
|
|
203
202
|
static clone(stats: BigIntStats | Stats): BigIntStats;
|
|
204
203
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
204
|
+
export declare class StatsFs implements Node.StatsFsBase<number> {
|
|
205
|
+
/** Type of file system. */
|
|
206
|
+
type: number;
|
|
207
|
+
/** Optimal transfer block size. */
|
|
208
|
+
bsize: number;
|
|
209
|
+
/** Total data blocks in file system. */
|
|
210
|
+
blocks: number;
|
|
211
|
+
/** Free blocks in file system. */
|
|
212
|
+
bfree: number;
|
|
213
|
+
/** Available blocks for unprivileged users */
|
|
214
|
+
bavail: number;
|
|
215
|
+
/** Total file nodes in file system. */
|
|
216
|
+
files: number;
|
|
217
|
+
/** Free file nodes in file system. */
|
|
218
|
+
ffree: number;
|
|
219
|
+
}
|
|
220
|
+
export declare class BigIntStatsFs implements Node.StatsFsBase<bigint> {
|
|
221
|
+
/** Type of file system. */
|
|
222
|
+
type: bigint;
|
|
223
|
+
/** Optimal transfer block size. */
|
|
224
|
+
bsize: bigint;
|
|
225
|
+
/** Total data blocks in file system. */
|
|
226
|
+
blocks: bigint;
|
|
227
|
+
/** Free blocks in file system. */
|
|
228
|
+
bfree: bigint;
|
|
229
|
+
/** Available blocks for unprivileged users */
|
|
230
|
+
bavail: bigint;
|
|
231
|
+
/** Total file nodes in file system. */
|
|
232
|
+
files: bigint;
|
|
233
|
+
/** Free file nodes in file system. */
|
|
234
|
+
ffree: bigint;
|
|
235
|
+
}
|
package/dist/stats.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S_IFDIR, S_IFLNK, S_IFMT, S_IFREG } from './emulation/constants.js';
|
|
1
|
+
import { S_IFDIR, S_IFLNK, S_IFMT, S_IFREG, S_IRWXG, S_IRWXO, S_IRWXU } from './emulation/constants.js';
|
|
2
2
|
/**
|
|
3
3
|
* Indicates the type of the given file. Applied to 'mode'.
|
|
4
4
|
*/
|
|
@@ -145,9 +145,8 @@ export class StatsCommon {
|
|
|
145
145
|
}
|
|
146
146
|
/**
|
|
147
147
|
* Checks if a given user/group has access to this item
|
|
148
|
-
* @param mode The
|
|
149
|
-
* @param
|
|
150
|
-
* @param gid The requesting GID
|
|
148
|
+
* @param mode The requested access, combination of W_OK, R_OK, and X_OK
|
|
149
|
+
* @param cred The requesting credentials
|
|
151
150
|
* @returns True if the request has access, false if the request does not
|
|
152
151
|
* @internal
|
|
153
152
|
*/
|
|
@@ -156,24 +155,9 @@ export class StatsCommon {
|
|
|
156
155
|
//Running as root
|
|
157
156
|
return true;
|
|
158
157
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const uPerms = (0xf00 & perms) >> 8;
|
|
163
|
-
uMode = (mode ^ uPerms) & mode;
|
|
164
|
-
}
|
|
165
|
-
if (cred.egid == this.gid) {
|
|
166
|
-
const gPerms = (0xf0 & perms) >> 4;
|
|
167
|
-
gMode = (mode ^ gPerms) & mode;
|
|
168
|
-
}
|
|
169
|
-
const wPerms = 0xf & perms;
|
|
170
|
-
wMode = (mode ^ wPerms) & mode;
|
|
171
|
-
/*
|
|
172
|
-
Result = 0b0xxx (read, write, execute)
|
|
173
|
-
If any bits are set that means the request does not have that permission.
|
|
174
|
-
*/
|
|
175
|
-
const result = uMode & gMode & wMode;
|
|
176
|
-
return !result;
|
|
158
|
+
// Mask for
|
|
159
|
+
const adjusted = (cred.uid == this.uid ? S_IRWXU : 0) | (cred.gid == this.gid ? S_IRWXG : 0) | S_IRWXO;
|
|
160
|
+
return (mode & this.mode & adjusted) == mode;
|
|
177
161
|
}
|
|
178
162
|
/**
|
|
179
163
|
* Convert the current stats object into a credentials object
|
|
@@ -251,34 +235,7 @@ export class BigIntStats extends StatsCommon {
|
|
|
251
235
|
return new BigIntStats(stats);
|
|
252
236
|
}
|
|
253
237
|
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* @returns true if stats is a file.
|
|
257
|
-
*/
|
|
258
|
-
export function isFile(stats) {
|
|
259
|
-
return (Number(stats.mode) & S_IFMT) === S_IFREG;
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* @returns True if stats is a directory.
|
|
263
|
-
*/
|
|
264
|
-
export function isDirectory(stats) {
|
|
265
|
-
return (Number(stats.mode) & S_IFMT) === S_IFDIR;
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* @returns true if stats is a symbolic link
|
|
269
|
-
*/
|
|
270
|
-
export function isSymbolicLink(stats) {
|
|
271
|
-
return (Number(stats.mode) & S_IFMT) === S_IFLNK;
|
|
272
|
-
}
|
|
273
|
-
export function isSocket() {
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
export function isBlockDevice() {
|
|
277
|
-
return false;
|
|
278
|
-
}
|
|
279
|
-
export function isCharacterDevice() {
|
|
280
|
-
return false;
|
|
238
|
+
export class StatsFs {
|
|
281
239
|
}
|
|
282
|
-
export
|
|
283
|
-
return false;
|
|
240
|
+
export class BigIntStatsFs {
|
|
284
241
|
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import { FileSystem } from './filesystem.js';
|
|
3
2
|
import { Cred } from './cred.js';
|
|
4
3
|
declare global {
|
|
@@ -25,12 +24,12 @@ export declare const setImmediate: (callback: () => unknown) => void;
|
|
|
25
24
|
* Encodes a string into a buffer
|
|
26
25
|
* @internal
|
|
27
26
|
*/
|
|
28
|
-
export declare function encode(input: string
|
|
27
|
+
export declare function encode(input: string): Uint8Array;
|
|
29
28
|
/**
|
|
30
29
|
* Decodes a string from a buffer
|
|
31
30
|
* @internal
|
|
32
31
|
*/
|
|
33
|
-
export declare function decode(input?: Uint8Array
|
|
32
|
+
export declare function decode(input?: Uint8Array): string;
|
|
34
33
|
/**
|
|
35
34
|
* Decodes a directory listing
|
|
36
35
|
* @internal
|