@zenfs/core 0.3.4 → 0.4.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.
Files changed (44) hide show
  1. package/dist/FileIndex.d.ts +6 -0
  2. package/dist/FileIndex.js +3 -3
  3. package/dist/backends/AsyncMirror.d.ts +3 -5
  4. package/dist/backends/AsyncMirror.js +7 -6
  5. package/dist/backends/AsyncStore.d.ts +9 -4
  6. package/dist/backends/AsyncStore.js +7 -2
  7. package/dist/backends/Locked.d.ts +8 -8
  8. package/dist/backends/Locked.js +2 -1
  9. package/dist/backends/Overlay.d.ts +13 -1
  10. package/dist/backends/Overlay.js +16 -16
  11. package/dist/backends/SyncStore.d.ts +8 -5
  12. package/dist/backends/SyncStore.js +9 -5
  13. package/dist/backends/backend.js +8 -8
  14. package/dist/browser.min.js +4 -5
  15. package/dist/browser.min.js.map +4 -4
  16. package/dist/cred.d.ts +1 -1
  17. package/dist/cred.js +1 -1
  18. package/dist/emulation/callbacks.d.ts +1 -1
  19. package/dist/emulation/callbacks.js +1 -1
  20. package/dist/emulation/constants.d.ts +48 -42
  21. package/dist/emulation/constants.js +68 -59
  22. package/dist/emulation/dir.d.ts +2 -2
  23. package/dist/emulation/promises.d.ts +1 -1
  24. package/dist/emulation/promises.js +6 -6
  25. package/dist/emulation/sync.d.ts +1 -1
  26. package/dist/emulation/sync.js +7 -7
  27. package/dist/file.d.ts +26 -12
  28. package/dist/file.js +68 -29
  29. package/dist/filesystem.d.ts +3 -3
  30. package/dist/index.d.ts +6 -3
  31. package/dist/index.js +4 -5
  32. package/dist/inode.d.ts +21 -15
  33. package/dist/inode.js +52 -40
  34. package/dist/mutex.d.ts +1 -2
  35. package/dist/mutex.js +1 -1
  36. package/dist/stats.d.ts +70 -18
  37. package/dist/stats.js +12 -18
  38. package/dist/utils.d.ts +3 -8
  39. package/dist/utils.js +60 -39
  40. package/package.json +5 -1
  41. package/readme.md +14 -10
  42. package/scripts/make-index.js +100 -0
  43. package/dist/backends/index.d.ts +0 -10
  44. package/dist/backends/index.js +0 -12
package/dist/file.js CHANGED
@@ -2,6 +2,9 @@ import { ApiError, ErrorCode } from './ApiError.js';
2
2
  import { O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY, S_IFMT } from './emulation/constants.js';
3
3
  import { size_max } from './inode.js';
4
4
  import { Stats } from './stats.js';
5
+ /**
6
+ * @hidden
7
+ */
5
8
  export var ActionType;
