@zenfs/core 0.7.10 → 0.8.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.
@@ -2,8 +2,9 @@
2
2
  /// <reference types="node" resolution-mode="require"/>
3
3
  /// <reference types="node" resolution-mode="require"/>
4
4
  import type * as Node from 'fs';
5
- import { FileContents, NoArgCallback, ThreeArgCallback, TwoArgCallback } from '../filesystem.js';
5
+ import type { FileContents } from '../filesystem.js';
6
6
  import { BigIntStats, type BigIntStatsFs, type Stats, type StatsFs } from '../stats.js';
7
+ import type { Callback } from '../utils.js';
7
8
  import { Dirent, type Dir } from './dir.js';
8
9
  import { PathLike } from './shared.js';
9
10
  import { ReadStream, WriteStream } from './streams.js';
@@ -14,7 +15,7 @@ import { ReadStream, WriteStream } from './streams.js';
14
15
  * @param newPath
15
16
  * @param callback
16
17
  */
17
- export declare function rename(oldPath: PathLike, newPath: PathLike, cb?: NoArgCallback): void;
18
+ export declare function rename(oldPath: PathLike, newPath: PathLike, cb?: Callback): void;
18
19
  /**
19
20
  * Test whether or not the given path exists by checking with the file system.
20
21
  * Then call the callback argument with either true or false.
@@ -28,14 +29,14 @@ export declare function exists(path: PathLike, cb?: (exists: boolean) => unknown
28
29
  * @param path
29
30
  * @param callback
30
31
  */
31
- export declare function stat(path: PathLike, callback: TwoArgCallback<Stats>): void;
32
- export declare function stat(path: PathLike, options: Node.StatOptions & {
32
+ export declare function stat(path: PathLike, callback: Callback<[Stats]>): void;
33
+ export declare function stat(path: PathLike, options: {
33
34
  bigint?: false;
34
- }, callback: TwoArgCallback<Stats>): void;
35
- export declare function stat(path: PathLike, options: Node.StatOptions & {
35
+ }, callback: Callback<[Stats]>): void;
36
+ export declare function stat(path: PathLike, options: {
36
37
  bigint: true;
37
- }, callback: TwoArgCallback<BigIntStats>): void;
38
- export declare function stat(path: PathLike, options: Node.StatOptions, callback: TwoArgCallback<Stats | BigIntStats>): void;
38
+ }, callback: Callback<[BigIntStats]>): void;
39
+ export declare function stat(path: PathLike, options: Node.StatOptions, callback: Callback<[Stats] | [BigIntStats]>): void;
39
40
  /**
40
41
  * Asynchronous `lstat`.
41
42
  * `lstat()` is identical to `stat()`, except that if path is a symbolic link,
@@ -43,28 +44,28 @@ export declare function stat(path: PathLike, options: Node.StatOptions, callback
43
44
  * @param path
44
45
  * @param callback
45
46
  */
46
- export declare function lstat(path: PathLike, callback: TwoArgCallback<Stats>): void;
47
+ export declare function lstat(path: PathLike, callback: Callback<[Stats]>): void;
47
48
  export declare function lstat(path: PathLike, options: Node.StatOptions & {
48
49
  bigint?: false;
49
- }, callback: TwoArgCallback<Stats>): void;
50
+ }, callback: Callback<[Stats]>): void;
50
51
  export declare function lstat(path: PathLike, options: Node.StatOptions & {
51
52
  bigint: true;
52
- }, callback: TwoArgCallback<BigIntStats>): void;
53
- export declare function lstat(path: PathLike, options: Node.StatOptions, callback: TwoArgCallback<Stats | BigIntStats>): void;
53
+ }, callback: Callback<[BigIntStats]>): void;
54
+ export declare function lstat(path: PathLike, options: Node.StatOptions, callback: Callback<[Stats | BigIntStats]>): void;
54
55
  /**
55
56
  * Asynchronous `truncate`.
56
57
  * @param path
57
58
  * @param len
58
59
  * @param callback
59
60
  */
60
- export declare function truncate(path: PathLike, cb?: NoArgCallback): void;
61
- export declare function truncate(path: PathLike, len: number, cb?: NoArgCallback): void;
61
+ export declare function truncate(path: PathLike, cb?: Callback): void;
62
+ export declare function truncate(path: PathLike, len: number, cb?: Callback): void;
62
63
  /**
63
64
  * Asynchronous `unlink`.
64
65
  * @param path
65
66
  * @param callback
66
67
  */
