@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,11 +1,12 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  /// <reference types="node" resolution-mode="require"/>
3
+ /// <reference types="node" resolution-mode="require"/>
3
4
  import type * as Node from 'fs';
4
- import { TwoArgCallback, NoArgCallback, ThreeArgCallback, FileContents } from '../filesystem.js';
5
- import { BigIntStats, type Stats } from '../stats.js';
5
+ import { FileContents, NoArgCallback, ThreeArgCallback, TwoArgCallback } from '../filesystem.js';
6
+ import { BigIntStats, type BigIntStatsFs, type Stats, type StatsFs } from '../stats.js';
7
+ import { Dirent, type Dir } from './dir.js';
6
8
  import { PathLike } from './shared.js';
7
9
  import { ReadStream, WriteStream } from './streams.js';
8
- import { Dirent } from './dir.js';
9
10
  /**
10
11
  * Asynchronous rename. No arguments other than a possible exception are given
11
12
  * to the completion callback.
@@ -19,6 +20,7 @@ export declare function rename(oldPath: PathLike, newPath: PathLike, cb?: NoArgC
19
20
  * Then call the callback argument with either true or false.
20
21
  * @param path
21
22
  * @param callback
23
+ * @deprecated Use {@link stat} or {@link access} instead.
22
24
  */
23
25
  export declare function exists(path: PathLike, cb?: (exists: boolean) => unknown): void;
24
26
  /**
@@ -197,9 +199,9 @@ export declare function fdatasync(fd: number, cb?: NoArgCallback): void;
197
199
  * @param callback The number specifies the number of bytes written into the file.
198
200
  */
199
201
  export declare function write(fd: number, buffer: Uint8Array, offset: number, length: number, cb?: ThreeArgCallback<number, Uint8Array>): void;
