@zenfs/core 0.5.5 → 0.5.7

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.
@@ -3,7 +3,7 @@
3
3
  import { Cred } from '../cred.js';
4
4
  import { FileSystem } from '../filesystem.js';
5
5
  import type { File } from '../file.js';
6
- import type { BaseEncodingOptions, OpenMode, WriteFileOptions } from 'node:fs';
6
+ import type { EncodingOption, OpenMode, WriteFileOptions } from 'node:fs';
7
7
  /**
8
8
  * converts Date or number to a integer UNIX timestamp
9
9
  * Grabbed from NodeJS sources (lib/fs.js)
@@ -34,7 +34,7 @@ export declare function normalizePath(p: string): string;
34
34
  * @param mode default mode
35
35
  * @internal
36
36
  */
37
- export declare function normalizeOptions(options?: WriteFileOptions | (BaseEncodingOptions & {
37
+ export declare function normalizeOptions(options?: WriteFileOptions | (EncodingOption & {
38
38
  flag?: OpenMode;
39
39
  }), encoding?: BufferEncoding, flag?: string, mode?: number): {
40
40
  encoding: BufferEncoding;
@@ -91,12 +91,3 @@ export declare function initialize(mountMapping: MountMapping): void;
91
91
  * In the future, maybe support URL?
92
92
  */
93
93
  export type PathLike = string;
94
- /**
95
- * @internal
96
- *
97
- * Recursivly converts `From` in `Target` to `To`
98
- */
99
- export type Convert<Target, From, To> = Target extends From ? To : Target extends (...args: any[]) => unknown ? (...args: Convert<Parameters<Target>, From, To> & Array<unknown>) => Convert<ReturnType<Target>, From, To> : Target extends object ? {
100
- [K in keyof Target]: Convert<Target[K], From, To>;
101
- } : Target;
102
- export type BufferToUint8Array<T> = Convert<T, Buffer, Uint8Array>;
@@ -67,6 +67,7 @@ export declare class WriteStream extends Writable implements Node.WriteStream {
67
67
  addListener(event: 'pipe', listener: (src: Readable) => void): this;
68
68
  addListener(event: 'ready', listener: () => void): this;
69
69
  addListener(event: 'unpipe', listener: (src: Readable) => void): this;
70
+ addListener(event: string | symbol, listener: (...args: any[]) => void): this;
70
71
  on(event: 'close', listener: () => void): this;
71
72
  on(event: 'drain', listener: () => void): this;
72
73
  on(event: 'error', listener: (err: Error) => void): this;
@@ -75,6 +76,7 @@ export declare class WriteStream extends Writable implements Node.WriteStream {
75
76
  on(event: 'pipe', listener: (src: Readable) => void): this;
76
77
  on(event: 'ready', listener: () => void): this;
77
78
  on(event: 'unpipe', listener: (src: Readable) => void): this;
79
+ on(event: string | symbol, listener: (...args: any[]) => void): this;
78
80
  once(event: 'close', listener: () => void): this;
79
81
  once(event: 'drain', listener: () => void): this;
80
82
  once(event: 'error', listener: (err: Error) => void): this;
@@ -83,6 +85,7 @@ export declare class WriteStream extends Writable implements Node.WriteStream {
83
85
  once(event: 'pipe', listener: (src: Readable) => void): this;
84
86
  once(event: 'ready', listener: () => void): this;
85
87
  once(event: 'unpipe', listener: (src: Readable) => void): this;
88
+ once(event: string | symbol, listener: (...args: any[]) => void): this;
86
89
  prependListener(event: 'close', listener: () => void): this;
87
90
  prependListener(event: 'drain', listener: () => void): this;
88
91
  prependListener(event: 'error', listener: (err: Error) => void): this;
@@ -91,6 +94,7 @@ export declare class WriteStream extends Writable implements Node.WriteStream {
91
94
  prependListener(event: 'pipe', listener: (src: Readable) => void): this;
92
95
  prependListener(event: 'ready', listener: () => void): this;
93
96
  prependListener(event: 'unpipe', listener: (src: Readable) => void): this;
97
+ prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
94
98
  prependOnceListener(event: 'close', listener: () => void): this;
95
99
  prependOnceListener(event: 'drain', listener: () => void): this;
96
100
  prependOnceListener(event: 'error', listener: (err: Error) => void): this;
@@ -99,4 +103,5 @@ export declare class WriteStream extends Writable implements Node.WriteStream {
99
103
  prependOnceListener(event: 'pipe', listener: (src: Readable) => void): this;
100
104
  prependOnceListener(event: 'ready', listener: () => void): this;
101
105
  prependOnceListener(event: 'unpipe', listener: (src: Readable) => void): this;
106
+ prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
102
107
  }
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  /// <reference types="node" resolution-mode="require"/>
3
3
  import { FileContents } from '../filesystem.js';
4
- import { BigIntStats, type Stats } from '../stats.js';
5
- import type { symlink, ReadSyncOptions, BaseEncodingOptions, BufferEncodingOption } from 'fs';
4
+ import { BigIntStats, type BigIntStatsFs, type Stats, type StatsFs } from '../stats.js';
5
+ import type { symlink, ReadSyncOptions, EncodingOption, BufferEncodingOption } from 'fs';
6
6
  import type * as Node from 'fs';
7
7
  import { PathLike } from './shared.js';
8
8
  import { Dir, Dirent } from './dir.js';
@@ -23,7 +23,7 @@ export declare function existsSync(path: PathLike): boolean;
23
23
  * @returns Stats
24
24
  */
25
25
  export declare function statSync(path: PathLike, options?: {
26
- bigint: false;
26
+ bigint?: false;
27
27
  }): Stats;
28
28
  export declare function statSync(path: PathLike, options: {
29
29
  bigint: true;
@@ -35,7 +35,7 @@ export declare function statSync(path: PathLike, options: {
35
35
  * @param path
36
36
  */
37
37
  export declare function lstatSync(path: PathLike, options?: {
38
- bigint: false;
38
+ bigint?: false;
39
39
  }): Stats;
40
40
  export declare function lstatSync(path: PathLike, options: {
41
41
  bigint: true;
@@ -75,8 +75,8 @@ export declare function lopenSync(path: PathLike, flag: string, mode?: Node.Mode
75
75
  */
76
76
  export declare function readFileSync(filename: string, options?: {
77
77
  flag?: string;
78
- }): Uint8Array;
79
- export declare function readFileSync(filename: string, options: (Node.BaseEncodingOptions & {
78
+ }): Buffer;
79
+ export declare function readFileSync(filename: string, options: (Node.EncodingOption & {
80
80
  flag?: string;
81
81
  }) | BufferEncoding): string;
82
82
  /**
@@ -104,7 +104,7 @@ export declare function writeFileSync(filename: string, data: FileContents, enco
104
104
  * @option options mode Defaults to `0644`.
105
105
  * @option options flag Defaults to `'a'`.
106
106
  */
107
- export declare function appendFileSync(filename: string, data: FileContents, arg3?: Node.WriteFileOptions): void;
107
+ export declare function appendFileSync(filename: string, data: FileContents, _options?: Node.WriteFileOptions): void;
108
108
  /**
109
109
  * Synchronous `fstat`.
110
110
  * `fstat()` is identical to `stat()`, except that the file to be stat-ed is
@@ -216,7 +216,7 @@ export declare function readdirSync(path: PathLike, options?: {
216
216
  export declare function readdirSync(path: PathLike, options: {
217
217
  encoding: 'buffer';
218
218
  withFileTypes?: false;
219
- } | 'buffer'): Uint8Array[];
219
+ } | 'buffer'): Buffer[];
220
220
  export declare function readdirSync(path: PathLike, options: {
221
221
  withFileTypes: true;
222
222
  }): Dirent[];
@@ -237,8 +237,8 @@ export declare function symlinkSync(target: PathLike, path: PathLike, type?: sym
237
237
  * Synchronous readlink.
238
238
  * @param path
239
239
  */
240
- export declare function readlinkSync(path: PathLike, options?: BufferEncodingOption): Uint8Array;
241
- export declare function readlinkSync(path: PathLike, options: BaseEncodingOptions | BufferEncoding): string;
240
+ export declare function readlinkSync(path: PathLike, options?: BufferEncodingOption): Buffer;
241
+ export declare function readlinkSync(path: PathLike, options: EncodingOption | BufferEncoding): string;
242
242
  /**
243
243
  * Synchronous `chown`.
244
244
  * @param path
@@ -287,18 +287,53 @@ export declare function lutimesSync(path: PathLike, atime: string | number | Dat
287
287
  * known real paths.
288
288
  * @returns the real path
289
289
  */
290
- export declare function realpathSync(path: PathLike, options: BufferEncodingOption): Uint8Array;
291
- export declare function realpathSync(path: PathLike, options?: BaseEncodingOptions | BufferEncoding): string;
290
+ export declare function realpathSync(path: PathLike, options: BufferEncodingOption): Buffer;
291
+ export declare function realpathSync(path: PathLike, options?: EncodingOption): string;
292
292
  /**
293
293
  * Synchronous `access`.
294
294
  * @param path
295
295
  * @param mode
296
296
  */
297
297
  export declare function accessSync(path: PathLike, mode?: number): void;
298
+ /**
299
+ * @todo Implement
300
+ */
298
301
  export declare function rmSync(path: PathLike): void;
299
- export declare function mkdtempSync(prefix: string, options: BufferEncodingOption): Uint8Array;
300
- export declare function mkdtempSync(prefix: string, options?: BaseEncodingOptions | BufferEncoding): string;
302
+ /**
303
+ * @todo Implement
304
+ */
305
+ export declare function mkdtempSync(prefix: string, options: BufferEncodingOption): Buffer;
306
+ export declare function mkdtempSync(prefix: string, options?: EncodingOption): string;
307
+ /**
308
+ * @todo Implement
309
+ */
301
310
  export declare function copyFileSync(src: string, dest: string, flags?: number): void;
311
+ /**
312
+ * @todo Implement
313
+ */
302
314
  export declare function readvSync(fd: number, buffers: readonly Uint8Array[], position?: number): number;
315
+ /**
316
+ * @todo Implement
317
+ */
303
318
  export declare function writevSync(fd: number, buffers: readonly Uint8Array[], position?: number): number;
319
+ /**
320
+ * @todo Implement
321
+ */
304
322
  export declare function opendirSync(path: PathLike, options?: Node.OpenDirOptions): Dir;
323
+ /**
324
+ * @todo Implement
325
+ */
326
+ export declare function cpSync(source: PathLike, destination: PathLike, opts?: Node.CopySyncOptions): void;
327
+ /**
328
+ * Synchronous statfs(2). Returns information about the mounted file system which contains path. The callback gets two arguments (err, stats) where stats is an <fs.StatFs> object.
329
+ * In case of an error, the err.code will be one of Common System Errors.
330
+ * @param path A path to an existing file or directory on the file system to be queried.
331
+ * @param callback
332
+ */
333
+ export declare function statfsSync(path: PathLike, options?: Node.StatFsOptions & {
334
+ bigint?: false;
335
+ }): StatsFs;
336
+ export declare function statfsSync(path: PathLike, options: Node.StatFsOptions & {
337
+ bigint: true;
338
+ }): BigIntStatsFs;
339
+ export declare function statfsSync(path: PathLike, options?: Node.StatFsOptions): StatsFs | BigIntStatsFs;
@@ -1,8 +1,7 @@
1
1
  import { ApiError, ErrorCode } from '../ApiError.js';
2
2
  import { ActionType, isAppendable, isReadable, isWriteable, parseFlag, pathExistsAction, pathNotExistsAction } from '../file.js';
3
3
  import { BigIntStats, FileType } from '../stats.js';
4
- import { normalizePath, cred, getFdForFile, normalizeMode, normalizeOptions, fdMap, fd2file, normalizeTime, resolveFS, fixError, mounts, } from './shared.js';
5
- import { decode, encode } from '../utils.js';
4
+ import { normalizePath, cred, getFdForFile, normalizeMode, normalizeOptions, fdMap, fd2file, normalizeTime, resolveFS, fixError, mounts } from './shared.js';
6
5
  import { Dirent } from './dir.js';
7
6
  import { dirname, join } from './path.js';
8
7
  function doOp(...[name, resolveSymlinks, path, ...args]) {
@@ -179,8 +178,8 @@ export function readFileSync(filename, arg2 = {}) {
179
178
  if (!isReadable(flag)) {
180
179
  throw new ApiError(ErrorCode.EINVAL, 'Flag passed to readFile must allow for reading.');
181
180
  }
182
- const data = _readFileSync(filename, options.flag, true);
183
- return options.encoding ? decode(data, options.encoding) : data;
181
+ const data = Buffer.from(_readFileSync(filename, options.flag, true));
182
+ return options.encoding ? data.toString(options.encoding) : data;
184
183
  }
185
184
  readFileSync;
186
185
  /**
@@ -207,7 +206,7 @@ export function writeFileSync(filename, data, _options) {
207
206
  if (typeof data != 'string' && !options.encoding) {
208
207
  throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
209
208
  }
210
- const encodedData = typeof data == 'string' ? encode(data, options.encoding) : data;
209
+ const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : data;
211
210
  if (encodedData === undefined) {
212
211
  throw new ApiError(ErrorCode.EINVAL, 'Data not specified');
213
212
  }
@@ -238,8 +237,8 @@ function _appendFileSync(fname, data, flag, mode, resolveSymlinks) {
238
237
  * @option options mode Defaults to `0644`.
239
238
  * @option options flag Defaults to `'a'`.
240
239
  */
241
- export function appendFileSync(filename, data, arg3) {
242
- const options = normalizeOptions(arg3, 'utf8', 'a', 0o644);
240
+ export function appendFileSync(filename, data, _options) {
241
+ const options = normalizeOptions(_options, 'utf8', 'a', 0o644);
243
242
  const flag = parseFlag(options.flag);
244
243
  if (!isAppendable(flag)) {
245
244
  throw new ApiError(ErrorCode.EINVAL, 'Flag passed to appendFile must allow for appending.');
@@ -247,7 +246,7 @@ export function appendFileSync(filename, data, arg3) {
247
246
  if (typeof data != 'string' && !options.encoding) {
248
247
  throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
249
248
  }
250
- const encodedData = typeof data == 'string' ? encode(data) : data;
249
+ const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : data;
251
250
  _appendFileSync(filename, encodedData, options.flag, options.mode, true);
252
251
  }
253
252
  appendFileSync;
@@ -300,7 +299,7 @@ export function writeSync(fd, data, posOrOff, lenOrEnc, pos) {
300
299
  position = typeof posOrOff === 'number' ? posOrOff : null;
301
300
  const encoding = (typeof lenOrEnc === 'string' ? lenOrEnc : 'utf8');
302
301
  offset = 0;
303
- buffer = encode(data, encoding);
302
+ buffer = Buffer.from(data, encoding);
304
303
  length = buffer.length;
305
304
  }
306
305
  else {
@@ -319,11 +318,13 @@ export function writeSync(fd, data, posOrOff, lenOrEnc, pos) {
319
318
  writeSync;
320
319
  export function readSync(fd, buffer, opts, length, position) {
321
320
  const file = fd2file(fd);
322
- let offset = opts;
321
+ const offset = typeof opts == 'object' ? opts.offset : opts;
323
322
  if (typeof opts == 'object') {
324
- ({ offset, length, position } = opts);
323
+ length = opts.length;
324
+ position = opts.position;
325
325
  }
326
- if (isNaN(+position)) {
326
+ position = Number(position);
327
+ if (isNaN(position)) {
327
328
  position = file.position;
328
329
  }
329
330
  return file.readSync(buffer, offset, length, position);
@@ -396,7 +397,7 @@ export function readdirSync(path, options) {
396
397
  return new Dirent(entry, statSync(join(path, entry)));
397
398
  }
398
399
  if (options == 'buffer' || (typeof options == 'object' && options.encoding == 'buffer')) {
399
- return encode(entry);
400
+ return Buffer.from(entry);
400
401
  }
401
402
  return entry;
402
403
  });
@@ -432,12 +433,12 @@ export function symlinkSync(target, path, type = 'file') {
432
433
  }
433
434
  symlinkSync;
434
435
  export function readlinkSync(path, options) {
435
- const value = _readFileSync(path, 'r', false);
436
+ const value = Buffer.from(_readFileSync(path, 'r', false));
436
437
  const encoding = typeof options == 'object' ? options.encoding : options;
437
438
  if (encoding == 'buffer') {
438
439
  return value;
439
440
  }
440
- return decode(value, encoding);
441
+ return value.toString(encoding);
441
442
  }
442
443
  readlinkSync;
443
444
  // PROPERTY OPERATIONS
@@ -519,7 +520,7 @@ export function realpathSync(path, options) {
519
520
  if (!stats.isSymbolicLink()) {
520
521
  return path;
521
522
  }
522
- const dst = normalizePath(mountPoint + decode(_readFileSync(resolvedPath, 'r+', false)));
523
+ const dst = normalizePath(mountPoint + Buffer.from(_readFileSync(resolvedPath, 'r+', false)).toString());
523
524
  return realpathSync(dst);
524
525
  }
525
526
  catch (e) {
@@ -539,27 +540,54 @@ export function accessSync(path, mode = 0o600) {
539
540
  }
540
541
  }
541
542
  accessSync;
543
+ /* eslint-disable @typescript-eslint/no-unused-vars */
544
+ /**
545
+ * @todo Implement
546
+ */
542
547
  export function rmSync(path) {
543
- throw new ApiError(ErrorCode.ENOTSUP);
548
+ throw ApiError.With('ENOTSUP', path, 'rmSync');
544
549
  }
545
550
  rmSync;
546
551
  export function mkdtempSync(prefix, options) {
547
- throw new ApiError(ErrorCode.ENOTSUP);
552
+ throw ApiError.With('ENOTSUP', prefix, 'mkdtempSync');
548
553
  }
549
554
  mkdtempSync;
555
+ /**
556
+ * @todo Implement
557
+ */
550
558
  export function copyFileSync(src, dest, flags) {
551
- throw new ApiError(ErrorCode.ENOTSUP);
559
+ throw ApiError.With('ENOTSUP', src, 'copyFileSync');
552
560
  }
553
561
  copyFileSync;
562
+ /**
563
+ * @todo Implement
564
+ */
554
565
  export function readvSync(fd, buffers, position) {
555
- throw new ApiError(ErrorCode.ENOTSUP);
566
+ throw ApiError.With('ENOTSUP', fd2file(fd).path, 'readvSync');
556
567
  }
557
568
  readvSync;
569
+ /**
570
+ * @todo Implement
571
+ */
558
572
  export function writevSync(fd, buffers, position) {
559
- throw new ApiError(ErrorCode.ENOTSUP);
573
+ throw ApiError.With('ENOTSUP', fd2file(fd).path, 'writevSync');
560
574
  }
561
575
  writevSync;
576
+ /**
577
+ * @todo Implement
578
+ */
562
579
  export function opendirSync(path, options) {
563
- throw new ApiError(ErrorCode.ENOTSUP);
580
+ throw ApiError.With('ENOTSUP', path, 'opendirSync');
564
581
  }
565
582
  opendirSync;
583
+ /**
584
+ * @todo Implement
585
+ */
586
+ export function cpSync(source, destination, opts) {
587
+ throw ApiError.With('ENOTSUP', source, 'cpSync');
588
+ }
589
+ cpSync;
590
+ export function statfsSync(path, options) {
591
+ throw ApiError.With('ENOTSUP', path, 'statfsSync');
592
+ }
593
+ /* eslint-enable @typescript-eslint/no-unused-vars */
package/dist/file.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
3
+ import type { FileReadResult } from 'node:fs/promises';
1
4
  import type { FileSystem } from './filesystem.js';
2
5
  import { Stats, type FileType } from './stats.js';
3
6
  declare global {
@@ -122,10 +125,7 @@ export declare abstract class File {
122
125
  * position.
123
126
  * @returns Promise resolving to the new length of the buffer
124
127
  */
125
- abstract read<TBuffer extends Uint8Array>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<{
126
- bytesRead: number;
127
- buffer: TBuffer;
128
- }>;
128
+ abstract read<TBuffer extends NodeJS.ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<FileReadResult<TBuffer>>;
129
129
  /**
130
130
  * Read data from the file.
131
131
  * @param buffer The buffer that the data will be written to.
@@ -135,7 +135,7 @@ export declare abstract class File {
135
135
  * in the file. If position is null, data will be read from the current file
136
136
  * position.
137
137
  */
138
- abstract readSync(buffer: Uint8Array, offset?: number, length?: number, position?: number): number;
138
+ abstract readSync(buffer: ArrayBufferView, offset?: number, length?: number, position?: number): number;
139
139
  /**
140
140
  * Asynchronous `datasync`.
141
141
  *
@@ -302,7 +302,7 @@ export declare abstract class PreloadFile<FS extends FileSystem> extends File {
302
302
  * in the file. If position is null, data will be read from the current file
303
303
  * position.
304
304
  */
305
- read<TBuffer extends Uint8Array>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<{
305
+ read<TBuffer extends ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<{
306
306
  bytesRead: number;
307
307
  buffer: TBuffer;
308
308
  }>;
@@ -317,7 +317,7 @@ export declare abstract class PreloadFile<FS extends FileSystem> extends File {
317
317
  * position.
318
318
  * @returns number of bytes written
319
319
  */
320
- readSync(buffer: Uint8Array, offset?: number, length?: number, position?: number): number;
320
+ readSync(buffer: ArrayBufferView, offset?: number, length?: number, position?: number): number;
321
321
  /**
322
322
  * Asynchronous `fchmod`.
323
323
  * @param mode the mode
package/dist/file.js CHANGED
@@ -379,7 +379,7 @@ export class PreloadFile extends File {
379
379
  // No copy/read. Return immediatly for better performance
380
380
  return bytesRead;
381
381
  }
382
- buffer.set(this._buffer.slice(position, end), offset);
382
+ new Uint8Array(buffer.buffer).set(this._buffer.slice(position, end), offset);
383
383
  return bytesRead;
384
384
  }
385
385
  /**
package/dist/stats.d.ts CHANGED
@@ -201,19 +201,35 @@ export declare class BigIntStats extends StatsCommon<bigint> implements Node.Big
201
201
  */
202
202
  static clone(stats: BigIntStats | Stats): BigIntStats;
203
203
  }
204
- /**
205
- * @returns true if stats is a file.
206
- */
207
- export declare function isFile(stats: StatsLike): boolean;
208
- /**
209
- * @returns True if stats is a directory.
210
- */
211
- export declare function isDirectory(stats: StatsLike): boolean;
212
- /**
213
- * @returns true if stats is a symbolic link
214
- */
215
- export declare function isSymbolicLink(stats: StatsLike): boolean;
216
- export declare function isSocket(): boolean;
217
- export declare function isBlockDevice(): boolean;
218
- export declare function isCharacterDevice(): boolean;
219
- export declare function isFIFO(): boolean;
204
+ export declare class StatsFs implements Node.StatsFsBase<number> {
205
+ /** Type of file system. */
206
+ type: number;
207
+ /** Optimal transfer block size. */
208
+ bsize: number;
209
+ /** Total data blocks in file system. */
210
+ blocks: number;
211
+ /** Free blocks in file system. */
212
+ bfree: number;
213
+ /** Available blocks for unprivileged users */
214
+ bavail: number;
215
+ /** Total file nodes in file system. */
216
+ files: number;
217
+ /** Free file nodes in file system. */
218
+ ffree: number;
219
+ }
220
+ export declare class BigIntStatsFs implements Node.StatsFsBase<bigint> {
221
+ /** Type of file system. */
222
+ type: bigint;
223
+ /** Optimal transfer block size. */
224
+ bsize: bigint;
225
+ /** Total data blocks in file system. */
226
+ blocks: bigint;
227
+ /** Free blocks in file system. */
228
+ bfree: bigint;
229
+ /** Available blocks for unprivileged users */
230
+ bavail: bigint;
231
+ /** Total file nodes in file system. */
232
+ files: bigint;
233
+ /** Free file nodes in file system. */
234
+ ffree: bigint;
235
+ }
package/dist/stats.js CHANGED
@@ -235,34 +235,7 @@ export class BigIntStats extends StatsCommon {
235
235
  return new BigIntStats(stats);
236
236
  }
237
237
  }
238
- BigIntStats;
239
- /**
240
- * @returns true if stats is a file.
241
- */
242
- export function isFile(stats) {
243
- return (Number(stats.mode) & S_IFMT) === S_IFREG;
244
- }
245
- /**
246
- * @returns True if stats is a directory.
247
- */
248
- export function isDirectory(stats) {
249
- return (Number(stats.mode) & S_IFMT) === S_IFDIR;
250
- }
251
- /**
252
- * @returns true if stats is a symbolic link
253
- */
254
- export function isSymbolicLink(stats) {
255
- return (Number(stats.mode) & S_IFMT) === S_IFLNK;
256
- }
257
- export function isSocket() {
258
- return false;
259
- }
260
- export function isBlockDevice() {
261
- return false;
262
- }
263
- export function isCharacterDevice() {
264
- return false;
238
+ export class StatsFs {
265
239
  }
266
- export function isFIFO() {
267
- return false;
240
+ export class BigIntStatsFs {
268
241
  }
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import { FileSystem } from './filesystem.js';
3
2
  import { Cred } from './cred.js';
4
3
  declare global {
@@ -25,12 +24,12 @@ export declare const setImmediate: (callback: () => unknown) => void;
25
24
  * Encodes a string into a buffer
26
25
  * @internal
27
26
  */
28
- export declare function encode(input: string, encoding?: BufferEncoding): Uint8Array;
27
+ export declare function encode(input: string): Uint8Array;
29
28
  /**
30
29
  * Decodes a string from a buffer
31
30
  * @internal
32
31
  */
33
- export declare function decode(input?: Uint8Array, encoding?: BufferEncoding): string;
32
+ export declare function decode(input?: Uint8Array): string;
34
33
  /**
35
34
  * Decodes a directory listing
36
35
  * @internal
package/dist/utils.js CHANGED
@@ -97,109 +97,23 @@ export const setImmediate = typeof globalThis.setImmediate == 'function' ? globa
97
97
  * Encodes a string into a buffer
98
98
  * @internal
99
99
  */
100
- export function encode(input, encoding = 'utf8') {
100
+ export function encode(input) {
101
101
  if (typeof input != 'string') {
102
102
  throw new ApiError(ErrorCode.EINVAL, 'Can not encode a non-string');
103
103
  }
104
- switch (encoding) {
105
- case 'ascii':
106
- return new Uint8Array(Array.from(input).map(char => char.charCodeAt(0) & 0x7f));
107
- case 'latin1':
108
- case 'binary':
109
- return new Uint8Array(Array.from(input).map(char => char.charCodeAt(0)));
110
- case 'utf8':
111
- case 'utf-8':
112
- return new Uint8Array(Array.from(input).flatMap(char => {
113
- const code = char.charCodeAt(0);
114
- if (code < 0x80) {
115
- return code;
116
- }
117
- const a = (code & 0x3f) | 0x80;
118
- if (code < 0x800) {
119
- return [(code >> 6) | 0xc0, a];
120
- }
121
- const b = ((code >> 6) & 0x3f) | 0x80;
122
- if (code < 0x10000) {
123
- return [(code >> 12) | 0xe0, b, a];
124
- }
125
- return [(code >> 18) | 0xf0, ((code >> 12) & 0x3f) | 0x80, b, a];
126
- }));
127
- case 'base64':
128
- return encode(atob(input), 'binary');
129
- case 'base64url':
130
- return encode(input.replace('_', '/').replace('-', '+'), 'base64');
131
- case 'hex':
132
- return new Uint8Array(input.match(/.{1,2}/g).map(e => parseInt(e, 16)));
133
- case 'utf16le':
134
- case 'ucs2':
135
- case 'ucs-2':
136
- const u16 = new Uint16Array(new ArrayBuffer(input.length * 2));
137
- for (let i = 0; i < input.length; i++) {
138
- u16[i] = input.charCodeAt(i);
139
- }
140
- return new Uint8Array(u16.buffer);
141
- default:
142
- throw new ApiError(ErrorCode.EINVAL, 'Invalid encoding: ' + encoding);
143
- }
104
+ return new Uint8Array(Array.from(input).map(char => char.charCodeAt(0)));
144
105
  }
145
106
  /**
146
107
  * Decodes a string from a buffer
147
108
  * @internal
148
109
  */
149
- export function decode(input, encoding = 'utf8') {
110
+ export function decode(input) {
150
111
  if (!(input instanceof Uint8Array)) {
151
112
  throw new ApiError(ErrorCode.EINVAL, 'Can not decode a non-Uint8Array');
152
113
  }
153
- switch (encoding) {
154
- case 'ascii':
155
- return Array.from(input)
156
- .map(char => String.fromCharCode(char & 0x7f))
157
- .join('');
158
- case 'latin1':
159
- case 'binary':
160
- return Array.from(input)
161
- .map(char => String.fromCharCode(char))
162
- .join('');
163
- case 'utf8':
164
- case 'utf-8':
165
- let utf8String = '';
166
- for (let i = 0; i < input.length; i++) {
167
- let code;
168
- if (input[i] < 0x80) {
169
- code = input[i];
170
- }
171
- else if (input[i] < 0xe0) {
172
- code = ((input[i] & 0x1f) << 6) | (input[++i] & 0x3f);
173
- }
174
- else if (input[i] < 0xf0) {
175
- code = ((input[i] & 0x0f) << 12) | ((input[++i] & 0x3f) << 6) | (input[++i] & 0x3f);
176
- }
177
- else {
178
- code = ((input[i] & 0x07) << 18) | ((input[++i] & 0x3f) << 12) | ((input[++i] & 0x3f) << 6) | (input[++i] & 0x3f);
179
- }
180
- utf8String += String.fromCharCode(code);
181
- }
182
- return utf8String;
183
- case 'utf16le':
184
- case 'ucs2':
185
- case 'ucs-2':
186
- let utf16leString = '';
187
- for (let i = 0; i < input.length; i += 2) {
188
- const code = input[i] | (input[i + 1] << 8);
189
- utf16leString += String.fromCharCode(code);
190
- }
191
- return utf16leString;
192
- case 'base64':
193
- return btoa(decode(input, 'binary'));
194
- case 'base64url':
195
- return decode(input, 'base64').replace('/', '_').replace('+', '-');
196
- case 'hex':
197
- return Array.from(input)
198
- .map(e => e.toString(16).padStart(2, '0'))
199
- .join('');
200
- default:
201
- throw new ApiError(ErrorCode.EINVAL, 'Invalid encoding: ' + encoding);
202
- }
114
+ return Array.from(input)
115
+ .map(char => String.fromCharCode(char))
116
+ .join('');
203
117
  }
204
118
  /**
205
119
  * Decodes a directory listing