67
- export declare function unlink(path: PathLike, cb?: NoArgCallback): void;
68
+ export declare function unlink(path: PathLike, cb?: Callback): void;
68
69
  /**
69
70
  * Asynchronous file open.
70
71
  * Exclusive mode ensures that path is newly created.
@@ -90,8 +91,8 @@ export declare function unlink(path: PathLike, cb?: NoArgCallback): void;
90
91
  * @param mode defaults to `0644`
91
92
  * @param callback
92
93
  */
93
- export declare function open(path: PathLike, flag: string, cb?: TwoArgCallback<number>): void;
94
- export declare function open(path: PathLike, flag: string, mode: number | string, cb?: TwoArgCallback<number>): void;
94
+ export declare function open(path: PathLike, flag: string, cb?: Callback<[number]>): void;
95
+ export declare function open(path: PathLike, flag: string, mode: number | string, cb?: Callback<[number]>): void;
95
96
  /**
96
97
  * Asynchronously reads the entire contents of a file.
97
98
  * @param filename
@@ -100,14 +101,14 @@ export declare function open(path: PathLike, flag: string, mode: number | string
100
101
  * @option options flag Defaults to `'r'`.
101
102
  * @param callback If no encoding is specified, then the raw buffer is returned.
102
103
  */
103
- export declare function readFile(filename: PathLike, cb: TwoArgCallback<Uint8Array>): void;
104
+ export declare function readFile(filename: PathLike, cb: Callback<[Uint8Array]>): void;
104
105
  export declare function readFile(filename: PathLike, options: {
105
106
  flag?: string;
106
- }, callback?: TwoArgCallback<Uint8Array>): void;
107
+ }, callback?: Callback<[Uint8Array]>): void;
107
108
  export declare function readFile(filename: PathLike, options: {
108
109
  encoding: BufferEncoding;
109
110
  flag?: string;
110
- } | BufferEncoding, cb: TwoArgCallback<string>): void;
111
+ } | BufferEncoding, cb: Callback<[string]>): void;
111
112
  /**
112
113
  * Asynchronously writes data to a file, replacing the file if it already
113
114
  * exists.
@@ -122,9 +123,9 @@ export declare function readFile(filename: PathLike, options: {
122
123
  * @option flag Defaults to `'w'`.
123
124
  * @param callback
124
125
  */
125
- export declare function writeFile(filename: PathLike, data: FileContents, cb?: NoArgCallback): void;
126
- export declare function writeFile(filename: PathLike, data: FileContents, encoding?: BufferEncoding, cb?: NoArgCallback): void;
127
- export declare function writeFile(filename: PathLike, data: FileContents, options?: Node.WriteFileOptions, cb?: NoArgCallback): void;
126
+ export declare function writeFile(filename: PathLike, data: FileContents, cb?: Callback): void;
127
+ export declare function writeFile(filename: PathLike, data: FileContents, encoding?: BufferEncoding, cb?: Callback): void;
128
+ export declare function writeFile(filename: PathLike, data: FileContents, options?: Node.WriteFileOptions, cb?: Callback): void;
128
129
  /**
129
130
  * Asynchronously append data to a file, creating the file if it not yet
130
131
  * exists.
@@ -137,13 +138,13 @@ export declare function writeFile(filename: PathLike, data: FileContents, option
137
138
  * @option flag Defaults to `'a'`.
138
139
  * @param callback
139
140
  */
140
- export declare function appendFile(filename: PathLike, data: FileContents, cb?: NoArgCallback): void;
141
+ export declare function appendFile(filename: PathLike, data: FileContents, cb?: Callback): void;
141
142
  export declare function appendFile(filename: PathLike, data: FileContents, options?: {
142
143
  encoding?: string;
143
144
  mode?: number | string;
144
145
  flag?: string;
145
- }, cb?: NoArgCallback): void;
146
- export declare function appendFile(filename: PathLike, data: FileContents, encoding?: string, cb?: NoArgCallback): void;
146
+ }, cb?: Callback): void;
147
+ export declare function appendFile(filename: PathLike, data: FileContents, encoding?: string, cb?: Callback): void;
147
148
  /**
148
149
  * Asynchronous `fstat`.
149
150
  * `fstat()` is identical to `stat()`, except that the file to be stat-ed is
@@ -151,39 +152,39 @@ export declare function appendFile(filename: PathLike, data: FileContents, encod
151
152
  * @param fd
152
153
  * @param callback
153
154
  */