6
9
  (function (ActionType) {
7
10
  // Indicates that the code should not do anything.
@@ -38,33 +41,32 @@ export class FileFlag {
38
41
  * @return The FileFlag object representing the flag
39
42
  * @throw when the flag string is invalid
40
43
  */
41
- static FromString(flag) {
44
+ static Get(flag) {
42
45
  // Check cache first.
43
- if (!FileFlag.flagCache.has(flag)) {
44
- FileFlag.flagCache.set(flag, new FileFlag(flag));
46
+ if (!FileFlag.cache.has(flag)) {
47
+ FileFlag.cache.set(flag, new FileFlag(flag));
45
48
  }
46
- return FileFlag.flagCache.get(flag);
49
+ return FileFlag.cache.get(flag);
47
50
  }
48
51
  /**
49
- * This should never be called directly.
50
52
  * @param flag The string or number representing the flag
51
53
  * @throw when the flag is invalid
52
54
  */
53
55
  constructor(flag) {
54
- if (typeof flag === 'number') {
55
- flag = FileFlag.NumberToString(flag);
56
+ if (typeof flag == 'number') {
57
+ flag = FileFlag.StringOf(flag);
56
58
  }
57
- if (FileFlag.validFlagStrs.indexOf(flag) < 0) {
59
+ if (!FileFlag.validStrings.includes(flag)) {
58
60
  throw new ApiError(ErrorCode.EINVAL, 'Invalid flag string: ' + flag);
59
61
  }
60
- this.flagStr = flag;
62
+ this._flag = flag;
61
63
  }
62
64
  /**
63
65
  * @param flag The number representing the flag
64
- * @return The string representing the flag
65
- * @throw when the flag number is invalid
66
+ * @returns The string representing the flag
67
+ * @throws when the flag number is invalid
66
68
  */
67
- static NumberToString(flag) {
69
+ static StringOf(flag) {
68
70
  // based on https://github.com/nodejs/node/blob/abbdc3efaa455e6c907ebef5409ac8b0f222f969/lib/internal/fs/utils.js#L619
69
71
  switch (flag) {
70
72
  case O_RDONLY:
@@ -95,11 +97,46 @@ export class FileFlag {
95
97
  throw new ApiError(ErrorCode.EINVAL, 'Invalid flag number: ' + flag);
96
98
  }
97
99
  }
100
+ /**
101
+ * @param flag The string representing the flag
102
+ * @returns The number representing the flag
103
+ * @throws when the flag string is invalid
104
+ */
105
+ static NumberOf(flag) {
106
+ switch (flag) {
107
+ case 'r':
108
+ return O_RDONLY;
109
+ case 'rs':
110
+ return O_RDONLY | O_SYNC;
111
+ case 'r+':
112
+ return O_RDWR;
113
+ case 'rs+':
114
+ return O_RDWR | O_SYNC;
115
+ case 'w':
116
+ return O_TRUNC | O_CREAT | O_WRONLY;
117
+ case 'wx':
118
+ return O_TRUNC | O_CREAT | O_WRONLY | O_EXCL;
119
+ case 'w+':
120
+ return O_TRUNC | O_CREAT | O_RDWR;
121
+ case 'wx+':
122
+ return O_TRUNC | O_CREAT | O_RDWR | O_EXCL;
123
+ case 'a':
124
+ return O_APPEND | O_CREAT | O_WRONLY;
125
+ case 'ax':
126
+ return O_APPEND | O_CREAT | O_WRONLY | O_EXCL;
127
+ case 'a+':
128
+ return O_APPEND | O_CREAT | O_RDWR;
129
+ case 'ax+':
130
+ return O_APPEND | O_CREAT | O_RDWR | O_EXCL;
131
+ default:
132
+ throw new ApiError(ErrorCode.EINVAL, 'Invalid flag string: ' + flag);
133
+ }
134
+ }
98
135
  /**
99
136
  * Get the underlying flag string for this flag.
100
137
  */
101
138
  toString() {
102
- return this.flagStr;
139
+ return this._flag;
103
140
  }
104
141
  /**
105
142
  * Get the equivalent mode (0b0xxx: read, write, execute)
@@ -118,37 +155,37 @@ export class FileFlag {
118
155
  * Returns true if the file is readable.
119
156
  */
120
157
  isReadable() {
121
- return this.flagStr.indexOf('r') !== -1 || this.flagStr.indexOf('+') !== -1;
158
+ return this._flag.indexOf('r') != -1 || this._flag.indexOf('+') != -1;
122
159
  }
123
160
  /**
124
161
  * Returns true if the file is writeable.
125
162
  */
126
163
  isWriteable() {
127
- return this.flagStr.indexOf('w') !== -1 || this.flagStr.indexOf('a') !== -1 || this.flagStr.indexOf('+') !== -1;
164
+ return this._flag.indexOf('w') != -1 || this._flag.indexOf('a') != -1 || this._flag.indexOf('+') != -1;
128
165
  }
129
166
  /**
130
167
  * Returns true if the file mode should truncate.
131
168
  */
132
169
  isTruncating() {
133
- return this.flagStr.indexOf('w') !== -1;
170
+ return this._flag.indexOf('w') !== -1;
134
171
  }
135
172
  /**
136
173
  * Returns true if the file is appendable.
137
174
  */
138
175
  isAppendable() {
139
- return this.flagStr.indexOf('a') !== -1;
176
+ return this._flag.indexOf('a') !== -1;
140
177
  }
141
178
  /**
142
179
  * Returns true if the file is open in synchronous mode.
143
180
  */
144
181
  isSynchronous() {
145
- return this.flagStr.indexOf('s') !== -1;
182
+ return this._flag.indexOf('s') !== -1;
146
183
  }
147
184
  /**
148
185
  * Returns true if the file is open in exclusive mode.
149
186
  */
150
187
  isExclusive() {
151
- return this.flagStr.indexOf('x') !== -1;
188
+ return this._flag.indexOf('x') !== -1;
152
189
  }
153
190
  /**
154
191
  * Returns one of the static fields on this object that indicates the
@@ -168,18 +205,20 @@ export class FileFlag {
168
205
  * appropriate response to the path not existing.
169
206
  */
170
207
  pathNotExistsAction() {
171
- if ((this.isWriteable() || this.isAppendable()) && this.flagStr !== 'r+') {
208
+ if ((this.isWriteable() || this.isAppendable()) && this._flag != 'r+') {
172
209
  return ActionType.CREATE;
173
210
  }
174
- else {
175
- return ActionType.THROW;
176
- }
211
+ return ActionType.THROW;
177
212
  }
178
213
  }
179
- // Contains cached FileMode instances.
180
- FileFlag.flagCache = new Map();
181
- // Array of valid mode strings.
182
- FileFlag.validFlagStrs = ['r', 'r+', 'rs', 'rs+', 'w', 'wx', 'w+', 'wx+', 'a', 'ax', 'a+', 'ax+'];
214
+ /**
215
+ * Contains cached FileMode instances.
216
+ */
217
+ FileFlag.cache = new Map();
218
+ /**
219
+ * Array of valid mode strings.
220
+ */
221
+ FileFlag.validStrings = ['r', 'r+', 'rs', 'rs+', 'w', 'wx', 'w+', 'wx+', 'a', 'ax', 'a+', 'ax+'];
183
222
  export class File {
184
223
  /**
185
224
  * Asynchronous `datasync`.
@@ -282,13 +321,13 @@ export class PreloadFile extends File {
282
321
  * Asynchronous `stat`.
283
322
  */
284
323
  async stat() {
285
- return Stats.clone(this.stats);
324
+ return new Stats(this.stats);
286
325
  }
287
326
  /**
288
327
  * Synchronous `stat`.
289
328
  */
290
329
  statSync() {
291
- return Stats.clone(this.stats);
330
+ return new Stats(this.stats);
292
331
  }
293
332
  /**
294
333
  * Asynchronous truncate.
@@ -1,7 +1,7 @@
1
1
  import { ApiError } from './ApiError.js';
2
- import { Stats } from './stats.js';
3
- import { File, FileFlag } from './file.js';
4
- import { Cred } from './cred.js';
2
+ import type { Stats } from './stats.js';
3
+ import type { File, FileFlag } from './file.js';
4
+ import type { Cred } from './cred.js';
5
5
  export type NoArgCallback = (e?: ApiError) => unknown;
6
6
  export type TwoArgCallback<T> = (e?: ApiError, rv?: T) => unknown;
7
7
  export type ThreeArgCallback<T, U> = (e?: ApiError, arg1?: T, arg2?: U) => unknown;
package/dist/index.d.ts CHANGED
@@ -3,7 +3,6 @@
3
3
  */
4
4
  import * as fs from './emulation/index.js';
5
5
  import { FileSystem } from './filesystem.js';
6
- import { backends } from './backends/index.js';
7
6
  import { type Backend, type BackendConfig } from './backends/backend.js';
8
7
  /**
9
8
  * Initializes ZenFS with the given file systems.
@@ -15,7 +14,7 @@ export declare function initialize(mounts: {
15
14
  * Defines a mapping of mount points to their configurations
16
15
  */
17
16
  export interface ConfigMapping {
18
- [mountPoint: string]: FileSystem | BackendConfig | keyof typeof backends | Backend;
17
+ [mountPoint: string]: FileSystem | BackendConfig | Backend;
19
18
  }
20
19
  /**
21
20
  * A configuration for ZenFS
@@ -26,8 +25,12 @@ export type Configuration = FileSystem | BackendConfig | ConfigMapping;
26
25
  * See the Configuration type for more info on the configuration object.
27
26
  */
28
27
  export declare function configure(config: Configuration): Promise<void>;
29
- export * from './backends/index.js';
28
+ export type { Backend, BackendConfig } from './backends/backend.js';
29
+ export * from './backends/AsyncMirror.js';
30
30
  export * from './backends/AsyncStore.js';
31
+ export * from './backends/InMemory.js';
32
+ export * from './backends/Locked.js';
33
+ export * from './backends/Overlay.js';
31
34
  export * from './backends/SyncStore.js';
32
35
  export * from './ApiError.js';
33
36
  export * from './cred.js';
package/dist/index.js CHANGED
@@ -3,7 +3,6 @@
3
3
  */
4
4
  import * as fs from './emulation/index.js';
5
5
  import { FileSystem } from './filesystem.js';
6
- import { backends } from './backends/index.js';
7
6
  import { Cred } from './cred.js';
8
7
  import { isBackend, resolveBackendConfig } from './backends/backend.js';
9
8
  import { setCred } from './emulation/shared.js';
@@ -31,9 +30,6 @@ export async function configure(config) {
31
30
  if (value instanceof FileSystem) {
32
31
  continue;
33
32
  }
34
- if (typeof value == 'string') {
35
- value = { backend: backends[value] };
36
- }
37
33
  if (isBackend(value)) {
38
34
  value = { backend: value };
39
35
  }
@@ -41,8 +37,11 @@ export async function configure(config) {
41
37
  }
42
38
  initialize(config);
43
39
  }
44
- export * from './backends/index.js';
40
+ export * from './backends/AsyncMirror.js';
45
41
  export * from './backends/AsyncStore.js';
42
+ export * from './backends/InMemory.js';
43
+ export * from './backends/Locked.js';
44
+ export * from './backends/Overlay.js';
46
45
  export * from './backends/SyncStore.js';
47
46
  export * from './ApiError.js';
48
47
  export * from './cred.js';
package/dist/inode.d.ts CHANGED
@@ -1,20 +1,28 @@
1
- import { Stats } from './stats.js';
1
+ import { Stats, type StatsLike } from './stats.js';
2
+ /**
3
+ * Alias for an ino.
4
+ * This will be helpful if in the future inode numbers/IDs are changed to strings or numbers.
5
+ */
2
6
  export type Ino = bigint;
7
+ /**
8
+ * Max 32-bit integer
9
+ * @hidden
10
+ */
3
11
  export declare const size_max: number;
4
12
  /**
5
- * @internal
13
+ * Room inode
14
+ * @hidden
6
15
  */
7
16
  export declare const rootIno: Ino;
8
17
  /**
9
- * Generate 4 random bits at a time
10
- *
18
+ * Generate a random ino
11
19
  * @internal
12
20
  */
13
21
  export declare function randomIno(): Ino;
14
22
  /**
15
23
  * Generic inode definition that can easily be serialized.
16
24
  */
17
- export declare class Inode {
25
+ export declare class Inode implements StatsLike {
18
26
  readonly buffer: ArrayBufferLike;
19
27
  get data(): Uint8Array;
20
28
  protected view: DataView;
@@ -31,20 +39,18 @@ export declare class Inode {
31
39
  set uid(value: number);
32
40
  get gid(): number;
33
41
  set gid(value: number);
34
- get atime(): number;
35
- set atime(value: number);
36
- get mtime(): number;
37
- set mtime(value: number);
38
- get ctime(): number;
39
- set ctime(value: number);
42
+ get atimeMs(): number;
43
+ set atimeMs(value: number);
44
+ get birthtimeMs(): number;
45
+ set birthtimeMs(value: number);
46
+ get mtimeMs(): number;
47
+ set mtimeMs(value: number);
48
+ get ctimeMs(): number;
49
+ set ctimeMs(value: number);
40
50
  /**
41
51
  * Handy function that converts the Inode to a Node Stats object.
42
52
  */
43
53
  toStats(): Stats;
44
- /**
45
- * Get the size of this Inode, in bytes.
46
- */
47
- sizeof(): number;
48
54
  /**
49
55
  * Updates the Inode using information from the stats object. Used by file
50
56
  * systems at sync time, e.g.:
package/dist/inode.js CHANGED
@@ -1,20 +1,12 @@
1
- import { S_IFMT } from './emulation/constants.js';
2
- import { Stats, FileType } from './stats.js';
3
- var Offset;
4
- (function (Offset) {
5
- Offset[Offset["ino"] = 0] = "ino";
6
- Offset[Offset["size"] = 8] = "size";
7
- Offset[Offset["mode"] = 12] = "mode";
8
- Offset[Offset["nlink"] = 14] = "nlink";
9
- Offset[Offset["uid"] = 18] = "uid";
10
- Offset[Offset["gid"] = 22] = "gid";
11
- Offset[Offset["atime"] = 26] = "atime";
12
- Offset[Offset["mtime"] = 34] = "mtime";
13
- Offset[Offset["ctime"] = 42] = "ctime";
14
- })(Offset || (Offset = {}));
1
+ import { Stats } from './stats.js';
2
+ /**
3
+ * Max 32-bit integer
4
+ * @hidden
5
+ */
15
6
  export const size_max = 2 ** 32 - 1;
16
7
  /**
17
- * @internal
8
+ * Room inode
9
+ * @hidden
18
10
  */
19
11
  export const rootIno = 0n;
20
12
  /**
@@ -24,13 +16,29 @@ function _random() {
24
16
  return Math.round(Math.random() * 2 ** 32).toString(16);
25
17
  }
26
18
  /**
27
- * Generate 4 random bits at a time
28
- *
19
+ * Generate a random ino
29
20
  * @internal
30
21
  */
31
22
  export function randomIno() {
32
23
  return BigInt('0x' + _random() + _random());
33
24
  }
25
+ /**
26
+ * Offsets for inode members
27
+ */
28
+ var Offset;
29
+ (function (Offset) {
30
+ Offset[Offset["ino"] = 0] = "ino";
31
+ Offset[Offset["size"] = 8] = "size";
32
+ Offset[Offset["mode"] = 12] = "mode";
33
+ Offset[Offset["nlink"] = 14] = "nlink";
34
+ Offset[Offset["uid"] = 18] = "uid";
35
+ Offset[Offset["gid"] = 22] = "gid";
36
+ Offset[Offset["atime"] = 26] = "atime";
37
+ Offset[Offset["birthtime"] = 34] = "birthtime";
38
+ Offset[Offset["mtime"] = 42] = "mtime";
39
+ Offset[Offset["ctime"] = 50] = "ctime";
40
+ Offset[Offset["end"] = 58] = "end";
41
+ })(Offset || (Offset = {}));
34
42
  /**
35
43
  * Generic inode definition that can easily be serialized.
36
44
  */
@@ -40,7 +48,10 @@ export class Inode {
40
48
  }
41
49
  constructor(buffer) {
42
50
  const setDefaults = !buffer;
43
- buffer ?? (buffer = new ArrayBuffer(50));
51
+ buffer ?? (buffer = new ArrayBuffer(Offset.end));
52
+ if (buffer?.byteLength < Offset.end) {
53
+ throw new RangeError(`Can not create an inode from a buffer less than ${Offset.end} bytes`);
54
+ }
44
55
  this.view = new DataView(buffer);
45
56
  this.buffer = buffer;
46
57
  if (!setDefaults) {
@@ -51,9 +62,10 @@ export class Inode {
51
62
  this.nlink = 1;
52
63
  this.size = 4096;
53
64
  const now = Date.now();
54
- this.atime = now;
55
- this.mtime = now;
56
- this.ctime = now;
65
+ this.atimeMs = now;
66
+ this.mtimeMs = now;
67
+ this.ctimeMs = now;
68
+ this.birthtimeMs = now;
57
69
  }
58
70
  get ino() {
59
71
  return this.view.getBigUint64(Offset.ino, true);
@@ -91,35 +103,35 @@ export class Inode {
91
103
  set gid(value) {
92
104
  this.view.setUint32(Offset.gid, value, true);
93
105
  }
94
- get atime() {
106
+ get atimeMs() {
95
107
  return this.view.getFloat64(Offset.atime, true);
96
108
  }
97
- set atime(value) {
109
+ set atimeMs(value) {
98
110
  this.view.setFloat64(Offset.atime, value, true);
99
111
  }
100
- get mtime() {
112
+ get birthtimeMs() {
113
+ return this.view.getFloat64(Offset.birthtime, true);
114
+ }
115
+ set birthtimeMs(value) {
116
+ this.view.setFloat64(Offset.birthtime, value, true);
117
+ }
118
+ get mtimeMs() {
101
119
  return this.view.getFloat64(Offset.mtime, true);
102
120
  }
103
- set mtime(value) {
121
+ set mtimeMs(value) {
104
122
  this.view.setFloat64(Offset.mtime, value, true);
105
123
  }
106
- get ctime() {
124
+ get ctimeMs() {
107
125
  return this.view.getFloat64(Offset.ctime, true);
108
126
  }
109
- set ctime(value) {
127
+ set ctimeMs(value) {
110
128
  this.view.setFloat64(Offset.ctime, value, true);
111
129
  }
112
130
  /**
113
131
  * Handy function that converts the Inode to a Node Stats object.
114
132
  */
115
133
  toStats() {
116
- return new Stats((this.mode & S_IFMT) === FileType.DIRECTORY ? FileType.DIRECTORY : FileType.FILE, this.size, this.mode, this.atime, this.mtime, this.ctime, this.uid, this.gid);
117
- }
118
- /**
119
- * Get the size of this Inode, in bytes.
120
- */
121
- sizeof() {
122
- return this.buffer.byteLength;
134
+ return new Stats(this);
123
135
  }
124
136
  /**
125
137
  * Updates the Inode using information from the stats object. Used by file
@@ -153,16 +165,16 @@ export class Inode {
153
165
  this.uid = stats.uid;
154
166
  hasChanged = true;
155
167
  }
156
- if (this.atime !== stats.atimeMs) {
157
- this.atime = stats.atimeMs;
168
+ if (this.atimeMs !== stats.atimeMs) {
169
+ this.atimeMs = stats.atimeMs;
158
170
  hasChanged = true;
159
171
  }
160
- if (this.mtime !== stats.mtimeMs) {
161
- this.mtime = stats.mtimeMs;
172
+ if (this.mtimeMs !== stats.mtimeMs) {
173
+ this.mtimeMs = stats.mtimeMs;
162
174
  hasChanged = true;
163
175
  }
164
- if (this.ctime !== stats.ctimeMs) {
165
- this.ctime = stats.ctimeMs;
176
+ if (this.ctimeMs !== stats.ctimeMs) {
177
+ this.ctimeMs = stats.ctimeMs;
166
178
  hasChanged = true;
167
179
  }
168
180
  return hasChanged;
package/dist/mutex.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- export type MutexCallback = () => void;
2
1
  /**
3
2
  * Non-recursive mutex
4
3
  * @internal
5
4
  */
6
- export default class Mutex {
5
+ export declare class Mutex {
7
6
  private _locks;
8
7
  lock(path: string): Promise<void>;
9
8
  unlock(path: string): void;
package/dist/mutex.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * Non-recursive mutex
3
3
  * @internal
4
4
  */
5
- export default class Mutex {
5
+ export class Mutex {
6
6
  constructor() {
7
7
  this._locks = new Map();
8
8
  }
package/dist/stats.d.ts CHANGED
@@ -10,14 +10,58 @@ export declare enum FileType {
10
10
  SYMLINK
11
11
  }
12
12
  /**
13
- * Common code used by both Stats and BigIntStats
13
+ *
14
+ */
15
+ export interface StatsLike {
16
+ /**
17
+ * Size of the item in bytes.
18
+ * For directories/symlinks, this is normally the size of the struct that represents the item.
19
+ */
20
+ size: number | bigint;
21
+ /**
22
+ * Unix-style file mode (e.g. 0o644) that includes the item type
23
+ * Type of the item can be FILE, DIRECTORY, SYMLINK, or SOCKET
24
+ */
25
+ mode: number | bigint;
26
+ /**
27
+ * time of last access, in milliseconds since epoch
28
+ */
29
+ atimeMs: number | bigint;
30
+ /**
31
+ * time of last modification, in milliseconds since epoch
32
+ */
33
+ mtimeMs: number | bigint;
34
+ /**
35
+ * time of last time file status was changed, in milliseconds since epoch
36
+ */
37
+ ctimeMs: number | bigint;
38
+ /**
39
+ * time of file creation, in milliseconds since epoch
40
+ */
41
+ birthtimeMs: number | bigint;
42
+ /**
43
+ * the id of the user that owns the file
44
+ */
45
+ uid: number | bigint;
46
+ /**
47
+ * the id of the group that owns the file
48
+ */
49
+ gid: number | bigint;
50
+ }
51
+ /**
52
+ * Provides information about a particular entry in the file system.
53
+ * Common code used by both Stats and BigIntStats.
14
54
  */
15
- export declare abstract class StatsCommon<T extends number | bigint> implements Node.StatsBase<T> {
55
+ export declare abstract class StatsCommon<T extends number | bigint> implements Node.StatsBase<T>, StatsLike {
16
56
  protected abstract _isBigint: boolean;
17
57
  protected get _typename(): string;
18
58
  protected get _typename_inverse(): string;
19
59
  protected _convert(arg: number | bigint | string | boolean): T;
20
60
  blocks: T;
61
+ /**
62
+ * Unix-style file mode (e.g. 0o644) that includes the type of the item.
63
+ * Type of the item can be FILE, DIRECTORY, SYMLINK, or SOCKET
64
+ */
21
65
  mode: T;
22
66
  /**
23
67
  * ID of device containing file
@@ -51,33 +95,39 @@ export declare abstract class StatsCommon<T extends number | bigint> implements
51
95
  * Some file systems stash data on stats objects.
52
96
  */
53
97
  fileData?: Uint8Array;
98
+ /**
99
+ * time of last access, in milliseconds since epoch
100
+ */
54
101
  atimeMs: T;
55
102
  get atime(): Date;
56
103
  set atime(value: Date);
104
+ /**
105
+ * time of last modification, in milliseconds since epoch
106
+ */
57
107
  mtimeMs: T;
58
108
  get mtime(): Date;
59
109
  set mtime(value: Date);
110
+ /**
111
+ * time of last time file status was changed, in milliseconds since epoch
112
+ */
60
113
  ctimeMs: T;
61
114
  get ctime(): Date;
62
115
  set ctime(value: Date);
116
+ /**
117
+ * time of file creation, in milliseconds since epoch
118
+ */
63
119
  birthtimeMs: T;
64
120
  get birthtime(): Date;
65
121
  set birthtime(value: Date);
122
+ /**
123
+ * Size of the item in bytes.
124
+ * For directories/symlinks, this is normally the size of the struct that represents the item.
125
+ */
66
126
  size: T;
67
127
  /**
68
- * Provides information about a particular entry in the file system.
69
- * @param itemType Type of the item (FILE, DIRECTORY, SYMLINK, or SOCKET)
70
- * @param size Size of the item in bytes. For directories/symlinks,
71
- * this is normally the size of the struct that represents the item.
72
- * @param mode Unix-style file mode (e.g. 0o644)
73
- * @param atimeMs time of last access, in milliseconds since epoch
74
- * @param mtimeMs time of last modification, in milliseconds since epoch
75
- * @param ctimeMs time of last time file status was changed, in milliseconds since epoch
76
- * @param uid the id of the user that owns the file
77
- * @param gid the id of the group that owns the file
78
- * @param birthtimeMs time of file creation, in milliseconds since epoch
128
+ * Creates a new stats instance from a stats-like object. Can be used to copy stats (note)
79
129
  */
80
- constructor(itemType?: FileType, size?: number | bigint, mode?: number | bigint, atimeMs?: number | bigint, mtimeMs?: number | bigint, ctimeMs?: number | bigint, uid?: number | bigint, gid?: number | bigint, birthtimeMs?: number | bigint);
130
+ constructor({ atimeMs, mtimeMs, ctimeMs, birthtimeMs, uid, gid, size, mode }?: Partial<StatsLike>);
81
131
  /**
82
132
  * @returns true if this item is a file.
83
133
  */
@@ -128,18 +178,19 @@ export declare abstract class StatsCommon<T extends number | bigint> implements
128
178
  * @see http://nodejs.org/api/fs.html#fs_class_fs_stats
129
179
  * @see http://man7.org/linux/man-pages/man2/stat.2.html
130
180
  */
131
- export declare class Stats extends StatsCommon<number> implements Node.Stats {
181
+ export declare class Stats extends StatsCommon<number> implements Node.Stats, StatsLike {
132
182
  protected _isBigint: boolean;
133
183
  /**
134
184
  * Clones the stats object.
185
+ * @deprecated use `new Stats(stats)`
135
186
  */
136
- static clone(s: Stats): Stats;
187
+ static clone(stats: Stats): Stats;
137
188
  }
138
189
  /**
139
190
  * Stats with bigint
140
191
  * @todo Implement with bigint instead of wrapping Stats
141
192
  */
142
- export declare class BigIntStats extends StatsCommon<bigint> implements Node.BigIntStats {
193
+ export declare class BigIntStats extends StatsCommon<bigint> implements Node.BigIntStats, StatsLike {
143
194
  protected _isBigint: boolean;
144
195
  atimeNs: bigint;
145
196
  mtimeNs: bigint;
@@ -147,6 +198,7 @@ export declare class BigIntStats extends StatsCommon<bigint> implements Node.Big
147
198
  birthtimeNs: bigint;
148
199
  /**
149
200
  * Clone a stats object.
201
+ * @deprecated use `new BigIntStats(stats)`
150
202
  */
151
- static clone(s: BigIntStats | Stats): BigIntStats;
203
+ static clone(stats: BigIntStats | Stats): BigIntStats;
152
204
  }