@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.
@@ -1,13 +1,21 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  /// <reference types="node" resolution-mode="require"/>
3
3
  /// <reference types="node" resolution-mode="require"/>
4
+ /// <reference types="node" resolution-mode="require"/>
5
+ /// <reference types="node" resolution-mode="require"/>
6
+ /// <reference types="node" resolution-mode="require"/>
7
+ import { Buffer } from 'buffer';
4
8
  import type * as Node from 'node:fs';
5
- export * as constants from './constants.js';
6
- import type { PathLike, BufferToUint8Array } from './shared.js';
9
+ import type * as promises from 'node:fs/promises';
10
+ import type { CreateReadStreamOptions, CreateWriteStreamOptions, FileChangeInfo, FileReadResult, FlagAndOpenMode } from 'node:fs/promises';
7
11
  import { FileContents } from '../filesystem.js';
8
- import { BigIntStats, type Stats } from '../stats.js';
9
- import { Dirent } from './dir.js';
10
- export declare class FileHandle implements BufferToUint8Array<Node.promises.FileHandle> {
12
+ import { BigIntStats, type BigIntStatsFs, type Stats, type StatsFs } from '../stats.js';
13
+ import { Dirent, type Dir } from './dir.js';
14
+ import type { PathLike } from './shared.js';
15
+ export * as constants from './constants.js';
16
+ import type { ReadableStream } from 'node:stream/web';
17
+ import type { Interface as ReadlineInterface } from 'readline';
18
+ export declare class FileHandle implements promises.FileHandle {
11
19
  /**
12
20
  * Gets the file descriptor for this file handle.
13
21
  */
@@ -17,6 +25,8 @@ export declare class FileHandle implements BufferToUint8Array<Node.promises.File
17
25
  * Gets the file descriptor for this file handle.
18
26
  */
19
27
  fd: number);
28
+ private get file();
29
+ private get path();
20
30
  /**
21
31
  * Asynchronous fchown(2) - Change ownership of a file.
22
32
  */
@@ -55,11 +65,7 @@ export declare class FileHandle implements BufferToUint8Array<Node.promises.File
55
65
  * If `mode` is a string, it is parsed as an octal integer.
56
66
  * If `flag` is not supplied, the default of `'a'` is used.
57
67
  */
58
- appendFile(data: string | Uint8Array, _options?: {
59
- encoding?: BufferEncoding;
60
- mode?: Node.Mode;
61
- flag?: Node.OpenMode;
62
- } | BufferEncoding): Promise<void>;
68
+ appendFile(data: string | Uint8Array, _options?: (Node.ObjectEncodingOptions & FlagAndOpenMode) | BufferEncoding): Promise<void>;
63
69
  /**
64
70
  * Asynchronously reads data from the file.
65
71
  * The `FileHandle` must have been opened for reading.
@@ -68,10 +74,7 @@ export declare class FileHandle implements BufferToUint8Array<Node.promises.File
68
74
  * @param length The number of bytes to read.
69
75
  * @param position The offset from the beginning of the file from which data should be read. If `null`, data will be read from the current position.
70
76
  */
71
- read<TBuffer extends Uint8Array>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<{
72
- bytesRead: number;
73
- buffer: TBuffer;
74
- }>;
77
+ read<TBuffer extends NodeJS.ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<FileReadResult<TBuffer>>;
75
78
  /**
76
79
  * Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically.
77
80
  * The `FileHandle` must have been opened for reading.
@@ -80,11 +83,22 @@ export declare class FileHandle implements BufferToUint8Array<Node.promises.File
80
83
  */
81
84
  readFile(_options?: {
82
85
  flag?: Node.OpenMode;
83
- }): Promise<Uint8Array>;
84
- readFile(_options: {
85
- encoding: BufferEncoding;
86
- flag?: Node.OpenMode;
87
- } | BufferEncoding): Promise<string>;
86
+ }): Promise<Buffer>;
87
+ readFile(_options: (Node.ObjectEncodingOptions & FlagAndOpenMode) | BufferEncoding): Promise<string>;
88
+ /**
89
+ * Returns a `ReadableStream` that may be used to read the files data.
90
+ *
91
+ * An error will be thrown if this method is called more than once or is called after the `FileHandle` is closed
92
+ * or closing.
93
+ *
94
+ * While the `ReadableStream` will read the file to completion, it will not close the `FileHandle` automatically. User code must still call the `fileHandle.close()` method.
95
+ *
96
+ * @since v17.0.0
97
+ * @experimental
98
+ */
99
+ readableWebStream(options?: promises.ReadableWebStreamOptions): ReadableStream;
100
+ readLines(options?: promises.CreateReadStreamOptions): ReadlineInterface;
101
+ [Symbol.asyncDispose](): Promise<void>;
88
102
  /**
89
103
  * Asynchronous fstat(2) - Get file status.
90
104
  */