154
- export declare function fstat(fd: number, cb: TwoArgCallback<Stats>): void;
155
+ export declare function fstat(fd: number, cb: Callback<[Stats]>): void;
155
156
  export declare function fstat(fd: number, options: Node.StatOptions & {
156
157
  bigint?: false;
157
- }, cb: TwoArgCallback<Stats>): void;
158
+ }, cb: Callback<[Stats]>): void;
158
159
  export declare function fstat(fd: number, options: Node.StatOptions & {
159
160
  bigint: true;
160
- }, cb: TwoArgCallback<BigIntStats>): void;
161
+ }, cb: Callback<[BigIntStats]>): void;
161
162
  /**
162
163
  * Asynchronous close.
163
164
  * @param fd
164
165
  * @param callback
165
166
  */
166
- export declare function close(fd: number, cb?: NoArgCallback): void;
167
+ export declare function close(fd: number, cb?: Callback): void;
167
168
  /**
168
169
  * Asynchronous ftruncate.
169
170
  * @param fd
170
171
  * @param len
171
172
  * @param callback
172
173
  */
173
- export declare function ftruncate(fd: number, cb?: NoArgCallback): void;
174
- export declare function ftruncate(fd: number, len?: number, cb?: NoArgCallback): void;
174
+ export declare function ftruncate(fd: number, cb?: Callback): void;
175
+ export declare function ftruncate(fd: number, len?: number, cb?: Callback): void;
175
176
  /**
176
177
  * Asynchronous fsync.
177
178
  * @param fd
178
179
  * @param callback
179
180
  */
180
- export declare function fsync(fd: number, cb?: NoArgCallback): void;
181
+ export declare function fsync(fd: number, cb?: Callback): void;
181
182
  /**
182
183
  * Asynchronous fdatasync.
183
184
  * @param fd
184
185
  * @param callback
185
186
  */
186
- export declare function fdatasync(fd: number, cb?: NoArgCallback): void;
187
+ export declare function fdatasync(fd: number, cb?: Callback): void;
187
188
  /**
188
189
  * Write buffer to the file specified by `fd`.
189
190
  * Note that it is unsafe to use fs.write multiple times on the same file
@@ -198,11 +199,11 @@ export declare function fdatasync(fd: number, cb?: NoArgCallback): void;
198
199
  * the current position.
199
200
  * @param callback The number specifies the number of bytes written into the file.
200
201
  */
201
- export declare function write(fd: number, buffer: Uint8Array, offset: number, length: number, cb?: ThreeArgCallback<number, Uint8Array>): void;
202
- export declare function write(fd: number, buffer: Uint8Array, offset: number, length: number, position?: number, cb?: ThreeArgCallback<number, Uint8Array>): void;
203
- export declare function write(fd: number, data: FileContents, cb?: ThreeArgCallback<number, string>): void;
204
- export declare function write(fd: number, data: FileContents, position?: number, cb?: ThreeArgCallback<number, string>): void;
205
- export declare function write(fd: number, data: FileContents, position: number | null, encoding: BufferEncoding, cb?: ThreeArgCallback<number, string>): void;
202
+ export declare function write(fd: number, buffer: Uint8Array, offset: number, length: number, cb?: Callback<[number, Uint8Array]>): void;
203
+ export declare function write(fd: number, buffer: Uint8Array, offset: number, length: number, position?: number, cb?: Callback<[number, Uint8Array]>): void;
204
+ export declare function write(fd: number, data: FileContents, cb?: Callback<[number, string]>): void;
205
+ export declare function write(fd: number, data: FileContents, position?: number, cb?: Callback<[number, string]>): void;
206
+ export declare function write(fd: number, data: FileContents, position: number | null, encoding: BufferEncoding, cb?: Callback<[number, string]>): void;
206
207
  /**
207
208
  * Read data from the file specified by `fd`.
208
209
  * @param buffer The buffer that the data will be
@@ -215,7 +216,7 @@ export declare function write(fd: number, data: FileContents, position: number |
215
216
  * position.
216
217
  * @param callback The number is the number of bytes read
217
218
  */
218
- export declare function read(fd: number, buffer: Uint8Array, offset: number, length: number, position?: number, cb?: ThreeArgCallback<number, Uint8Array>): void;
219
+ export declare function read(fd: number, buffer: Uint8Array, offset: number, length: number, position?: number, cb?: Callback<[number, Uint8Array]>): void;
219
220
  /**
220
221
  * Asynchronous `fchown`.
221
222
  * @param fd
@@ -223,14 +224,14 @@ export declare function read(fd: number, buffer: Uint8Array, offset: number, len
223
224
  * @param gid
224
225
  * @param callback
225
226
  */
