@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.
@@ -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.
@@ -134,17 +148,21 @@ export declare class FileHandle implements BufferToUint8Array<Node.promises.File
134
148
  */
135
149
  writeFile(data: string | Uint8Array, _options?: Node.WriteFileOptions): Promise<void>;
136
150
  /**
137
- * See `fs.writev` promisified version.
151
+ * Asynchronous close(2) - close a `FileHandle`.
138
152
  */
139
- writev(buffers: ReadonlyArray<Uint8Array>, position?: number): Promise<Node.WriteVResult>;
153
+ close(): Promise<void>;
140
154
  /**
141
- * See `fs.readv` promisified version.
155
+ * See `fs.writev` promisified version.
156
+ * @todo Implement
142
157
  */
143
- readv(buffers: ReadonlyArray<Uint8Array>, position?: number): Promise<Node.ReadVResult>;
158
+ writev(buffers: NodeJS.ArrayBufferView[], position?: number): Promise<Node.WriteVResult>;
144
159
  /**
145
- * Asynchronous close(2) - close a `FileHandle`.
160
+ * See `fs.readv` promisified version.
161
+ * @todo Implement
146
162
  */
147
- close(): Promise<void>;
163
+ readv(buffers: readonly NodeJS.ArrayBufferView[], position?: number): Promise<Node.ReadVResult>;
164
+ createReadStream(options?: CreateReadStreamOptions): Node.ReadStream;
165
+ createWriteStream(options?: CreateWriteStreamOptions): Node.WriteStream;
148
166
  }
149
167
  /**
150
168
  * Renames a file
@@ -213,8 +231,8 @@ 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: (Node.BaseEncodingOptions & {
234
+ }): Promise<Buffer>;
235
+ export declare function readFile(filename: PathLike, options: (Node.EncodingOption & {
218
236
  flag?: Node.OpenMode;
219
237
  }) | BufferEncoding): Promise<string>;
220
238
  /**
@@ -239,64 +257,10 @@ export declare function writeFile(filename: PathLike, data: FileContents, _optio
239
257
  * @option options mode Defaults to `0644`.
240
258
  * @option options flag Defaults to `'a'`.
241
259
  */
242
- 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 & {
243
261
  mode?: Node.Mode;
244
262
  flag?: Node.OpenMode;
245
263
  })): Promise<void>;