200
- export declare function write(fd: number, buffer: Uint8Array, offset: number, length: number, position: number | null, 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;
201
203
  export declare function write(fd: number, data: FileContents, cb?: ThreeArgCallback<number, string>): void;
202
- export declare function write(fd: number, data: FileContents, position: number | null, cb?: ThreeArgCallback<number, string>): void;
204
+ export declare function write(fd: number, data: FileContents, position?: number, cb?: ThreeArgCallback<number, string>): void;
203
205
  export declare function write(fd: number, data: FileContents, position: number | null, encoding: BufferEncoding, cb?: ThreeArgCallback<number, string>): void;
204
206
  /**
205
207
  * Read data from the file specified by `fd`.
@@ -288,8 +290,8 @@ export declare function symlink(target: PathLike, path: PathLike, type?: Node.sy
288
290
  */
289
291
  export declare function readlink(path: PathLike, callback: TwoArgCallback<string> & any): void;
290
292
  export declare function readlink(path: PathLike, options: Node.BufferEncodingOption, callback: TwoArgCallback<Uint8Array>): void;
291
- export declare function readlink(path: PathLike, options: Node.BaseEncodingOptions | string, callback: TwoArgCallback<string | Uint8Array>): void;
292
- export declare function readlink(path: PathLike, options: Node.BaseEncodingOptions | BufferEncoding, callback: TwoArgCallback<string>): 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;
293
295
  /**
294
296
  * Asynchronous `chown`.
295
297
  * @param path
@@ -344,7 +346,7 @@ export declare function lutimes(path: PathLike, atime: number | Date, mtime: num
344
346
  * @param callback
345
347
  */
346
348
  export declare function realpath(path: PathLike, cb?: TwoArgCallback<string>): void;
347
- export declare function realpath(path: PathLike, options: Node.BaseEncodingOptions, cb: TwoArgCallback<string>): void;
349
+ export declare function realpath(path: PathLike, options: Node.EncodingOption, cb: TwoArgCallback<string>): void;
348
350
  /**
349
351
  * Asynchronous `access`.
350
352
  * @param path
@@ -353,16 +355,28 @@ export declare function realpath(path: PathLike, options: Node.BaseEncodingOptio
353
355
  */
354
356
  export declare function access(path: PathLike, cb: NoArgCallback): void;
355
357
  export declare function access(path: PathLike, mode: number, cb: NoArgCallback): void;
358
+ /**
359
+ * @todo Implement
360
+ */
356
361
  export declare function watchFile(filename: PathLike, listener: (curr: Stats, prev: Stats) => void): void;
357
362
  export declare function watchFile(filename: PathLike, options: {
358
363
  persistent?: boolean;
359
364
  interval?: number;
360
365
  }, listener: (curr: Stats, prev: Stats) => void): void;
366
+ /**
367
+ * @todo Implement
368
+ */
361
369
  export declare function unwatchFile(filename: PathLike, listener?: (curr: Stats, prev: Stats) => void): void;
370
+ /**
371
+ * @todo Implement
372
+ */
362
373
  export declare function watch(filename: PathLike, listener?: (event: string, filename: string) => any): Node.FSWatcher;
363
374
  export declare function watch(filename: PathLike, options: {
364
375
  persistent?: boolean;
365
376
  }, listener?: (event: string, filename: string) => any): Node.FSWatcher;
377
+ /**
378
+ * @todo Implement
379
+ */
366
380
  export declare function createReadStream(path: PathLike, options?: {
367
381
  flags?: string;
368
382
  encoding?: string;
@@ -370,19 +384,42 @@ export declare function createReadStream(path: PathLike, options?: {
370
384
  mode?: number;
371
385
  autoClose?: boolean;
372
386
  }): ReadStream;
387
+ /**
388
+ * @todo Implement
389
+ */
373
390
  export declare function createWriteStream(path: PathLike, options?: {
374
391
  flags?: string;
375
392
  encoding?: string;
376
393
  fd?: number;
377
394
  mode?: number;
378
395
  }): WriteStream;
379
- export declare function rm(path: PathLike): void;
380
- export declare function mkdtemp(path: PathLike): void;
396
+ export declare function rm(path: PathLike, callback: NoArgCallback): void;
397
+ export declare function rm(path: PathLike, options: Node.RmOptions, callback: NoArgCallback): void;
398
+ /**
399
+ * Asynchronously creates a unique temporary directory.
400
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
401
+ */
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;
381
405
  export declare function copyFile(src: PathLike, dest: PathLike, callback: NoArgCallback): void;
382
406
  export declare function copyFile(src: PathLike, dest: PathLike, flags: number, callback: NoArgCallback): void;
383
- export declare function readv(path: PathLike): void;
384
- type writevCallback = ThreeArgCallback<number, Uint8Array[]>;
385
- export declare function writev(fd: number, buffers: Uint8Array[], cb: writevCallback): void;
386
- export declare function writev(fd: number, buffers: Uint8Array[], position: number, cb: writevCallback): void;
387
- export declare function opendir(path: PathLike): void;
407
+ type readvCb = ThreeArgCallback<number, NodeJS.ArrayBufferView[]>;
408
+ export declare function readv(fd: number, buffers: readonly NodeJS.ArrayBufferView[], cb: readvCb): void;
409
+ export declare function readv(fd: number, buffers: readonly NodeJS.ArrayBufferView[], position: number, cb: readvCb): void;
410
+ type writevCb = ThreeArgCallback<number, NodeJS.ArrayBufferView[]>;
411
+ export declare function writev(fd: number, buffers: NodeJS.ArrayBufferView[], cb: writevCb): void;
412
+ 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;
418
+ export declare function statfs(path: PathLike, options: Node.StatFsOptions & {
419
+ bigint?: false;
420
+ }, callback: TwoArgCallback<StatsFs>): void;
421
+ export declare function statfs(path: PathLike, options: Node.StatFsOptions & {
422
+ bigint: true;
423
+ }, callback: TwoArgCallback<BigIntStatsFs>): void;
424
+ export declare function openAsBlob(path: PathLike, options?: Node.OpenAsBlobOptions): Promise<Blob>;
388
425
  export {};
@@ -1,9 +1,8 @@
1
1
  import { ApiError, ErrorCode } from '../ApiError.js';
2
2
  import { BigIntStats } from '../stats.js';
3
- import { fd2file, nop, normalizeMode } from './shared.js';
4
- import * as promises from './promises.js';
5
3
  import { R_OK } from './constants.js';
6
- import { decode, encode } from '../utils.js';
4
+ import * as promises from './promises.js';
5
+ import { fd2file, nop, normalizeMode } from './shared.js';
7
6
  /**
8
7
  * Asynchronous rename. No arguments other than a possible exception are given
9
8
  * to the completion callback.
@@ -23,6 +22,7 @@ rename;
23
22
  * Then call the callback argument with either true or false.
24
23
  * @param path
25
24
  * @param callback
25
+ * @deprecated Use {@link stat} or {@link access} instead.
26
26
  */
27
27
  export function exists(path, cb = nop) {
28
28
  promises
@@ -154,45 +154,45 @@ export function fdatasync(fd, cb = nop) {
154
154
  .catch(cb);
155
155
  }
156
156
  fdatasync;
157
- export function write(fd, arg2, arg3, arg4, arg5, cb = nop) {
157
+ export function write(fd, data, cbPosOff, cbLenEnc, cbPos, cb = nop) {
158
158
  let buffer, offset, length, position = null, encoding;
159
159
  const handle = new promises.FileHandle(fd);
160
- if (typeof arg2 === 'string') {
160
+ if (typeof data === 'string') {
161
161
  // Signature 1: (fd, string, [position?, [encoding?]], cb?)
162
162
  encoding = 'utf8';
163
- switch (typeof arg3) {
163
+ switch (typeof cbPosOff) {
164
164
  case 'function':
165
165
  // (fd, string, cb)
166
- cb = arg3;
166
+ cb = cbPosOff;
167
167
  break;
168
168
  case 'number':
169
169
  // (fd, string, position, encoding?, cb?)
170
- position = arg3;
171
- encoding = (typeof arg4 === 'string' ? arg4 : 'utf8');
172
- cb = typeof arg5 === 'function' ? arg5 : cb;
170
+ position = cbPosOff;
171
+ encoding = (typeof cbLenEnc === 'string' ? cbLenEnc : 'utf8');
172
+ cb = typeof cbPos === 'function' ? cbPos : cb;
173
173
  break;
174
174
  default:
175
175
  // ...try to find the callback and get out of here!
176
- cb = typeof arg4 === 'function' ? arg4 : typeof arg5 === 'function' ? arg5 : cb;
176
+ cb = typeof cbLenEnc === 'function' ? cbLenEnc : typeof cbPos === 'function' ? cbPos : cb;
177
177
  cb(new ApiError(ErrorCode.EINVAL, 'Invalid arguments.'));
178
178
  return;
179
179
  }
180
- buffer = encode(arg2);
180
+ buffer = Buffer.from(data);
181
181
  offset = 0;
182
182
  length = buffer.length;
183
183
  const _cb = cb;
184
184
  handle
185
185
  .write(buffer, offset, length, position)
186
- .then(({ bytesWritten }) => _cb(null, bytesWritten, decode(buffer)))
186
+ .then(({ bytesWritten }) => _cb(null, bytesWritten, buffer.toString(encoding)))
187
187
  .catch(_cb);
188
188
  }
189
189
  else {
190
190
  // Signature 2: (fd, buffer, offset, length, position?, cb?)
191
- buffer = arg2;
192
- offset = arg3;
193
- length = arg4;
194
- position = typeof arg5 === 'number' ? arg5 : null;
195
- const _cb = (typeof arg5 === 'function' ? arg5 : cb);
191
+ buffer = Buffer.from(data);
192
+ offset = cbPosOff;
193
+ length = cbLenEnc;
194
+ position = typeof cbPos === 'number' ? cbPos : null;
195
+ const _cb = (typeof cbPos === 'function' ? cbPos : cb);
196
196
  handle
197
197
  .write(buffer, offset, length, position)
198
198
  .then(({ bytesWritten }) => _cb(null, bytesWritten, buffer))
@@ -426,35 +426,99 @@ export function access(path, arg2, cb = nop) {
426
426
  }
427
427
  access;
428
428
  export function watchFile(filename, arg2, listener = nop) {
429
- throw new ApiError(ErrorCode.ENOTSUP);
429
+ throw ApiError.With('ENOTSUP', filename, 'watchFile');
430
430
  }
431
+ watchFile;
432
+ /**
433
+ * @todo Implement
434
+ */
431
435
  export function unwatchFile(filename, listener = nop) {
432
- throw new ApiError(ErrorCode.ENOTSUP);
436
+ throw ApiError.With('ENOTSUP', filename, 'unwatchFile');
433
437
  }
434
- export function watch(filename, arg2, listener = nop) {
435
- throw new ApiError(ErrorCode.ENOTSUP);
438
+ unwatchFile;
439
+ export function watch(filename, options, listener = nop) {
440
+ throw ApiError.With('ENOTSUP', filename, 'watch');
436
441
  }
442
+ watch;
443
+ /**
444
+ * @todo Implement
445
+ */
437
446
  export function createReadStream(path, options) {
438
- throw new ApiError(ErrorCode.ENOTSUP);
447
+ throw ApiError.With('ENOTSUP', path, 'createReadStream');
439
448
  }
449
+ createReadStream;
450
+ /**
451
+ * @todo Implement
452
+ */
440
453
  export function createWriteStream(path, options) {
441
- throw new ApiError(ErrorCode.ENOTSUP);
454
+ throw ApiError.With('ENOTSUP', path, 'createWriteStream');
442
455
  }
443
- export function rm(path) {
444
- new ApiError(ErrorCode.ENOTSUP);
456
+ createWriteStream;
457
+ export function rm(path, options, callback = nop) {
458
+ callback = typeof options === 'function' ? options : callback;
459
+ promises
460
+ .rm(path, typeof options === 'function' ? null : options)
461
+ .then(result => callback(null))
462
+ .catch(callback);
445
463
  }
446
- export function mkdtemp(path) {
447
- new ApiError(ErrorCode.ENOTSUP);
464
+ rm;
465
+ export function mkdtemp(prefix, options, callback = nop) {
466
+ callback = typeof options === 'function' ? options : callback;
467
+ promises
468
+ .mkdtemp(prefix, typeof options != 'function' ? options : null)
469
+ .then(result => callback(null, result))
470
+ .catch(callback);
448
471
  }
472
+ mkdtemp;
449
473
  export function copyFile(src, dest, flags, callback) {
450
- new ApiError(ErrorCode.ENOTSUP);
474
+ callback = typeof flags === 'function' ? flags : callback;
475
+ promises
476
+ .copyFile(src, dest, typeof flags === 'function' ? null : flags)
477
+ .then(result => callback(null))
478
+ .catch(callback);
451
479
  }
452
- export function readv(path) {
453
- new ApiError(ErrorCode.ENOTSUP);
480
+ copyFile;
481
+ export function readv(fd, buffers, position, cb = nop) {
482
+ cb = typeof position === 'function' ? position : cb;
483
+ new promises.FileHandle(fd)
484
+ .readv(buffers, typeof position === 'function' ? null : position)
485
+ .then(({ buffers, bytesRead }) => cb(null, bytesRead, buffers))
486
+ .catch(cb);
487
+ }
488
+ readv;
489
+ export function writev(fd, buffers, position, cb = nop) {
490
+ cb = typeof position === 'function' ? position : cb;
491
+ new promises.FileHandle(fd)
492
+ .writev(buffers, typeof position === 'function' ? null : position)
493
+ .then(({ buffers, bytesWritten }) => cb(null, bytesWritten, buffers))
494
+ .catch(cb);
495
+ }
496
+ writev;
497
+ export function opendir(path, options, cb = nop) {
498
+ cb = typeof options === 'function' ? options : cb;
499
+ promises
500
+ .opendir(path, typeof options === 'function' ? null : options)
501
+ .then(result => cb(null, result))
502
+ .catch(cb);
503
+ }
504
+ opendir;
505
+ export function cp(source, destination, opts, callback) {
506
+ callback = typeof opts === 'function' ? opts : callback;
507
+ promises
508
+ .cp(source, destination, typeof opts === 'function' ? null : opts)
509
+ .then(() => callback(null))
510
+ .catch(callback);
454
511
  }
455
- export function writev(fd, buffers, position, cb) {
456
- throw new ApiError(ErrorCode.ENOTSUP);
512
+ cp;
513
+ export function statfs(path, options, callback = nop) {
514
+ callback = typeof options === 'function' ? options : callback;
515
+ promises
516
+ .statfs(path, typeof options === 'function' ? null : options)
517
+ .then(result => callback(null, result))
518
+ .catch(callback);
457
519
  }
458
- export function opendir(path) {
459
- throw new ApiError(ErrorCode.ENOTSUP);
520
+ statfs;
521
+ export function openAsBlob(path, options) {
522
+ throw ApiError.With('ENOTSUP', path, 'openAsBlob');
460
523
  }
524
+ openAsBlob;
@@ -105,3 +105,8 @@ export declare const S_IROTH = 4;
105
105
  export declare const S_IWOTH = 2;
106
106
  /** File mode indicating executable by others. */
107
107
  export declare const S_IXOTH = 1;
108
+ /**
109
+ * When set, a memory file mapping is used to access the file.
110
+ * This flag is ignored since a unix-like FS is emulated
111
+ */
112
+ export declare const UV_FS_O_FILEMAP = 0;
@@ -117,3 +117,8 @@ export const S_IROTH = 4;
117
117
  export const S_IWOTH = 2;
118
118
  /** File mode indicating executable by others. */
119
119
  export const S_IXOTH = 1;
120
+ /**
121
+ * When set, a memory file mapping is used to access the file.
122
+ * This flag is ignored since a unix-like FS is emulated
123
+ */
124
+ export const UV_FS_O_FILEMAP = 0;
@@ -3,9 +3,10 @@ import type { Dirent as _Dirent, Dir as _Dir } from 'fs';
3
3
  import type { NoArgCallback, TwoArgCallback } from '../filesystem.js';
4
4
  import type { Stats } from '../stats.js';
5
5
  export declare class Dirent implements _Dirent {
6
- name: string;
6
+ path: string;
7
7
  protected stats: Stats;
8
- constructor(name: string, stats: Stats);
8
+ get name(): string;
9
+ constructor(path: string, stats: Stats);
9
10
  isFile(): boolean;
10
11
  isDirectory(): boolean;
11
12
  isBlockDevice(): boolean;
@@ -1,9 +1,13 @@
1
1
  import { readdir } from './promises.js';
2
2
  import { ApiError, ErrorCode } from '../ApiError.js';
3
3
  import { readdirSync } from './sync.js';
4
+ import { basename } from './path.js';
4
5
  export class Dirent {
5
- constructor(name, stats) {
6
- this.name = name;
6
+ get name() {
7
+ return basename(this.path);
8
+ }
9
+ constructor(path, stats) {
10
+ this.path = path;
7
11
  this.stats = stats;
8
12
  }
9
13
  isFile() {
@@ -1,8 +1,8 @@
1
- export * from './callbacks.js';
1
+ export * from './async.js';
2
2
  export * from './sync.js';
3
3
  export * as promises from './promises.js';
4
4
  export * as constants from './constants.js';
5
5
  export * from './streams.js';
6
6
  export * from './dir.js';
7
7
  export { initialize, mounts, mount, umount, _toUnixTimestamp } from './shared.js';
8
- export { Stats, BigIntStats } from '../stats.js';
8
+ export { Stats, BigIntStats, StatsFs } from '../stats.js';
@@ -1,8 +1,8 @@
1
- export * from './callbacks.js';
1
+ export * from './async.js';
2
2
  export * from './sync.js';
3
3
  export * as promises from './promises.js';
4
4
  export * as constants from './constants.js';
5
5
  export * from './streams.js';
6
6
  export * from './dir.js';
7
7
  export { initialize, mounts, mount, umount, _toUnixTimestamp } from './shared.js';
8
- export { Stats, BigIntStats } from '../stats.js';
8
+ export { Stats, BigIntStats, StatsFs } from '../stats.js';