226
- export declare function fchown(fd: number, uid: number, gid: number, cb?: NoArgCallback): void;
227
+ export declare function fchown(fd: number, uid: number, gid: number, cb?: Callback): void;
227
228
  /**
228
229
  * Asynchronous `fchmod`.
229
230
  * @param fd
230
231
  * @param mode
231
232
  * @param callback
232
233
  */
233
- export declare function fchmod(fd: number, mode: string | number, cb: NoArgCallback): void;
234
+ export declare function fchmod(fd: number, mode: string | number, cb: Callback): void;
234
235
  /**
235
236
  * Change the file timestamps of a file referenced by the supplied file
236
237
  * descriptor.
@@ -239,20 +240,20 @@ export declare function fchmod(fd: number, mode: string | number, cb: NoArgCallb
239
240
  * @param mtime
240
241
  * @param callback
241
242
  */
242
- export declare function futimes(fd: number, atime: number | Date, mtime: number | Date, cb?: NoArgCallback): void;
243
+ export declare function futimes(fd: number, atime: number | Date, mtime: number | Date, cb?: Callback): void;
243
244
  /**
244
245
  * Asynchronous `rmdir`.
245
246
  * @param path
246
247
  * @param callback
247
248
  */
248
- export declare function rmdir(path: PathLike, cb?: NoArgCallback): void;
249
+ export declare function rmdir(path: PathLike, cb?: Callback): void;
249
250
  /**
250
251
  * Asynchronous `mkdir`.
251
252
  * @param path
252
253
  * @param mode defaults to `0777`
253
254
  * @param callback
254
255
  */
255
- export declare function mkdir(path: PathLike, mode?: Node.Mode, cb?: NoArgCallback): void;
256
+ export declare function mkdir(path: PathLike, mode?: Node.Mode, cb?: Callback): void;
256
257
  /**
257
258
  * Asynchronous `readdir`. Reads the contents of a directory.
258
259
  * The callback gets two arguments `(err, files)` where `files` is an array of
@@ -260,20 +261,20 @@ export declare function mkdir(path: PathLike, mode?: Node.Mode, cb?: NoArgCallba
260
261
  * @param path
261
262
  * @param callback
262
263
  */
263
- export declare function readdir(path: PathLike, cb: TwoArgCallback<string[]>): void;
264
+ export declare function readdir(path: PathLike, cb: Callback<[string[]]>): void;
264
265
  export declare function readdir(path: PathLike, options: {
265
266
  withFileTypes?: false;
266
- }, cb: TwoArgCallback<string[]>): void;
267
+ }, cb: Callback<[string[]]>): void;
267
268
  export declare function readdir(path: PathLike, options: {
268
269
  withFileTypes: true;
269
- }, cb: TwoArgCallback<Dirent[]>): void;
270
+ }, cb: Callback<[Dirent[]]>): void;
270
271
  /**
271
272
  * Asynchronous `link`.
272
273
  * @param existing
273
274
  * @param newpath
274
275
  * @param callback
275
276
  */
276
- export declare function link(existing: PathLike, newpath: PathLike, cb?: NoArgCallback): void;
277
+ export declare function link(existing: PathLike, newpath: PathLike, cb?: Callback): void;
277
278
  /**
278
279
  * Asynchronous `symlink`.
279
280
  * @param target target path
@@ -281,17 +282,17 @@ export declare function link(existing: PathLike, newpath: PathLike, cb?: NoArgCa
281
282
  * @param type can be either `'dir'` or `'file'` (default is `'file'`)
282
283
  * @param callback
283
284
  */
284
- export declare function symlink(target: PathLike, path: PathLike, cb?: NoArgCallback): void;
285
- export declare function symlink(target: PathLike, path: PathLike, type?: Node.symlink.Type, cb?: NoArgCallback): void;
285
+ export declare function symlink(target: PathLike, path: PathLike, cb?: Callback): void;
286
+ export declare function symlink(target: PathLike, path: PathLike, type?: Node.symlink.Type, cb?: Callback): void;
286
287
  /**
287
288
  * Asynchronous readlink.
288
289
  * @param path
289
290
  * @param callback
290
291
  */
291
- export declare function readlink(path: PathLike, callback: TwoArgCallback<string> & any): void;
292
- export declare function readlink(path: PathLike, options: Node.BufferEncodingOption, callback: TwoArgCallback<Uint8Array>): void;
293
- export declare function readlink(path: PathLike, options: Node.EncodingOption, callback: TwoArgCallback<string | Uint8Array>): void;
294
- export declare function readlink(path: PathLike, options: Node.EncodingOption, callback: TwoArgCallback<string>): void;
292
+ export declare function readlink(path: PathLike, callback: Callback<[string]> & any): void;
293
+ export declare function readlink(path: PathLike, options: Node.BufferEncodingOption, callback: Callback<[Uint8Array]>): void;
294
+ export declare function readlink(path: PathLike, options: Node.EncodingOption, callback: Callback<[string | Uint8Array]>): void;
295
+ export declare function readlink(path: PathLike, options: Node.EncodingOption, callback: Callback<[string]>): void;
295
296
  /**
296
297
  * Asynchronous `chown`.
297
298
  * @param path
@@ -299,7 +300,7 @@ export declare function readlink(path: PathLike, options: Node.EncodingOption, c
299
300
  * @param gid
300
301
  * @param callback
301
302
  */