246
- /**
247
- * Write buffer to the file specified by `fd`.
248
- * Note that it is unsafe to use fs.write multiple times on the same file without waiting for it to return.
249
- * @param handle
250
- * @param data Uint8Array containing the data to write to the file.
251
- * @param offset Offset in the buffer to start reading data from.
252
- * @param length The amount of bytes to write to the file.
253
- * @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.
254
- */
255
- export declare function write(handle: FileHandle, data: Uint8Array, offset: number, length: number, position?: number): Promise<{
256
- bytesWritten: number;
257
- buffer: Uint8Array;
258
- }>;
259
- export declare function write(handle: FileHandle, data: string, position?: number, encoding?: BufferEncoding): Promise<{
260
- bytesWritten: number;
261
- buffer: string;
262
- }>;
263
- /**
264
- * Read data from the file specified by `fd`.
265
- * @param handle
266
- * @param buffer The buffer that the data will be
267
- * written to.
268
- * @param offset The offset within the buffer where writing will
269
- * start.
270
- * @param length An integer specifying the number of bytes to read.
271
- * @param position An integer specifying where to begin reading from
272
- * in the file. If position is null, data will be read from the current file
273
- * position.
274
- */
275
- export declare function read(handle: FileHandle, buffer: Uint8Array, offset: number, length: number, position?: number): Promise<{
276
- bytesRead: number;
277
- buffer: Uint8Array;
278
- }>;
279
- /**
280
- * `fchown`.
281
- * @param handle
282
- * @param uid
283
- * @param gid
284
- */
285
- export declare function fchown(handle: FileHandle, uid: number, gid: number): Promise<void>;
286
- /**
287
- * `fchmod`.
288
- * @param handle
289
- * @param mode
290
- */
291
- export declare function fchmod(handle: FileHandle, mode: Node.Mode): Promise<void>;
292
- /**
293
- * Change the file timestamps of a file referenced by the supplied file
294
- * descriptor.
295
- * @param handle
296
- * @param atime
297
- * @param mtime
298
- */
299
- export declare function futimes(handle: FileHandle, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
300
264
  /**
301
265
  * `rmdir`.
302
266
  * @param path
@@ -317,13 +281,13 @@ export declare function mkdir(path: PathLike, mode: Node.MakeDirectoryOptions &
317
281
  * `readdir`. Reads the contents of a directory.
318
282
  * @param path
319
283
  */
320
- export declare function readdir(path: PathLike, options?: (Node.BaseEncodingOptions & {
284
+ export declare function readdir(path: PathLike, options?: (Node.EncodingOption & {
321
285
  withFileTypes?: false;
322
286
  }) | BufferEncoding): Promise<string[]>;
323
287
  export declare function readdir(path: PathLike, options: Node.BufferEncodingOption & {
324
288
  withFileTypes?: false;
325
- }): Promise<Uint8Array[]>;
326
- export declare function readdir(path: PathLike, options: Node.BaseEncodingOptions & {
289
+ }): Promise<Buffer[]>;
290
+ export declare function readdir(path: PathLike, options: Node.EncodingOption & {
327
291
  withFileTypes: true;
328
292
  }): Promise<Dirent[]>;
329
293
  /**
@@ -343,8 +307,8 @@ export declare function symlink(target: PathLike, path: PathLike, type?: Node.sy
343
307
  * readlink.
344
308
  * @param path
345
309
  */
346
- export declare function readlink(path: PathLike, options: Node.BufferEncodingOption): Promise<Uint8Array>;
347
- 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>;
348
312
  /**
349
313
  * `chown`.
350
314
  * @param path
@@ -392,37 +356,47 @@ export declare function lutimes(path: PathLike, atime: number | Date, mtime: num
392
356
  *
393
357
  * Note: This *Can not* use doOp since doOp depends on it
394
358
  */
395
- export declare function realpath(path: PathLike, options: Node.BufferEncodingOption): Promise<Uint8Array>;
396
- export declare function realpath(path: PathLike, options?: Node.BaseEncodingOptions | BufferEncoding): Promise<string>;
397
- export declare function watchFile(filename: PathLike, listener: (curr: Stats, prev: Stats) => void): Promise<void>;
398
- export declare function watchFile(filename: PathLike, options: {
399
- persistent?: boolean;
400
- interval?: number;
401
- }, listener: (curr: Stats, prev: Stats) => void): Promise<void>;
402
- export declare function unwatchFile(filename: PathLike, listener?: (curr: Stats, prev: Stats) => void): Promise<void>;
403
- export declare function watch(filename: PathLike, listener?: (event: string, filename: PathLike) => any): Promise<Node.FSWatcher>;
404
- export declare function watch(filename: PathLike, options: {
405
- persistent?: boolean;
406
- }, 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>>;
407
368
  /**
408
369
  * `access`.
409
370
  * @param path
410
371
  * @param mode
411
372
  */
412
373
  export declare function access(path: PathLike, mode?: number): Promise<void>;
413
- export declare function createReadStream(path: PathLike, options?: {
414
- flags?: string;
415
- encoding?: string;
416
- fd?: number;
417
- mode?: number;
418
- autoClose?: boolean;
419
- }): Promise<Node.ReadStream>;
420
- export declare function createWriteStream(path: PathLike, options?: {
421
- flags?: string;
422
- encoding?: string;
423
- fd?: number;
424
- mode?: number;
425
- }): Promise<Node.WriteStream>;
426
- export declare function rm(path: PathLike): Promise<void>;
427
- export declare function mkdtemp(path: PathLike): Promise<void>;
428
- 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>;
@@ -1,12 +1,12 @@
1
+ import { Buffer } from 'buffer';
1
2
  import { ApiError, ErrorCode } from '../ApiError.js';
2
- export * as constants from './constants.js';
3
- import { ActionType, isReadable, isWriteable, isAppendable, parseFlag, pathExistsAction, pathNotExistsAction } from '../file.js';
4
- import { normalizePath, normalizeMode, getFdForFile, normalizeOptions, fd2file, fdMap, normalizeTime, cred, nop, resolveFS, fixError, mounts } from './shared.js';
3
+ import { ActionType, isAppendable, isReadable, isWriteable, parseFlag, pathExistsAction, pathNotExistsAction } from '../file.js';
5
4
  import { BigIntStats, FileType } from '../stats.js';
6
- import { decode, encode } from '../utils.js';
5
+ import { F_OK } from './constants.js';
7
6
  import { Dirent } from './dir.js';
8
7
  import { dirname, join } from './path.js';
9
- import { F_OK } from './constants.js';
8
+ import { cred, fd2file, fdMap, fixError, getFdForFile, mounts, normalizeMode, normalizeOptions, normalizePath, normalizeTime, resolveFS } from './shared.js';
9
+ export * as constants from './constants.js';
10
10
  export class FileHandle {
11
11
  constructor(
12
12
  /**
@@ -15,11 +15,17 @@ export class FileHandle {
15
15
  fd) {
16
16
  this.fd = fd;
17
17
  }
18
+ get file() {
19
+ return fd2file(this.fd);
20
+ }
21
+ get path() {
22
+ return this.file.path;
23
+ }
18
24
  /**
19
25
  * Asynchronous fchown(2) - Change ownership of a file.
20
26
  */
21
27
  chown(uid, gid) {
22
- return fd2file(this.fd).chown(uid, gid);
28
+ return this.file.chown(uid, gid);
23
29
  }
24
30
  /**
25
31
  * Asynchronous fchmod(2) - Change permissions of a file.
@@ -30,19 +36,19 @@ export class FileHandle {
30
36
  if (numMode < 0) {
31
37
  throw new ApiError(ErrorCode.EINVAL, 'Invalid mode.');
32
38
  }
33
- return fd2file(this.fd).chmod(numMode);
39
+ return this.file.chmod(numMode);
34
40
  }
35
41
  /**
36
42
  * Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.
37
43
  */
38
44
  datasync() {
39
- return fd2file(this.fd).datasync();
45
+ return this.file.datasync();
40
46
  }
41
47
  /**
42
48
  * Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
43
49
  */
44
50
  sync() {
45
- return fd2file(this.fd).sync();
51
+ return this.file.sync();
46
52
  }
47
53
  /**
48
54
  * Asynchronous ftruncate(2) - Truncate a file to a specified length.
@@ -52,7 +58,7 @@ export class FileHandle {
52
58
  if (len < 0) {
53
59
  throw new ApiError(ErrorCode.EINVAL);
54
60
  }
55
- return fd2file(this.fd).truncate(len);
61
+ return this.file.truncate(len);
56
62
  }
57
63
  /**
58
64
  * Asynchronously change file timestamps of the file.
@@ -60,7 +66,7 @@ export class FileHandle {
60
66
  * @param mtime The last modified time. If a string is provided, it will be coerced to number.
61
67
  */
62
68
  utimes(atime, mtime) {
63
- return fd2file(this.fd).utimes(normalizeTime(atime), normalizeTime(mtime));
69
+ return this.file.utimes(normalizeTime(atime), normalizeTime(mtime));
64
70
  }
65
71
  /**
66
72
  * Asynchronously append data to a file, creating the file if it does not exist. The underlying file will _not_ be closed automatically.
@@ -81,8 +87,8 @@ export class FileHandle {
81
87
  if (typeof data != 'string' && !options.encoding) {
82
88
  throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
83
89
  }
84
- const encodedData = typeof data == 'string' ? encode(data) : data;
85
- await fd2file(this.fd).write(encodedData, 0, encodedData.length, null);
90
+ const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : data;
91
+ await this.file.write(encodedData, 0, encodedData.length, null);
86
92
  }
87
93
  /**
88
94
  * Asynchronously reads data from the file.
@@ -94,9 +100,9 @@ export class FileHandle {
94
100
  */
95
101
  read(buffer, offset, length, position) {
96
102
  if (isNaN(+position)) {
97
- position = fd2file(this.fd).position;
103
+ position = this.file.position;
98
104
  }
99
- return fd2file(this.fd).read(buffer, offset, length, position);
105
+ return this.file.read(buffer, offset, length, position);
100
106
  }
101
107
  async readFile(_options) {
102
108
  const options = normalizeOptions(_options, null, 'r', 0o444);
@@ -106,11 +112,32 @@ export class FileHandle {
106
112
  }
107
113
  const { size } = await this.stat();
108
114
  const data = new Uint8Array(size);
109
- await fd2file(this.fd).read(data, 0, size, 0);
110
- return options.encoding ? decode(data, options.encoding) : data;
115
+ await this.file.read(data, 0, size, 0);
116
+ const buffer = Buffer.from(data);
117
+ return options.encoding ? buffer.toString(options.encoding) : buffer;
118
+ }
119
+ /**
120
+ * Returns a `ReadableStream` that may be used to read the files data.
121
+ *
122
+ * An error will be thrown if this method is called more than once or is called after the `FileHandle` is closed
123
+ * or closing.
124
+ *
125
+ * 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.
126
+ *
127
+ * @since v17.0.0
128
+ * @experimental
129
+ */
130
+ readableWebStream(options) {
131
+ throw ApiError.With('ENOTSUP', this.path, 'FileHandle.readableWebStream');
132
+ }
133
+ readLines(options) {
134
+ throw ApiError.With('ENOTSUP', this.path, 'FileHandle.readLines');
135
+ }
136
+ [Symbol.asyncDispose]() {
137
+ throw ApiError.With('ENOTSUP', this.path, 'FileHandle.@@asyncDispose');
111
138
  }
112
139
  async stat(opts) {
113
- const stats = await fd2file(this.fd).stat();
140
+ const stats = await this.file.stat();
114
141
  return opts?.bigint ? new BigIntStats(stats) : stats;
115
142
  }
116
143
  async write(data, posOrOff, lenOrEnc, position) {
@@ -120,7 +147,7 @@ export class FileHandle {
120
147
  position = typeof posOrOff === 'number' ? posOrOff : null;
121
148
  const encoding = (typeof lenOrEnc === 'string' ? lenOrEnc : 'utf8');
122
149
  offset = 0;
123
- buffer = encode(data, encoding);
150
+ buffer = Buffer.from(data, encoding);
124
151
  length = buffer.length;
125
152
  }
126
153
  else {
@@ -130,8 +157,8 @@ export class FileHandle {
130
157
  length = lenOrEnc;
131
158
  position = typeof position === 'number' ? position : null;
132
159
  }
133
- position ?? (position = fd2file(this.fd).position);
134
- const bytesWritten = await fd2file(this.fd).write(buffer, offset, length, position);
160
+ position ?? (position = this.file.position);
161
+ const bytesWritten = await this.file.write(buffer, offset, length, position);
135
162
  return { buffer, bytesWritten };
136
163
  }
137
164
  /**
@@ -154,27 +181,36 @@ export class FileHandle {
154
181
  if (typeof data != 'string' && !options.encoding) {
155
182
  throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
156
183
  }
157
- const encodedData = typeof data == 'string' ? encode(data, options.encoding) : data;
158
- await fd2file(this.fd).write(encodedData, 0, encodedData.length, 0);
184
+ const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : data;
185
+ await this.file.write(encodedData, 0, encodedData.length, 0);
159
186
  }
187
+ /**
188
+ * Asynchronous close(2) - close a `FileHandle`.
189
+ */
190
+ async close() {
191
+ await this.file.close();
192
+ fdMap.delete(this.fd);
193
+ }
194
+ /* eslint-disable @typescript-eslint/no-unused-vars */
160
195
  /**
161
196
  * See `fs.writev` promisified version.
197
+ * @todo Implement
162
198
  */
163
199
  writev(buffers, position) {
164
- throw new ApiError(ErrorCode.ENOTSUP);
200
+ throw ApiError.With('ENOTSUP', this.path, 'FileHandle.writev');
165
201
  }
166
202
  /**
167
203
  * See `fs.readv` promisified version.
204
+ * @todo Implement
168
205
  */
169
206
  readv(buffers, position) {
170
- throw new ApiError(ErrorCode.ENOTSUP);
207
+ throw ApiError.With('ENOTSUP', this.path, 'FileHandle.readv');
171
208
  }
172
- /**
173
- * Asynchronous close(2) - close a `FileHandle`.
174
- */
175
- async close() {
176
- await fd2file(this.fd).close();
177
- fdMap.delete(this.fd);
209
+ createReadStream(options) {
210
+ throw ApiError.With('ENOTSUP', this.path, 'createReadStream');
211
+ }
212
+ createWriteStream(options) {
213
+ throw ApiError.With('ENOTSUP', this.path, 'createWriteStream');
178
214
  }
179
215
  }
180
216
  /**
@@ -363,8 +399,8 @@ export async function readFile(filename, _options) {
363
399
  if (!isReadable(flag)) {
364
400
  throw new ApiError(ErrorCode.EINVAL, 'Flag passed must allow for reading.');
365
401
  }
366
- const data = await _readFile(filename, options.flag, true);
367
- return options.encoding ? decode(data, options.encoding) : data;
402
+ const data = Buffer.from(await _readFile(filename, options.flag, true));
403
+ return options.encoding ? data.toString(options.encoding) : data;
368
404
  }
369
405
  readFile;
370
406
  /**
@@ -421,60 +457,10 @@ export async function appendFile(filename, data, _options) {
421
457
  if (typeof data != 'string' && !options.encoding) {
422
458
  throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
423
459
  }
424
- const encodedData = typeof data == 'string' ? encode(data) : data;
460
+ const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : data;
425
461
  await _appendFile(filename, encodedData, options.flag, options.mode, true);
426
462
  }
427
463
  appendFile;
428
- export function write(handle, data, posOrOff, lenOrEnc, position) {
429
- return handle.write(data, posOrOff, lenOrEnc, position);
430
- }
431
- write;
432
- /**
433
- * Read data from the file specified by `fd`.
434
- * @param handle
435
- * @param buffer The buffer that the data will be
436
- * written to.
437
- * @param offset The offset within the buffer where writing will
438
- * start.
439
- * @param length An integer specifying the number of bytes to read.
440
- * @param position An integer specifying where to begin reading from
441
- * in the file. If position is null, data will be read from the current file
442
- * position.
443
- */
444
- export function read(handle, buffer, offset, length, position) {
445
- return handle.read(buffer, offset, length, position);
446
- }
447
- read;
448
- /**
449
- * `fchown`.
450
- * @param handle
451
- * @param uid
452
- * @param gid
453
- */
454
- export function fchown(handle, uid, gid) {
455
- return handle.chown(uid, gid);
456
- }
457
- fchown;
458
- /**
459
- * `fchmod`.
460
- * @param handle
461
- * @param mode
462
- */
463
- export function fchmod(handle, mode) {
464
- return handle.chmod(mode);
465
- }
466
- fchmod;
467
- /**
468
- * Change the file timestamps of a file referenced by the supplied file
469
- * descriptor.
470
- * @param handle
471
- * @param atime
472
- * @param mtime
473
- */
474
- export function futimes(handle, atime, mtime) {
475
- return handle.utimes(atime, mtime);
476
- }
477
- futimes;
478
464
  // DIRECTORY-ONLY METHODS
479
465
  /**
480
466
  * `rmdir`.
@@ -539,12 +525,12 @@ export async function symlink(target, path, type = 'file') {
539
525
  }
540
526
  symlink;
541
527
  export async function readlink(path, options) {
542
- const value = await _readFile(path, 'r', false);
528
+ const value = Buffer.from(await _readFile(path, 'r', false));
543
529
  const encoding = typeof options == 'object' ? options.encoding : options;
544
530
  if (encoding == 'buffer') {
545
531
  return value;
546
532
  }
547
- return decode(value, encoding);
533
+ return value.toString(encoding);
548
534
  }
549
535
  readlink;
550
536
  // PROPERTY OPERATIONS
@@ -650,7 +636,7 @@ export async function realpath(path, options) {
650
636
  if (!stats.isSymbolicLink()) {
651
637
  return path;
652
638
  }
653
- const dst = mountPoint + normalizePath(decode(await _readFile(resolvedPath, 'r+', false)));
639
+ const dst = mountPoint + normalizePath(Buffer.from(await _readFile(resolvedPath, 'r+', false)).toString());
654
640
  return realpath(dst);
655
641
  }
656
642
  catch (e) {
@@ -658,15 +644,10 @@ export async function realpath(path, options) {
658
644
  }
659
645
  }
660
646
  realpath;
661
- export async function watchFile(filename, arg2, listener = nop) {
662
- throw new ApiError(ErrorCode.ENOTSUP);
663
- }
664
- export async function unwatchFile(filename, listener = nop) {
665
- throw new ApiError(ErrorCode.ENOTSUP);
666
- }
667
- export async function watch(filename, arg2, listener = nop) {
668
- throw new ApiError(ErrorCode.ENOTSUP);
647
+ export function watch(filename, options) {
648
+ throw ApiError.With('ENOTSUP', filename, 'watch');
669
649
  }
650
+ watch;
670
651
  /**
671
652
  * `access`.
672
653
  * @param path
@@ -678,18 +659,38 @@ export async function access(path, mode = F_OK) {
678
659
  throw new ApiError(ErrorCode.EACCES);
679
660
  }
680
661
  }
681
- export async function createReadStream(path, options) {
682
- throw new ApiError(ErrorCode.ENOTSUP);
662
+ access;
663
+ /* eslint-disable @typescript-eslint/no-unused-vars */
664
+ /**
665
+ * @todo Implement
666
+ */
667
+ export async function rm(path, options) {
668
+ throw ApiError.With('ENOTSUP', path, 'rm');
669
+ }
670
+ rm;
671
+ export async function mkdtemp(prefix, options) {
672
+ throw ApiError.With('ENOTSUP', prefix, 'mkdtemp');
683
673
  }
684
- export async function createWriteStream(path, options) {
685
- throw new ApiError(ErrorCode.ENOTSUP);
674
+ mkdtemp;
675
+ /**
676
+ * @todo Implement
677
+ */
678
+ export async function copyFile(src, dest, mode) {
679
+ throw ApiError.With('ENOTSUP', src, 'copyFile');
686
680
  }
687
- export async function rm(path) {
688
- throw new ApiError(ErrorCode.ENOTSUP);
681
+ copyFile;
682
+ /**
683
+ * @todo Implement
684
+ */
685
+ export async function opendir(path, options) {
686
+ throw ApiError.With('ENOTSUP', path, 'opendir');
689
687
  }
690
- export async function mkdtemp(path) {
691
- throw new ApiError(ErrorCode.ENOTSUP);
688
+ opendir;
689
+ export async function cp(source, destination, opts) {
690
+ throw ApiError.With('ENOTSUP', source, 'cp');
692
691
  }
693
- export async function copyFile(path) {
694
- throw new ApiError(ErrorCode.ENOTSUP);
692
+ cp;
693
+ export async function statfs(path, opts) {
694
+ throw ApiError.With('ENOTSUP', path, 'statfs');
695
695
  }
696
+ /* eslint-enable @typescript-eslint/no-unused-vars */