@@ -104,9 +118,9 @@ export declare class FileHandle implements BufferToUint8Array<Node.promises.File
104
118
  * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
105
119
  * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
106
120
  */
107
- write(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<{
121
+ write<TBuffer extends Uint8Array>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<{
108
122
  bytesWritten: number;
109
- buffer: Uint8Array;
123
+ buffer: TBuffer;
110
124
  }>;
111
125
  /**
112
126
  * Asynchronously writes `string` to the file.
@@ -135,16 +149,20 @@ export declare class FileHandle implements BufferToUint8Array<Node.promises.File
135
149
  writeFile(data: string | Uint8Array, _options?: Node.WriteFileOptions): Promise<void>;
136
150
  /**
137
151
  * See `fs.writev` promisified version.
152
+ * @todo Implement
138
153
  */
139
- writev(buffers: ReadonlyArray<Uint8Array>, position?: number): Promise<Node.WriteVResult>;
154
+ writev(buffers: NodeJS.ArrayBufferView[], position?: number): Promise<Node.WriteVResult>;
140
155
  /**
141
156
  * See `fs.readv` promisified version.
157
+ * @todo Implement
142
158
  */
143
- readv(buffers: ReadonlyArray<Uint8Array>, position?: number): Promise<Node.ReadVResult>;
159
+ readv(buffers: readonly NodeJS.ArrayBufferView[], position?: number): Promise<Node.ReadVResult>;
144
160
  /**
145
161
  * Asynchronous close(2) - close a `FileHandle`.
146
162
  */
147
163
  close(): Promise<void>;
164
+ createReadStream(options?: CreateReadStreamOptions): Node.ReadStream;
165
+ createWriteStream(options?: CreateWriteStreamOptions): Node.WriteStream;
148
166
  }
149
167
  /**
150
168
  * Renames a file
@@ -213,11 +231,10 @@ export declare function lopen(path: PathLike, flag: string, mode?: Node.Mode): P
213
231
  */
214
232
  export declare function readFile(filename: PathLike, options?: {
215
233
  flag?: Node.OpenMode;
216
- }): Promise<Uint8Array>;
217
- export declare function readFile(filename: PathLike, options: {
218
- encoding?: BufferEncoding;
234
+ }): Promise<Buffer>;
235
+ export declare function readFile(filename: PathLike, options: (Node.EncodingOption & {
219
236
  flag?: Node.OpenMode;
220
- } | BufferEncoding): Promise<string>;
237
+ }) | BufferEncoding): Promise<string>;
221
238
  /**
222
239
  * Synchronously writes data to a file, replacing the file if it already exists.
223
240
  *
@@ -240,64 +257,10 @@ export declare function writeFile(filename: PathLike, data: FileContents, _optio
240
257
  * @option options mode Defaults to `0644`.
241
258
  * @option options flag Defaults to `'a'`.
242
259
  */