302
- export declare function chown(path: PathLike, uid: number, gid: number, cb?: NoArgCallback): void;
303
+ export declare function chown(path: PathLike, uid: number, gid: number, cb?: Callback): void;
303
304
  /**
304
305
  * Asynchronous `lchown`.
305
306
  * @param path
@@ -307,21 +308,21 @@ export declare function chown(path: PathLike, uid: number, gid: number, cb?: NoA
307
308
  * @param gid
308
309
  * @param callback
309
310
  */
310
- export declare function lchown(path: PathLike, uid: number, gid: number, cb?: NoArgCallback): void;
311
+ export declare function lchown(path: PathLike, uid: number, gid: number, cb?: Callback): void;
311
312
  /**
312
313
  * Asynchronous `chmod`.
313
314
  * @param path
314
315
  * @param mode
315
316
  * @param callback
316
317
  */
317
- export declare function chmod(path: PathLike, mode: number | string, cb?: NoArgCallback): void;
318
+ export declare function chmod(path: PathLike, mode: number | string, cb?: Callback): void;
318
319
  /**
319
320
  * Asynchronous `lchmod`.
320
321
  * @param path
321
322
  * @param mode
322
323
  * @param callback
323
324
  */
324
- export declare function lchmod(path: PathLike, mode: number | string, cb?: NoArgCallback): void;
325
+ export declare function lchmod(path: PathLike, mode: number | string, cb?: Callback): void;
325
326
  /**
326
327
  * Change file timestamps of the file referenced by the supplied path.
327
328
  * @param path
@@ -329,7 +330,7 @@ export declare function lchmod(path: PathLike, mode: number | string, cb?: NoArg
329
330
  * @param mtime
330
331
  * @param callback
331
332
  */
332
- export declare function utimes(path: PathLike, atime: number | Date, mtime: number | Date, cb?: NoArgCallback): void;
333
+ export declare function utimes(path: PathLike, atime: number | Date, mtime: number | Date, cb?: Callback): void;
333
334
  /**
334
335
  * Change file timestamps of the file referenced by the supplied path.
335
336
  * @param path
@@ -337,7 +338,7 @@ export declare function utimes(path: PathLike, atime: number | Date, mtime: numb
337
338
  * @param mtime
338
339
  * @param callback
339
340
  */
340
- export declare function lutimes(path: PathLike, atime: number | Date, mtime: number | Date, cb?: NoArgCallback): void;
341
+ export declare function lutimes(path: PathLike, atime: number | Date, mtime: number | Date, cb?: Callback): void;
341
342
  /**
342
343
  * Asynchronous `realpath`. The callback gets two arguments
343
344
  * `(err, resolvedPath)`. May use `process.cwd` to resolve relative paths.
@@ -345,16 +346,16 @@ export declare function lutimes(path: PathLike, atime: number | Date, mtime: num
345
346
  * @param path
346
347
  * @param callback
347
348
  */
348
- export declare function realpath(path: PathLike, cb?: TwoArgCallback<string>): void;
349
- export declare function realpath(path: PathLike, options: Node.EncodingOption, cb: TwoArgCallback<string>): void;
349
+ export declare function realpath(path: PathLike, cb?: Callback<[string]>): void;
350
+ export declare function realpath(path: PathLike, options: Node.EncodingOption, cb: Callback<[string]>): void;
350
351
  /**
351
352
  * Asynchronous `access`.
352
353
  * @param path
353
354
  * @param mode
354
355
  * @param callback
355
356
  */
356
- export declare function access(path: PathLike, cb: NoArgCallback): void;
357
- export declare function access(path: PathLike, mode: number, cb: NoArgCallback): void;
357
+ export declare function access(path: PathLike, cb: Callback): void;
358
+ export declare function access(path: PathLike, mode: number, cb: Callback): void;
358
359
  /**
359
360
  * @todo Implement
360
361
  */
@@ -393,33 +394,33 @@ export declare function createWriteStream(path: PathLike, options?: {
393
394
  fd?: number;
394
395
  mode?: number;
395
396
  }): WriteStream;
