@zenfs/core 0.12.0 → 0.12.2
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/backends/backend.d.ts +15 -5
- package/dist/backends/index/fs.d.ts +1 -0
- package/dist/backends/index/index.d.ts +5 -0
- package/dist/backends/index/index.js +1 -0
- package/dist/backends/overlay.js +1 -1
- package/dist/backends/port/fs.d.ts +3 -1
- package/dist/browser.min.js +4 -4
- package/dist/browser.min.js.map +4 -4
- package/dist/config.d.ts +33 -11
- package/dist/config.js +16 -7
- package/dist/emulation/async.d.ts +5 -4
- package/dist/emulation/async.js +3 -2
- package/dist/emulation/index.d.ts +1 -1
- package/dist/emulation/index.js +1 -1
- package/dist/emulation/path.d.ts +4 -1
- package/dist/emulation/promises.d.ts +4 -4
- package/dist/emulation/promises.js +27 -27
- package/dist/emulation/shared.d.ts +6 -0
- package/dist/emulation/shared.js +19 -1
- package/dist/emulation/sync.d.ts +4 -4
- package/dist/emulation/sync.js +76 -38
- package/dist/file.d.ts +5 -10
- package/dist/file.js +38 -55
- package/dist/filesystem.d.ts +45 -3
- package/dist/filesystem.js +37 -8
- package/dist/stats.d.ts +16 -16
- package/dist/stats.js +42 -49
- package/package.json +2 -2
- package/src/backends/backend.ts +15 -6
- package/src/backends/index/index.ts +5 -0
- package/src/backends/overlay.ts +1 -1
- package/src/config.ts +62 -21
- package/src/emulation/async.ts +19 -18
- package/src/emulation/index.ts +1 -1
- package/src/emulation/path.ts +4 -1
- package/src/emulation/promises.ts +33 -31
- package/src/emulation/shared.ts +22 -1
- package/src/emulation/sync.ts +83 -54
- package/src/error.ts +1 -1
- package/src/file.ts +39 -57
- package/src/filesystem.ts +133 -51
- package/src/stats.ts +48 -60
package/src/filesystem.ts
CHANGED
|
@@ -30,6 +30,41 @@ export interface FileSystemMetadata {
|
|
|
30
30
|
* The available space
|
|
31
31
|
*/
|
|
32
32
|
freeSpace: number;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* If set, disables File from using a resizable array buffer.
|
|
36
|
+
* @default false
|
|
37
|
+
*/
|
|
38
|
+
noResizableBuffers: boolean;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* If set, disables caching on async file systems.
|
|
42
|
+
* This means *sync operations will not work*.
|
|
43
|
+
* It has no affect on sync file systems.
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
noAsyncCache: boolean;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The optimal block size to use with the file system
|
|
50
|
+
* @default 4096
|
|
51
|
+
*/
|
|
52
|
+
blockSize?: number;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Total number of (file) nodes available
|
|
56
|
+
*/
|
|
57
|
+
totalNodes?: number;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Number of free (file) nodes available
|
|
61
|
+
*/
|
|
62
|
+
freeNodes?: number;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The type of the FS
|
|
66
|
+
*/
|
|
67
|
+
type?: number;
|
|
33
68
|
}
|
|
34
69
|
|
|
35
70
|
/**
|
|
@@ -44,7 +79,13 @@ export interface FileSystemMetadata {
|
|
|
44
79
|
*/
|
|
45
80
|
export abstract class FileSystem {
|
|
46
81
|
/**
|
|
47
|
-
*
|
|
82
|
+
* Numeric type, used for statfs
|
|
83
|
+
* @internal @protected
|
|
84
|
+
*/
|
|
85
|
+
_type?: number;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Get metadata about the current file system
|
|
48
89
|
*/
|
|
49
90
|
public metadata(): FileSystemMetadata {
|
|
50
91
|
return {
|
|
@@ -52,12 +93,13 @@ export abstract class FileSystem {
|
|
|
52
93
|
readonly: false,
|
|
53
94
|
totalSpace: 0,
|
|
54
95
|
freeSpace: 0,
|
|
96
|
+
noResizableBuffers: false,
|
|
97
|
+
noAsyncCache: false,
|
|
98
|
+
type: this._type,
|
|
55
99
|
};
|
|
56
100
|
}
|
|
57
101
|
|
|
58
|
-
public constructor(
|
|
59
|
-
// unused
|
|
60
|
-
}
|
|
102
|
+
public constructor() {}
|
|
61
103
|
|
|
62
104
|
public async ready(): Promise<void> {}
|
|
63
105
|
|
|
@@ -157,7 +199,7 @@ export abstract class FileSystem {
|
|
|
157
199
|
await this.stat(path, cred);
|
|
158
200
|
return true;
|
|
159
201
|
} catch (e) {
|
|
160
|
-
return
|
|
202
|
+
return (e as ErrnoError).code != 'ENOENT';
|
|
161
203
|
}
|
|
162
204
|
}
|
|
163
205
|
|
|
@@ -169,7 +211,7 @@ export abstract class FileSystem {
|
|
|
169
211
|
this.statSync(path, cred);
|
|
170
212
|
return true;
|
|
171
213
|
} catch (e) {
|
|
172
|
-
return
|
|
214
|
+
return (e as ErrnoError).code != 'ENOENT';
|
|
173
215
|
}
|
|
174
216
|
}
|
|
175
217
|
|
|
@@ -198,19 +240,19 @@ export abstract class FileSystem {
|
|
|
198
240
|
* @internal
|
|
199
241
|
*/
|
|
200
242
|
declare abstract class SyncFS extends FileSystem {
|
|
201
|
-
metadata(): FileSystemMetadata;
|
|
202
|
-
ready(): Promise<void>;
|
|
203
|
-
exists(path: string, cred: Cred): Promise<boolean>;
|
|
204
|
-
rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
|
|
205
|
-
stat(path: string, cred: Cred): Promise<Stats>;
|
|
206
|
-
createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File>;
|
|
207
|
-
openFile(path: string, flag: string, cred: Cred): Promise<File>;
|
|
208
|
-
unlink(path: string, cred: Cred): Promise<void>;
|
|
209
|
-
rmdir(path: string, cred: Cred): Promise<void>;
|
|
210
|
-
mkdir(path: string, mode: number, cred: Cred): Promise<void>;
|
|
211
|
-
readdir(path: string, cred: Cred): Promise<string[]>;
|
|
212
|
-
link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
|
|
213
|
-
sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
|
|
243
|
+
public metadata(): FileSystemMetadata;
|
|
244
|
+
public ready(): Promise<void>;
|
|
245
|
+
public exists(path: string, cred: Cred): Promise<boolean>;
|
|
246
|
+
public rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
|
|
247
|
+
public stat(path: string, cred: Cred): Promise<Stats>;
|
|
248
|
+
public createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File>;
|
|
249
|
+
public openFile(path: string, flag: string, cred: Cred): Promise<File>;
|
|
250
|
+
public unlink(path: string, cred: Cred): Promise<void>;
|
|
251
|
+
public rmdir(path: string, cred: Cred): Promise<void>;
|
|
252
|
+
public mkdir(path: string, mode: number, cred: Cred): Promise<void>;
|
|
253
|
+
public readdir(path: string, cred: Cred): Promise<string[]>;
|
|
254
|
+
public link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
|
|
255
|
+
public sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
|
|
214
256
|
}
|
|
215
257
|
|
|
216
258
|
/**
|
|
@@ -268,25 +310,33 @@ export function Sync<T extends abstract new (...args: any[]) => FileSystem>(FS:
|
|
|
268
310
|
|
|
269
311
|
/**
|
|
270
312
|
* @internal
|
|
313
|
+
* Note: `_*` should be treated like protected.
|
|
314
|
+
* Protected can't be used because of TS quirks however.
|
|
271
315
|
*/
|
|
272
316
|
declare abstract class AsyncFS extends FileSystem {
|
|
273
317
|
/**
|
|
318
|
+
* @access protected
|
|
274
319
|
* @hidden
|
|
275
320
|
*/
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
321
|
+
_disableSync: boolean;
|
|
322
|
+
/**
|
|
323
|
+
* @access protected
|
|
324
|
+
* @hidden
|
|
325
|
+
*/
|
|
326
|
+
abstract _sync?: FileSystem;
|
|
327
|
+
public queueDone(): Promise<void>;
|
|
328
|
+
public metadata(): FileSystemMetadata;
|
|
329
|
+
public ready(): Promise<void>;
|
|
330
|
+
public renameSync(oldPath: string, newPath: string, cred: Cred): void;
|
|
331
|
+
public statSync(path: string, cred: Cred): Stats;
|
|
332
|
+
public createFileSync(path: string, flag: string, mode: number, cred: Cred): File;
|
|
333
|
+
public openFileSync(path: string, flag: string, cred: Cred): File;
|
|
334
|
+
public unlinkSync(path: string, cred: Cred): void;
|
|
335
|
+
public rmdirSync(path: string, cred: Cred): void;
|
|
336
|
+
public mkdirSync(path: string, mode: number, cred: Cred): void;
|
|
337
|
+
public readdirSync(path: string, cred: Cred): string[];
|
|
338
|
+
public linkSync(srcpath: string, dstpath: string, cred: Cred): void;
|
|
339
|
+
public syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
|
|
290
340
|
}
|
|
291
341
|
|
|
292
342
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -331,14 +381,18 @@ export function Async<T extends abstract new (...args: any[]) => FileSystem>(FS:
|
|
|
331
381
|
|
|
332
382
|
private _isInitialized: boolean = false;
|
|
333
383
|
|
|
334
|
-
|
|
384
|
+
_disableSync: boolean = false;
|
|
385
|
+
|
|
386
|
+
abstract _sync?: FileSystem;
|
|
335
387
|
|
|
336
388
|
public async ready(): Promise<void> {
|
|
337
|
-
await this._sync.ready();
|
|
338
389
|
await super.ready();
|
|
339
|
-
if (this._isInitialized) {
|
|
390
|
+
if (this._isInitialized || this._disableSync) {
|
|
340
391
|
return;
|
|
341
392
|
}
|
|
393
|
+
this.checkSync();
|
|
394
|
+
|
|
395
|
+
await this._sync.ready();
|
|
342
396
|
|
|
343
397
|
try {
|
|
344
398
|
await this.crossCopy('/');
|
|
@@ -349,22 +403,42 @@ export function Async<T extends abstract new (...args: any[]) => FileSystem>(FS:
|
|
|
349
403
|
}
|
|
350
404
|
}
|
|
351
405
|
|
|
406
|
+
public metadata(): FileSystemMetadata {
|
|
407
|
+
return {
|
|
408
|
+
...super.metadata(),
|
|
409
|
+
noAsyncCache: this._disableSync,
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
protected checkSync(path?: string, syscall?: string): asserts this is { _sync: FileSystem } {
|
|
414
|
+
if (this._disableSync) {
|
|
415
|
+
throw new ErrnoError(Errno.ENOTSUP, 'Sync caching has been disabled for this async file system', path, syscall);
|
|
416
|
+
}
|
|
417
|
+
if (!this._sync) {
|
|
418
|
+
throw new ErrnoError(Errno.ENOTSUP, 'No sync cache is attached to this async file system', path, syscall);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
352
422
|
public renameSync(oldPath: string, newPath: string, cred: Cred): void {
|
|
423
|
+
this.checkSync(oldPath, 'rename');
|
|
353
424
|
this._sync.renameSync(oldPath, newPath, cred);
|
|
354
425
|
this.queue('rename', oldPath, newPath, cred);
|
|
355
426
|
}
|
|
356
427
|
|
|
357
428
|
public statSync(path: string, cred: Cred): Stats {
|
|
429
|
+
this.checkSync(path, 'stat');
|
|
358
430
|
return this._sync.statSync(path, cred);
|
|
359
431
|
}
|
|
360
432
|
|
|
361
433
|
public createFileSync(path: string, flag: string, mode: number, cred: Cred): PreloadFile<this> {
|
|
434
|
+
this.checkSync(path, 'createFile');
|
|
362
435
|
this._sync.createFileSync(path, flag, mode, cred);
|
|
363
436
|
this.queue('createFile', path, flag, mode, cred);
|
|
364
437
|
return this.openFileSync(path, flag, cred);
|
|
365
438
|
}
|
|
366
439
|
|
|
367
440
|
public openFileSync(path: string, flag: string, cred: Cred): PreloadFile<this> {
|
|
441
|
+
this.checkSync(path, 'openFile');
|
|
368
442
|
const file = this._sync.openFileSync(path, flag, cred);
|
|
369
443
|
const stats = file.statSync();
|
|
370
444
|
const buffer = new Uint8Array(stats.size);
|
|
@@ -373,35 +447,42 @@ export function Async<T extends abstract new (...args: any[]) => FileSystem>(FS:
|
|
|
373
447
|
}
|
|
374
448
|
|
|
375
449
|
public unlinkSync(path: string, cred: Cred): void {
|
|
450
|
+
this.checkSync(path, 'unlinkSync');
|
|
376
451
|
this._sync.unlinkSync(path, cred);
|
|
377
452
|
this.queue('unlink', path, cred);
|
|
378
453
|
}
|
|
379
454
|
|
|
380
455
|
public rmdirSync(path: string, cred: Cred): void {
|
|
456
|
+
this.checkSync(path, 'rmdir');
|
|
381
457
|
this._sync.rmdirSync(path, cred);
|
|
382
458
|
this.queue('rmdir', path, cred);
|
|
383
459
|
}
|
|
384
460
|
|
|
385
461
|
public mkdirSync(path: string, mode: number, cred: Cred): void {
|
|
462
|
+
this.checkSync(path, 'mkdir');
|
|
386
463
|
this._sync.mkdirSync(path, mode, cred);
|
|
387
464
|
this.queue('mkdir', path, mode, cred);
|
|
388
465
|
}
|
|
389
466
|
|
|
390
467
|
public readdirSync(path: string, cred: Cred): string[] {
|
|
468
|
+
this.checkSync(path, 'readdir');
|
|
391
469
|
return this._sync.readdirSync(path, cred);
|
|
392
470
|
}
|
|
393
471
|
|
|
394
472
|
public linkSync(srcpath: string, dstpath: string, cred: Cred): void {
|
|
473
|
+
this.checkSync(srcpath, 'link');
|
|
395
474
|
this._sync.linkSync(srcpath, dstpath, cred);
|
|
396
475
|
this.queue('link', srcpath, dstpath, cred);
|
|
397
476
|
}
|
|
398
477
|
|
|
399
478
|
public syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void {
|
|
479
|
+
this.checkSync(path, 'sync');
|
|
400
480
|
this._sync.syncSync(path, data, stats);
|
|
401
481
|
this.queue('sync', path, data, stats);
|
|
402
482
|
}
|
|
403
483
|
|
|
404
484
|
public existsSync(path: string, cred: Cred): boolean {
|
|
485
|
+
this.checkSync(path, 'exists');
|
|
405
486
|
return this._sync.existsSync(path, cred);
|
|
406
487
|
}
|
|
407
488
|
|
|
@@ -409,6 +490,7 @@ export function Async<T extends abstract new (...args: any[]) => FileSystem>(FS:
|
|
|
409
490
|
* @internal
|
|
410
491
|
*/
|
|
411
492
|
protected async crossCopy(path: string): Promise<void> {
|
|
493
|
+
this.checkSync(path, 'crossCopy');
|
|
412
494
|
const stats = await this.stat(path, rootCred);
|
|
413
495
|
if (stats.isDirectory()) {
|
|
414
496
|
if (path !== '/') {
|
|
@@ -463,21 +545,21 @@ export function Async<T extends abstract new (...args: any[]) => FileSystem>(FS:
|
|
|
463
545
|
* @internal
|
|
464
546
|
*/
|
|
465
547
|
declare abstract class ReadonlyFS extends FileSystem {
|
|
466
|
-
metadata(): FileSystemMetadata;
|
|
467
|
-
rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
|
|
468
|
-
renameSync(oldPath: string, newPath: string, cred: Cred): void;
|
|
469
|
-
createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File>;
|
|
470
|
-
createFileSync(path: string, flag: string, mode: number, cred: Cred): File;
|
|
471
|
-
unlink(path: string, cred: Cred): Promise<void>;
|
|
472
|
-
unlinkSync(path: string, cred: Cred): void;
|
|
473
|
-
rmdir(path: string, cred: Cred): Promise<void>;
|
|
474
|
-
rmdirSync(path: string, cred: Cred): void;
|
|
475
|
-
mkdir(path: string, mode: number, cred: Cred): Promise<void>;
|
|
476
|
-
mkdirSync(path: string, mode: number, cred: Cred): void;
|
|
477
|
-
link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
|
|
478
|
-
linkSync(srcpath: string, dstpath: string, cred: Cred): void;
|
|
479
|
-
sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
|
|
480
|
-
syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
|
|
548
|
+
public metadata(): FileSystemMetadata;
|
|
549
|
+
public rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
|
|
550
|
+
public renameSync(oldPath: string, newPath: string, cred: Cred): void;
|
|
551
|
+
public createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File>;
|
|
552
|
+
public createFileSync(path: string, flag: string, mode: number, cred: Cred): File;
|
|
553
|
+
public unlink(path: string, cred: Cred): Promise<void>;
|
|
554
|
+
public unlinkSync(path: string, cred: Cred): void;
|
|
555
|
+
public rmdir(path: string, cred: Cred): Promise<void>;
|
|
556
|
+
public rmdirSync(path: string, cred: Cred): void;
|
|
557
|
+
public mkdir(path: string, mode: number, cred: Cred): Promise<void>;
|
|
558
|
+
public mkdirSync(path: string, mode: number, cred: Cred): void;
|
|
559
|
+
public link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
|
|
560
|
+
public linkSync(srcpath: string, dstpath: string, cred: Cred): void;
|
|
561
|
+
public sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
|
|
562
|
+
public syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
|
|
481
563
|
}
|
|
482
564
|
|
|
483
565
|
/**
|
package/src/stats.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type * as Node from 'fs';
|
|
2
2
|
import { Cred } from './cred.js';
|
|
3
|
-
import { S_IFDIR, S_IFLNK, S_IFMT, S_IFREG, S_IRWXG, S_IRWXO, S_IRWXU } from './emulation/constants.js';
|
|
3
|
+
import { S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK, S_IRWXG, S_IRWXO, S_IRWXU } from './emulation/constants.js';
|
|
4
|
+
import { size_max } from './inode.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Indicates the type of the given file. Applied to 'mode'.
|
|
@@ -60,21 +61,15 @@ export interface StatsLike<T extends number | bigint = number | bigint> {
|
|
|
60
61
|
* Common code used by both Stats and BigIntStats.
|
|
61
62
|
*/
|
|
62
63
|
export abstract class StatsCommon<T extends number | bigint> implements Node.StatsBase<T>, StatsLike {
|
|
63
|
-
protected abstract _isBigint:
|
|
64
|
-
|
|
65
|
-
protected get _typename(): string {
|
|
66
|
-
return this._isBigint ? 'bigint' : 'number';
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
protected get _typename_inverse(): string {
|
|
70
|
-
return this._isBigint ? 'number' : 'bigint';
|
|
71
|
-
}
|
|
64
|
+
protected abstract _isBigint: T extends bigint ? true : false;
|
|
72
65
|
|
|
73
66
|
protected _convert(arg: number | bigint | string | boolean): T {
|
|
74
|
-
return
|
|
67
|
+
return (this._isBigint ? BigInt(arg) : Number(arg)) as T;
|
|
75
68
|
}
|
|
76
69
|
|
|
77
|
-
public blocks: T
|
|
70
|
+
public get blocks(): T {
|
|
71
|
+
return this._convert(Math.ceil(Number(this.size) / 512));
|
|
72
|
+
}
|
|
78
73
|
|
|
79
74
|
/**
|
|
80
75
|
* Unix-style file mode (e.g. 0o644) that includes the type of the item.
|
|
@@ -184,17 +179,15 @@ export abstract class StatsCommon<T extends number | bigint> implements Node.Sta
|
|
|
184
179
|
* Creates a new stats instance from a stats-like object. Can be used to copy stats (note)
|
|
185
180
|
*/
|
|
186
181
|
constructor({ atimeMs, mtimeMs, ctimeMs, birthtimeMs, uid, gid, size, mode, ino }: Partial<StatsLike> = {}) {
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
this.
|
|
191
|
-
this.
|
|
192
|
-
this.
|
|
193
|
-
this.
|
|
194
|
-
this.
|
|
195
|
-
this.
|
|
196
|
-
this.size = resolveT(size, 0);
|
|
197
|
-
this.ino = resolveT(ino, 0);
|
|
182
|
+
const now = Date.now();
|
|
183
|
+
this.atimeMs = this._convert(atimeMs ?? now);
|
|
184
|
+
this.mtimeMs = this._convert(mtimeMs ?? now);
|
|
185
|
+
this.ctimeMs = this._convert(ctimeMs ?? now);
|
|
186
|
+
this.birthtimeMs = this._convert(birthtimeMs ?? now);
|
|
187
|
+
this.uid = this._convert(uid ?? 0);
|
|
188
|
+
this.gid = this._convert(gid ?? 0);
|
|
189
|
+
this.size = this._convert(size ?? 0);
|
|
190
|
+
this.ino = this._convert(ino ?? 0);
|
|
198
191
|
const itemType: FileType = Number(mode) & S_IFMT || FileType.FILE;
|
|
199
192
|
|
|
200
193
|
if (mode) {
|
|
@@ -209,11 +202,9 @@ export abstract class StatsCommon<T extends number | bigint> implements Node.Sta
|
|
|
209
202
|
this.mode = this._convert(0o777);
|
|
210
203
|
}
|
|
211
204
|
}
|
|
212
|
-
// number of 512B blocks allocated
|
|
213
|
-
this.blocks = this._convert(Math.ceil(Number(size) / 512));
|
|
214
205
|
// Check if mode also includes top-most bits, which indicate the file's type.
|
|
215
206
|
if ((this.mode & S_IFMT) == 0) {
|
|
216
|
-
this.mode =
|
|
207
|
+
this.mode = (this.mode | this._convert(itemType)) as T;
|
|
217
208
|
}
|
|
218
209
|
}
|
|
219
210
|
|
|
@@ -241,19 +232,19 @@ export abstract class StatsCommon<T extends number | bigint> implements Node.Sta
|
|
|
241
232
|
// Currently unsupported
|
|
242
233
|
|
|
243
234
|
public isSocket(): boolean {
|
|
244
|
-
return
|
|
235
|
+
return (this.mode & S_IFMT) === S_IFSOCK;
|
|
245
236
|
}
|
|
246
237
|
|
|
247
238
|
public isBlockDevice(): boolean {
|
|
248
|
-
return
|
|
239
|
+
return (this.mode & S_IFMT) === S_IFBLK;
|
|
249
240
|
}
|
|
250
241
|
|
|
251
242
|
public isCharacterDevice(): boolean {
|
|
252
|
-
return
|
|
243
|
+
return (this.mode & S_IFMT) === S_IFCHR;
|
|
253
244
|
}
|
|
254
245
|
|
|
255
246
|
public isFIFO(): boolean {
|
|
256
|
-
return
|
|
247
|
+
return (this.mode & S_IFMT) === S_IFIFO;
|
|
257
248
|
}
|
|
258
249
|
|
|
259
250
|
/**
|
|
@@ -315,16 +306,16 @@ export abstract class StatsCommon<T extends number | bigint> implements Node.Sta
|
|
|
315
306
|
}
|
|
316
307
|
|
|
317
308
|
public get atimeNs(): bigint {
|
|
318
|
-
return BigInt(this.atimeMs);
|
|
309
|
+
return BigInt(this.atimeMs) * 1000n;
|
|
319
310
|
}
|
|
320
311
|
public get mtimeNs(): bigint {
|
|
321
|
-
return BigInt(this.mtimeMs);
|
|
312
|
+
return BigInt(this.mtimeMs) * 1000n;
|
|
322
313
|
}
|
|
323
314
|
public get ctimeNs(): bigint {
|
|
324
|
-
return BigInt(this.ctimeMs);
|
|
315
|
+
return BigInt(this.ctimeMs) * 1000n;
|
|
325
316
|
}
|
|
326
317
|
public get birthtimeNs(): bigint {
|
|
327
|
-
return BigInt(this.birthtimeMs);
|
|
318
|
+
return BigInt(this.birthtimeMs) * 1000n;
|
|
328
319
|
}
|
|
329
320
|
}
|
|
330
321
|
|
|
@@ -334,41 +325,35 @@ export abstract class StatsCommon<T extends number | bigint> implements Node.Sta
|
|
|
334
325
|
* Attribute descriptions are from `man 2 stat'
|
|
335
326
|
* @see http://nodejs.org/api/fs.html#fs_class_fs_stats
|
|
336
327
|
* @see http://man7.org/linux/man-pages/man2/stat.2.html
|
|
328
|
+
* @internal
|
|
337
329
|
*/
|
|
338
330
|
export class Stats extends StatsCommon<number> implements Node.Stats, StatsLike {
|
|
339
|
-
protected _isBigint = false;
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Clones the stats object.
|
|
343
|
-
* @deprecated use `new Stats(stats)`
|
|
344
|
-
*/
|
|
345
|
-
public static clone(stats: Stats): Stats {
|
|
346
|
-
return new Stats(stats);
|
|
347
|
-
}
|
|
331
|
+
protected _isBigint = false as const;
|
|
348
332
|
}
|
|
349
333
|
Stats satisfies typeof Node.Stats;
|
|
350
334
|
|
|
351
335
|
/**
|
|
352
336
|
* Stats with bigint
|
|
353
337
|
* @todo Implement with bigint instead of wrapping Stats
|
|
338
|
+
* @internal
|
|
354
339
|
*/
|
|
355
340
|
export class BigIntStats extends StatsCommon<bigint> implements Node.BigIntStats, StatsLike {
|
|
356
|
-
protected _isBigint = true;
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* Clone a stats object.
|
|
360
|
-
* @deprecated use `new BigIntStats(stats)`
|
|
361
|
-
*/
|
|
362
|
-
public static clone(stats: BigIntStats | Stats): BigIntStats {
|
|
363
|
-
return new BigIntStats(stats);
|
|
364
|
-
}
|
|
341
|
+
protected _isBigint = true as const;
|
|
365
342
|
}
|
|
366
343
|
|
|
344
|
+
/**
|
|
345
|
+
* @internal
|
|
346
|
+
*/
|
|
347
|
+
export const ZenFsType = 0x7a656e6673; // 'z' 'e' 'n' 'f' 's'
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* @hidden
|
|
351
|
+
*/
|
|
367
352
|
export class StatsFs implements Node.StatsFsBase<number> {
|
|
368
353
|
/** Type of file system. */
|
|
369
|
-
public type: number =
|
|
354
|
+
public type: number = 0x7a656e6673;
|
|
370
355
|
/** Optimal transfer block size. */
|
|
371
|
-
public bsize: number =
|
|
356
|
+
public bsize: number = 4096;
|
|
372
357
|
/** Total data blocks in file system. */
|
|
373
358
|
public blocks: number = 0;
|
|
374
359
|
/** Free blocks in file system. */
|
|
@@ -376,16 +361,19 @@ export class StatsFs implements Node.StatsFsBase<number> {
|
|
|
376
361
|
/** Available blocks for unprivileged users */
|
|
377
362
|
public bavail: number = 0;
|
|
378
363
|
/** Total file nodes in file system. */
|
|
379
|
-
public files: number =
|
|
364
|
+
public files: number = size_max;
|
|
380
365
|
/** Free file nodes in file system. */
|
|
381
|
-
public ffree: number =
|
|
366
|
+
public ffree: number = size_max;
|
|
382
367
|
}
|
|
383
368
|
|
|
369
|
+
/**
|
|
370
|
+
* @hidden
|
|
371
|
+
*/
|
|
384
372
|
export class BigIntStatsFs implements Node.StatsFsBase<bigint> {
|
|
385
373
|
/** Type of file system. */
|
|
386
|
-
public type: bigint =
|
|
374
|
+
public type: bigint = 0x7a656e6673n;
|
|
387
375
|
/** Optimal transfer block size. */
|
|
388
|
-
public bsize: bigint =
|
|
376
|
+
public bsize: bigint = 4096n;
|
|
389
377
|
/** Total data blocks in file system. */
|
|
390
378
|
public blocks: bigint = 0n;
|
|
391
379
|
/** Free blocks in file system. */
|
|
@@ -393,7 +381,7 @@ export class BigIntStatsFs implements Node.StatsFsBase<bigint> {
|
|
|
393
381
|
/** Available blocks for unprivileged users */
|
|
394
382
|
public bavail: bigint = 0n;
|
|
395
383
|
/** Total file nodes in file system. */
|
|
396
|
-
public files: bigint =
|
|
384
|
+
public files: bigint = BigInt(size_max);
|
|
397
385
|
/** Free file nodes in file system. */
|
|
398
|
-
public ffree: bigint =
|
|
386
|
+
public ffree: bigint = BigInt(size_max);
|
|
399
387
|
}
|