243
- export declare function appendFile(filename: PathLike, data: FileContents, _options?: BufferEncoding | (Node.BaseEncodingOptions & {
260
+ export declare function appendFile(filename: PathLike, data: FileContents, _options?: BufferEncoding | (Node.EncodingOption & {
244
261
  mode?: Node.Mode;
245
262
  flag?: Node.OpenMode;
246
263
  })): Promise<void>;
247
- /**
248
- * Write buffer to the file specified by `fd`.
249
- * Note that it is unsafe to use fs.write multiple times on the same file without waiting for it to return.
250
- * @param handle
251
- * @param data Uint8Array containing the data to write to the file.
252
- * @param offset Offset in the buffer to start reading data from.
253
- * @param length The amount of bytes to write to the file.
254
- * @param position Offset from the beginning of the file where this data should be written. If position is null, the data will be written at the current position.
255
- */
256
- export declare function write(handle: FileHandle, data: Uint8Array, offset: number, length: number, position?: number): Promise<{
257
- bytesWritten: number;
258
- buffer: Uint8Array;
259
- }>;
260
- export declare function write(handle: FileHandle, data: string, position?: number, encoding?: BufferEncoding): Promise<{
261
- bytesWritten: number;
262
- buffer: string;
263
- }>;
264
- /**
265
- * Read data from the file specified by `fd`.
266
- * @param handle
267
- * @param buffer The buffer that the data will be
268
- * written to.
269
- * @param offset The offset within the buffer where writing will
270
- * start.
271
- * @param length An integer specifying the number of bytes to read.
272
- * @param position An integer specifying where to begin reading from
273
- * in the file. If position is null, data will be read from the current file
274
- * position.
275
- */
276
- export declare function read(handle: FileHandle, buffer: Uint8Array, offset: number, length: number, position?: number): Promise<{
277
- bytesRead: number;
278
- buffer: Uint8Array;
279
- }>;
280
- /**
281
- * `fchown`.
282
- * @param handle
283
- * @param uid
284
- * @param gid
285
- */
286
- export declare function fchown(handle: FileHandle, uid: number, gid: number): Promise<void>;
287
- /**
288
- * `fchmod`.
289
- * @param handle
290
- * @param mode
291
- */
292
- export declare function fchmod(handle: FileHandle, mode: Node.Mode): Promise<void>;
293
- /**
294
- * Change the file timestamps of a file referenced by the supplied file
295
- * descriptor.
296
- * @param handle
297
- * @param atime
298
- * @param mtime
299
- */
300
- export declare function futimes(handle: FileHandle, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
301
264
  /**
302
265
  * `rmdir`.
303
266
  * @param path
@@ -318,13 +281,13 @@ export declare function mkdir(path: PathLike, mode: Node.MakeDirectoryOptions &
318
281
  * `readdir`. Reads the contents of a directory.
319
282
  * @param path
320
283
  */
321
- export declare function readdir(path: PathLike, options?: (Node.BaseEncodingOptions & {
284
+ export declare function readdir(path: PathLike, options?: (Node.EncodingOption & {
322
285
  withFileTypes?: false;
323
286
  }) | BufferEncoding): Promise<string[]>;
324
287
  export declare function readdir(path: PathLike, options: Node.BufferEncodingOption & {
325
288
  withFileTypes?: false;
326
- }): Promise<Uint8Array[]>;
327
- export declare function readdir(path: PathLike, options: Node.BaseEncodingOptions & {
289
+ }): Promise<Buffer[]>;
290
+ export declare function readdir(path: PathLike, options: Node.EncodingOption & {
328
291
  withFileTypes: true;
329
292
  }): Promise<Dirent[]>;
330
293
  /**
@@ -344,8 +307,8 @@ export declare function symlink(target: PathLike, path: PathLike, type?: Node.sy
344
307
  * readlink.
345
308
  * @param path
346
309
  */
347
- export declare function readlink(path: PathLike, options: Node.BufferEncodingOption): Promise<Uint8Array>;
348
- export declare function readlink(path: PathLike, options?: Node.BaseEncodingOptions | BufferEncoding): Promise<string>;
310
+ export declare function readlink(path: PathLike, options: Node.BufferEncodingOption): Promise<Buffer>;
311
+ export declare function readlink(path: PathLike, options?: Node.EncodingOption | BufferEncoding): Promise<string>;
349
312
  /**
350
313
  * `chown`.
351
314
  * @param path
@@ -393,37 +356,47 @@ export declare function lutimes(path: PathLike, atime: number | Date, mtime: num
393
356
  *
394
357
  * Note: This *Can not* use doOp since doOp depends on it
395
358
  */
396
- export declare function realpath(path: PathLike, options: Node.BufferEncodingOption): Promise<Uint8Array>;
397
- export declare function realpath(path: PathLike, options?: Node.BaseEncodingOptions | BufferEncoding): Promise<string>;
398
- export declare function watchFile(filename: PathLike, listener: (curr: Stats, prev: Stats) => void): Promise<void>;
399
- export declare function watchFile(filename: PathLike, options: {
400
- persistent?: boolean;
401
- interval?: number;
402
- }, listener: (curr: Stats, prev: Stats) => void): Promise<void>;
403
- export declare function unwatchFile(filename: PathLike, listener?: (curr: Stats, prev: Stats) => void): Promise<void>;
404
- export declare function watch(filename: PathLike, listener?: (event: string, filename: PathLike) => any): Promise<Node.FSWatcher>;
405
- export declare function watch(filename: PathLike, options: {
406
- persistent?: boolean;
407
- }, listener?: (event: string, filename: string) => any): Promise<Node.FSWatcher>;
359
+ export declare function realpath(path: PathLike, options: Node.BufferEncodingOption): Promise<Buffer>;
360
+ export declare function realpath(path: PathLike, options?: Node.EncodingOption | BufferEncoding): Promise<string>;
361
+ /**
362
+ * @todo Implement
363
+ */
364
+ export declare function watch(filename: PathLike, options: (Node.WatchOptions & {
365
+ encoding: 'buffer';
366
+ }) | 'buffer'): AsyncIterable<FileChangeInfo<Buffer>>;
367
+ export declare function watch(filename: PathLike, options?: Node.WatchOptions | BufferEncoding): AsyncIterable<FileChangeInfo<string>>;
408
368
  /**
409
369
  * `access`.
410
370
  * @param path
411
371
  * @param mode
412
372
  */
413
373
  export declare function access(path: PathLike, mode?: number): Promise<void>;
414
- export declare function createReadStream(path: PathLike, options?: {
415
- flags?: string;
416
- encoding?: string;
417
- fd?: number;
418
- mode?: number;
419
- autoClose?: boolean;
420
- }): Promise<Node.ReadStream>;
421
- export declare function createWriteStream(path: PathLike, options?: {
422
- flags?: string;
423
- encoding?: string;
424
- fd?: number;
425
- mode?: number;
426
- }): Promise<Node.WriteStream>;
427
- export declare function rm(path: PathLike): Promise<void>;
428
- export declare function mkdtemp(path: PathLike): Promise<void>;
429
- export declare function copyFile(path: PathLike): Promise<void>;
374
+ /**
375
+ * @todo Implement
376
+ */
377
+ export declare function rm(path: PathLike, options?: Node.RmOptions): Promise<void>;
378
+ /**
379
+ * @todo Implement
380
+ */
381
+ export declare function mkdtemp(prefix: string, options?: Node.EncodingOption): Promise<string>;
382
+ export declare function mkdtemp(prefix: string, options?: Node.BufferEncodingOption): Promise<Buffer>;
383
+ /**
384
+ * @todo Implement
385
+ */
386
+ export declare function copyFile(src: PathLike, dest: PathLike, mode?: number): Promise<void>;
387
+ /**
388
+ * @todo Implement
389
+ */
390
+ export declare function opendir(path: PathLike, options?: Node.OpenDirOptions): Promise<Dir>;
391
+ export declare function cp(source: PathLike, destination: PathLike, opts?: Node.CopyOptions): Promise<void>;
392
+ /**
393
+ * @since v18.15.0
394
+ * @return Fulfills with an {fs.StatFs} for the file system.
395
+ */
396
+ export declare function statfs(path: PathLike, opts?: Node.StatFsOptions & {
397
+ bigint?: false;
398
+ }): Promise<StatsFs>;
399
+ export declare function statfs(path: PathLike, opts: Node.StatFsOptions & {
400
+ bigint: true;
401
+ }): Promise<BigIntStatsFs>;
402
+ export declare function statfs(path: PathLike, opts?: Node.StatFsOptions): Promise<StatsFs | BigIntStatsFs>;