396
- export declare function rm(path: PathLike, callback: NoArgCallback): void;
397
- export declare function rm(path: PathLike, options: Node.RmOptions, callback: NoArgCallback): void;
397
+ export declare function rm(path: PathLike, callback: Callback): void;
398
+ export declare function rm(path: PathLike, options: Node.RmOptions, callback: Callback): void;
398
399
  /**
399
400
  * Asynchronously creates a unique temporary directory.
400
401
  * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
401
402
  */
402
- export declare function mkdtemp(prefix: string, callback: TwoArgCallback<string>): void;
403
- export declare function mkdtemp(prefix: string, options: Node.EncodingOption, callback: TwoArgCallback<string>): void;
404
- export declare function mkdtemp(prefix: string, options: Node.BufferEncodingOption, callback: TwoArgCallback<Buffer>): void;
405
- export declare function copyFile(src: PathLike, dest: PathLike, callback: NoArgCallback): void;
406
- export declare function copyFile(src: PathLike, dest: PathLike, flags: number, callback: NoArgCallback): void;
407
- type readvCb = ThreeArgCallback<number, NodeJS.ArrayBufferView[]>;
403
+ export declare function mkdtemp(prefix: string, callback: Callback<[string]>): void;
404
+ export declare function mkdtemp(prefix: string, options: Node.EncodingOption, callback: Callback<[string]>): void;
405
+ export declare function mkdtemp(prefix: string, options: Node.BufferEncodingOption, callback: Callback<[Buffer]>): void;
406
+ export declare function copyFile(src: PathLike, dest: PathLike, callback: Callback): void;
407
+ export declare function copyFile(src: PathLike, dest: PathLike, flags: number, callback: Callback): void;
408
+ type readvCb = Callback<[number, NodeJS.ArrayBufferView[]]>;
408
409
  export declare function readv(fd: number, buffers: readonly NodeJS.ArrayBufferView[], cb: readvCb): void;
409
410
  export declare function readv(fd: number, buffers: readonly NodeJS.ArrayBufferView[], position: number, cb: readvCb): void;
410
- type writevCb = ThreeArgCallback<number, NodeJS.ArrayBufferView[]>;
411
+ type writevCb = Callback<[number, NodeJS.ArrayBufferView[]]>;
411
412
  export declare function writev(fd: number, buffers: NodeJS.ArrayBufferView[], cb: writevCb): void;
412
413
  export declare function writev(fd: number, buffers: NodeJS.ArrayBufferView[], position: number, cb: writevCb): void;
413
- export declare function opendir(path: PathLike, cb: TwoArgCallback<Dir>): void;
414
- export declare function opendir(path: PathLike, options: Node.OpenDirOptions, cb: TwoArgCallback<Dir>): void;
415
- export declare function cp(source: PathLike, destination: PathLike, callback: NoArgCallback): void;
416
- export declare function cp(source: PathLike, destination: PathLike, opts: Node.CopyOptions, callback: NoArgCallback): void;
417
- export declare function statfs(path: PathLike, callback: TwoArgCallback<StatsFs>): void;
414
+ export declare function opendir(path: PathLike, cb: Callback<[Dir]>): void;
415
+ export declare function opendir(path: PathLike, options: Node.OpenDirOptions, cb: Callback<[Dir]>): void;
416
+ export declare function cp(source: PathLike, destination: PathLike, callback: Callback): void;
417
+ export declare function cp(source: PathLike, destination: PathLike, opts: Node.CopyOptions, callback: Callback): void;
418
+ export declare function statfs(path: PathLike, callback: Callback<[StatsFs]>): void;
418
419
  export declare function statfs(path: PathLike, options: Node.StatFsOptions & {
419
420
  bigint?: false;
420
- }, callback: TwoArgCallback<StatsFs>): void;
421
+ }, callback: Callback<[StatsFs]>): void;
421
422
  export declare function statfs(path: PathLike, options: Node.StatFsOptions & {
422
423
  bigint: true;
423
- }, callback: TwoArgCallback<BigIntStatsFs>): void;
424
+ }, callback: Callback<[BigIntStatsFs]>): void;
424
425
  export declare function openAsBlob(path: PathLike, options?: Node.OpenAsBlobOptions): Promise<Blob>;
425
426
  export {};
@@ -35,7 +35,7 @@ export function stat(path, options, callback = nop) {
35
35
  callback = typeof options == 'function' ? options : callback;
36
36
  promises
37
37
  .stat(path, typeof options != 'function' ? options : {})
38
- .then(stats => callback(null, stats))
38
+ .then((stats) => callback(null, stats))
39
39
  .catch(callback);
40
40
  }
41
41
  stat;
@@ -105,7 +105,7 @@ export function fstat(fd, options, cb = nop) {
105
105
  cb = typeof options == 'function' ? options : cb;
106
106
  fd2file(fd)
107
107
  .stat()
108
- .then(stats => cb(null, (typeof options == 'object' && options?.bigint ? new BigIntStats(stats) : stats)))
108
+ .then(stats => cb(null, typeof options == 'object' && options?.bigint ? new BigIntStats(stats) : stats))
109
109
  .catch(cb);
110
110
  }
111
111
  fstat;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  import type { Dirent as _Dirent, Dir as _Dir } from 'fs';
3
- import type { NoArgCallback, TwoArgCallback } from '../filesystem.js';
3
+ import type { Callback } from '../utils.js';
4
4
  import type { Stats } from '../stats.js';
5
5
  export declare class Dirent implements _Dirent {
6
6
  path: string;
@@ -29,7 +29,7 @@ export declare class Dir implements _Dir {
29
29
  * Subsequent reads will result in errors.
30
30
  */
31
31
  close(): Promise<void>;
32
- close(cb: NoArgCallback): void;
32
+ close(cb: Callback): void;
33
33
  /**
34
34
  * Synchronously close the directory's underlying resource handle.
35
35
  * Subsequent reads will result in errors.
@@ -42,7 +42,7 @@ export declare class Dir implements _Dir {
42
42
  * Directory entries returned by this function are in no particular order as provided by the operating system's underlying directory mechanisms.
43
43
  */
44
44
  read(): Promise<Dirent | null>;
45
- read(cb: TwoArgCallback<Dirent | null>): void;
45
+ read(cb: Callback<[Dirent | null]>): void;
46
46
  /**
47
47
  * Synchronously read the next directory entry via `readdir(3)` as a `Dirent`.
48
48
  * If there are no more directory entries to read, null will be returned.
@@ -416,7 +416,7 @@ readFile;
416
416
  * @option options flag Defaults to `'w'`.
417
417
  */
418
418
  export async function writeFile(filename, data, _options) {
419
- const options = normalizeOptions(_options, 'utf8', 'w', 0o644);
419
+ const options = normalizeOptions(_options, 'utf8', 'w+', 0o644);
420
420
  const handle = await open(filename, options.flag, options.mode);
421
421
  try {
422
422
  await handle.writeFile(data, options);
@@ -2,9 +2,9 @@
2
2
  /// <reference types="node" resolution-mode="require"/>
3
3
  import type * as Node from 'fs';
4
4
  import { Readable, Writable } from 'readable-stream';
5
- import { NoArgCallback } from '../filesystem.js';
5
+ import { Callback } from '../utils.js';
6
6
  export declare class ReadStream extends Readable implements Node.ReadStream {
7
- close(callback?: NoArgCallback): void;
7
+ close(callback?: Callback): void;
8
8
  bytesRead: number;
9
9
  path: string | Buffer;
10
10
  pending: boolean;
@@ -55,7 +55,7 @@ export declare class ReadStream extends Readable implements Node.ReadStream {
55
55
  prependOnceListener(event: 'resume', listener: () => void): this;
56
56
  }
57
57
  export declare class WriteStream extends Writable implements Node.WriteStream {
58
- close(callback?: NoArgCallback): void;
58
+ close(callback?: Callback): void;
59
59
  bytesWritten: number;
60
60
  path: string | Buffer;
61
61
  pending: boolean;
@@ -199,7 +199,7 @@ function _writeFileSync(fname, data, flag, mode, resolveSymlinks) {
199
199
  }
200
200
  }
201
201
  export function writeFileSync(filename, data, _options) {
202
- const options = normalizeOptions(_options, 'utf8', 'w', 0o644);
202
+ const options = normalizeOptions(_options, 'utf8', 'w+', 0o644);
203
203
  const flag = parseFlag(options.flag);
204
204
  if (!isWriteable(flag)) {
205
205
  throw new ApiError(ErrorCode.EINVAL, 'Flag passed to writeFile must allow for writing.');
@@ -1,10 +1,6 @@
1
- import { ApiError } from './ApiError.js';
2
- import type { Stats } from './stats.js';
3
- import { type File } from './file.js';
4
1
  import { type Cred } from './cred.js';
5
- export type NoArgCallback = (e?: ApiError) => unknown;
6
- export type TwoArgCallback<T> = (e?: ApiError, rv?: T) => unknown;
7
- export type ThreeArgCallback<T, U> = (e?: ApiError, arg1?: T, arg2?: U) => unknown;
2
+ import { type File } from './file.js';
3
+ import type { Stats } from './stats.js';
8
4
  export type FileContents = Uint8Array | string;
9
5
  /**
10
6
  * Metadata about a FileSystem
@@ -18,10 +14,6 @@ export interface FileSystemMetadata {
18
14
  * Wheter the FS is readonly or not
19
15
  */
20
16
  readonly: boolean;
21
- /**
22
- * Does the FS support properties
23
- */
24
- supportsProperties: boolean;
25
17
  /**
26
18
  * The total space
27
19
  */
@@ -1,7 +1,7 @@
1
1
  import { ApiError, ErrorCode } from './ApiError.js';
2
- import { PreloadFile, parseFlag } from './file.js';
3
2
  import { rootCred } from './cred.js';
4
3
  import { join } from './emulation/path.js';
4
+ import { PreloadFile, parseFlag } from './file.js';
5
5
  /**
6
6
  * Structure for a filesystem. All ZenFS FileSystems must implement this.
7
7
  *
@@ -20,7 +20,6 @@ export class FileSystem {
20
20
  return {
21
21
  name: this.constructor.name,
22
22
  readonly: false,
23
- supportsProperties: false,
24
23
  totalSpace: 0,
25
24
  freeSpace: 0,
26
25
  };
@@ -125,6 +124,7 @@ export function Async(FS) {
125
124
  this._isInitialized = false;
126
125
  }
127
126
  async ready() {
127
+ await this._sync.ready();
128
128
  if (this._isInitialized) {
129
129
  return this;
130
130
  }
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,7 @@
1
- import { FileSystem } from './filesystem.js';
1
+ import type { OptionalTuple } from 'utilium';
2
+ import { ApiError } from './ApiError.js';
2
3
  import { Cred } from './cred.js';
4
+ import { FileSystem } from './filesystem.js';
3
5
  declare global {
4
6
  function atob(data: string): string;
5
7
  function btoa(data: string): string;
@@ -14,11 +16,6 @@ export declare function mkdirpSync(p: string, mode: number, cred: Cred, fs: File
14
16
  * @hidden
15
17
  */
16
18
  export declare function levenshtein(a: string, b: string): number;
17
- /**
18
- * Waits n ms.
19
- * @hidden
20
- */
21
- export declare function wait(ms: number): Promise<void>;
22
19
  /**
23
20
  * @hidden
24
21
  */
@@ -43,20 +40,4 @@ export declare function decodeDirListing(data: Uint8Array): Record<string, bigin
43
40
  * @hidden
44
41
  */
45
42
  export declare function encodeDirListing(data: Record<string, bigint>): Uint8Array;
46
- /**
47
- * Extracts an object of properties assignable to P from an object T
48
- * @hidden
49
- */
50
- export type ExtractProperties<T, P> = {
51
- [K in keyof T as T[K] extends infer Prop ? (Prop extends P ? K : never) : never]: T[K];
52
- };
53
- /**
54
- * Extract a the keys in T which are required properties
55
- * @hidden
56
- * @see https://stackoverflow.com/a/55247867/17637456
57
- */
58
- export type RequiredKeys<T> = {
59
- [K in keyof T]-?: {} extends {
60
- [P in K]: T[K];
61
- } ? never : K;
62
- }[keyof T];
43
+ export type Callback<Args extends unknown[] = []> = (e?: ApiError, ...args: OptionalTuple<Args>) => unknown;
package/dist/utils.js CHANGED
@@ -83,15 +83,6 @@ export function levenshtein(a, b) {
83
83
  }
84
84
  return dd;
85
85
  }
86
- /**
87
- * Waits n ms.
88
- * @hidden
89
- */
90
- export function wait(ms) {
91
- return new Promise(resolve => {
92
- setTimeout(resolve, ms);
93
- });
94
- }
95
86
  /**
96
87
  * @hidden
97
88
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/core",
3
- "version": "0.7.10",
3
+ "version": "0.8.0",
4
4
  "description": "A filesystem in your browser",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist",
@@ -57,7 +57,8 @@
57
57
  "@types/readable-stream": "^4.0.10",
58
58
  "buffer": "^6.0.3",
59
59
  "minimatch": "^9.0.3",
60
- "readable-stream": "^4.5.2"
60
+ "readable-stream": "^4.5.2",
61
+ "utilium": "^0.2.0"
61
62
  },
62
63
  "devDependencies": {
63
64
  "@fal-works/esbuild-plugin-global-externals": "^2.1.2",