@zenfs/core 2.4.1 → 2.4.2
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.
- package/COPYING.md +18 -0
- package/{readme.md → README.md} +16 -74
- package/dist/backends/fetch.js +1 -1
- package/dist/backends/memory.js +1 -1
- package/dist/backends/passthrough.d.ts +1 -2
- package/dist/backends/single_buffer.js +1 -1
- package/dist/backends/store/fs.js +4 -4
- package/dist/config.js +15 -15
- package/dist/context.js +3 -2
- package/dist/index.d.ts +9 -3
- package/dist/index.js +9 -4
- package/dist/internal/contexts.d.ts +5 -4
- package/dist/internal/devices.js +1 -1
- package/dist/internal/error.d.ts +11 -2
- package/dist/internal/error.js +38 -2
- package/dist/internal/file_index.js +1 -1
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +2 -1
- package/dist/internal/index_fs.js +1 -1
- package/dist/internal/inode.d.ts +51 -2
- package/dist/internal/inode.js +18 -2
- package/dist/mixins/shared.js +1 -1
- package/dist/node/async.d.ts +278 -0
- package/dist/node/async.js +518 -0
- package/dist/node/compat.d.ts +4 -0
- package/dist/node/compat.js +6 -0
- package/dist/node/dir.d.ts +78 -0
- package/dist/node/dir.js +150 -0
- package/dist/node/index.d.ts +8 -0
- package/dist/node/index.js +8 -0
- package/dist/{vfs → node}/promises.d.ts +10 -66
- package/dist/{vfs → node}/promises.js +141 -478
- package/dist/{vfs → node}/stats.d.ts +0 -4
- package/dist/{vfs → node}/stats.js +1 -16
- package/dist/{vfs → node}/streams.js +2 -2
- package/dist/node/sync.d.ts +252 -0
- package/dist/node/sync.js +682 -0
- package/dist/node/types.d.ts +21 -0
- package/dist/utils.d.ts +1 -7
- package/dist/utils.js +0 -6
- package/dist/vfs/acl.js +1 -1
- package/dist/vfs/async.d.ts +22 -278
- package/dist/vfs/async.js +212 -501
- package/dist/vfs/dir.d.ts +5 -82
- package/dist/vfs/dir.js +5 -233
- package/dist/vfs/file.d.ts +52 -13
- package/dist/vfs/file.js +167 -25
- package/dist/vfs/flags.js +1 -1
- package/dist/vfs/index.d.ts +2 -5
- package/dist/vfs/index.js +2 -5
- package/dist/vfs/shared.d.ts +25 -1
- package/dist/vfs/shared.js +6 -4
- package/dist/vfs/sync.d.ts +17 -245
- package/dist/vfs/sync.js +129 -773
- package/dist/vfs/watchers.d.ts +1 -1
- package/dist/vfs/watchers.js +2 -2
- package/dist/vfs/xattr.js +1 -1
- package/eslint.shared.js +1 -0
- package/package.json +7 -5
- package/scripts/make-index.js +5 -29
- package/scripts/test.js +59 -51
- package/tests/backend/fetch.test.ts +2 -2
- package/tests/backend/port.test.ts +2 -3
- package/tests/backend/single-buffer.test.ts +1 -1
- package/tests/common/casefold.test.ts +1 -1
- package/tests/common/context.test.ts +11 -4
- package/tests/common/devices.test.ts +3 -3
- package/tests/common/handle.test.ts +4 -3
- package/tests/common/inode.test.ts +2 -2
- package/tests/common/mounts.test.ts +1 -3
- package/tests/common/mutex.test.ts +1 -3
- package/tests/common/path.test.ts +2 -2
- package/tests/common/readline.test.ts +1 -1
- package/tests/common.ts +5 -4
- package/tests/fetch/fetch.ts +1 -1
- package/tests/fs/dir.test.ts +3 -43
- package/tests/fs/directory.test.ts +4 -4
- package/tests/fs/errors.test.ts +2 -2
- package/tests/fs/links.test.ts +1 -1
- package/tests/fs/permissions.test.ts +3 -3
- package/tests/fs/read.test.ts +1 -1
- package/tests/fs/scaling.test.ts +1 -1
- package/tests/fs/stat.test.ts +1 -2
- package/tests/fs/times.test.ts +1 -1
- package/tests/fs/watch.test.ts +3 -2
- package/tests/setup/context.ts +1 -2
- package/tests/setup/cow.ts +1 -1
- package/tests/setup/index.ts +2 -2
- package/tests/setup/port.ts +1 -1
- package/tests/setup/single-buffer.ts +1 -1
- package/tests/setup.ts +4 -3
- package/dist/vfs/types.d.ts +0 -24
- package/tests/assignment.ts +0 -21
- /package/dist/{vfs/constants.d.ts → constants.d.ts} +0 -0
- /package/dist/{vfs/constants.js → constants.js} +0 -0
- /package/dist/{readline.d.ts → node/readline.d.ts} +0 -0
- /package/dist/{readline.js → node/readline.js} +0 -0
- /package/dist/{vfs → node}/streams.d.ts +0 -0
- /package/dist/{vfs → node}/types.js +0 -0
package/dist/node/dir.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
import { withErrno } from 'kerium';
|
|
3
|
+
import { warn } from 'kerium/log';
|
|
4
|
+
import { parse } from '../path.js';
|
|
5
|
+
import { DirType } from '../vfs/dir.js';
|
|
6
|
+
import { readdir } from './promises.js';
|
|
7
|
+
import { readdirSync } from './sync.js';
|
|
8
|
+
export class Dirent {
|
|
9
|
+
ino;
|
|
10
|
+
type;
|
|
11
|
+
_name;
|
|
12
|
+
get name() {
|
|
13
|
+
const name = Buffer.from(this._name);
|
|
14
|
+
return (this._encoding == 'buffer' ? name : name.toString(this._encoding));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @internal @protected
|
|
18
|
+
*/
|
|
19
|
+
_encoding;
|
|
20
|
+
/**
|
|
21
|
+
* @internal @protected
|
|
22
|
+
*/
|
|
23
|
+
_parentPath;
|
|
24
|
+
get parentPath() {
|
|
25
|
+
return this._parentPath;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated Removed in Node v24, use `parentPath` instead.
|
|
29
|
+
*/
|
|
30
|
+
get path() {
|
|
31
|
+
warn('Dirent.path was removed in Node v24, use parentPath instead');
|
|
32
|
+
return this._parentPath;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
static from(vfs, encoding) {
|
|
38
|
+
const dirent = new Dirent();
|
|
39
|
+
const { base, dir } = parse(vfs.path);
|
|
40
|
+
dirent._parentPath = dir || '.';
|
|
41
|
+
dirent._name = base;
|
|
42
|
+
dirent.ino = vfs.ino;
|
|
43
|
+
dirent.type = vfs.type;
|
|
44
|
+
dirent._encoding = encoding;
|
|
45
|
+
return dirent;
|
|
46
|
+
}
|
|
47
|
+
isFile() {
|
|
48
|
+
return this.type === DirType.REG;
|
|
49
|
+
}
|
|
50
|
+
isDirectory() {
|
|
51
|
+
return this.type === DirType.DIR;
|
|
52
|
+
}
|
|
53
|
+
isBlockDevice() {
|
|
54
|
+
return this.type === DirType.BLK;
|
|
55
|
+
}
|
|
56
|
+
isCharacterDevice() {
|
|
57
|
+
return this.type === DirType.CHR;
|
|
58
|
+
}
|
|
59
|
+
isSymbolicLink() {
|
|
60
|
+
return this.type === DirType.LNK;
|
|
61
|
+
}
|
|
62
|
+
isFIFO() {
|
|
63
|
+
return this.type === DirType.FIFO;
|
|
64
|
+
}
|
|
65
|
+
isSocket() {
|
|
66
|
+
return this.type === DirType.SOCK;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A class representing a directory stream.
|
|
71
|
+
*/
|
|
72
|
+
export class Dir {
|
|
73
|
+
path;
|
|
74
|
+
context;
|
|
75
|
+
closed = false;
|
|
76
|
+
checkClosed() {
|
|
77
|
+
if (this.closed)
|
|
78
|
+
throw withErrno('EBADF', 'Can not use closed Dir');
|
|
79
|
+
}
|
|
80
|
+
_entries;
|
|
81
|
+
constructor(path, context) {
|
|
82
|
+
this.path = path;
|
|
83
|
+
this.context = context;
|
|
84
|
+
}
|
|
85
|
+
close(cb) {
|
|
86
|
+
this.closed = true;
|
|
87
|
+
if (!cb) {
|
|
88
|
+
return Promise.resolve();
|
|
89
|
+
}
|
|
90
|
+
cb(null);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Synchronously close the directory's underlying resource handle.
|
|
94
|
+
* Subsequent reads will result in errors.
|
|
95
|
+
*/
|
|
96
|
+
closeSync() {
|
|
97
|
+
this.closed = true;
|
|
98
|
+
}
|
|
99
|
+
async _read() {
|
|
100
|
+
this.checkClosed();
|
|
101
|
+
this._entries ??= await readdir.call(this.context, this.path, {
|
|
102
|
+
withFileTypes: true,
|
|
103
|
+
});
|
|
104
|
+
if (!this._entries.length)
|
|
105
|
+
return null;
|
|
106
|
+
return this._entries.shift() ?? null;
|
|
107
|
+
}
|
|
108
|
+
read(cb) {
|
|
109
|
+
if (!cb) {
|
|
110
|
+
return this._read();
|
|
111
|
+
}
|
|
112
|
+
void this._read().then(value => cb(null, value));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Synchronously read the next directory entry via `readdir(3)` as a `Dirent`.
|
|
116
|
+
* If there are no more directory entries to read, null will be returned.
|
|
117
|
+
* Directory entries returned by this function are in no particular order as provided by the operating system's underlying directory mechanisms.
|
|
118
|
+
*/
|
|
119
|
+
readSync() {
|
|
120
|
+
this.checkClosed();
|
|
121
|
+
this._entries ??= readdirSync.call(this.context, this.path, { withFileTypes: true });
|
|
122
|
+
if (!this._entries.length)
|
|
123
|
+
return null;
|
|
124
|
+
return this._entries.shift() ?? null;
|
|
125
|
+
}
|
|
126
|
+
async next() {
|
|
127
|
+
const value = await this._read();
|
|
128
|
+
if (value) {
|
|
129
|
+
return { done: false, value };
|
|
130
|
+
}
|
|
131
|
+
await this.close();
|
|
132
|
+
return { done: true, value: undefined };
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Asynchronously iterates over the directory via `readdir(3)` until all entries have been read.
|
|
136
|
+
*/
|
|
137
|
+
[Symbol.asyncIterator]() {
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
[Symbol.dispose]() {
|
|
141
|
+
if (this.closed)
|
|
142
|
+
return;
|
|
143
|
+
this.closeSync();
|
|
144
|
+
}
|
|
145
|
+
async [Symbol.asyncDispose]() {
|
|
146
|
+
if (this.closed)
|
|
147
|
+
return;
|
|
148
|
+
await this.close();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * as constants from '../constants.js';
|
|
2
|
+
export * from './async.js';
|
|
3
|
+
export * from './dir.js';
|
|
4
|
+
export * as promises from './promises.js';
|
|
5
|
+
export { BigIntStatsFs, Stats, StatsFs } from './stats.js';
|
|
6
|
+
export type { StatsLike } from './stats.js';
|
|
7
|
+
export * from './streams.js';
|
|
8
|
+
export * from './sync.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
2
|
+
export * as constants from '../constants.js';
|
|
3
|
+
export * from './async.js';
|
|
4
|
+
export * from './dir.js';
|
|
5
|
+
export * as promises from './promises.js';
|
|
6
|
+
export { BigIntStatsFs, Stats, StatsFs } from './stats.js';
|
|
7
|
+
export * from './streams.js';
|
|
8
|
+
export * from './sync.js';
|
|
@@ -4,53 +4,22 @@ import type * as promises from 'node:fs/promises';
|
|
|
4
4
|
import type { Stream } from 'node:stream';
|
|
5
5
|
import type { ReadableStream as NodeReadableStream } from 'node:stream/web';
|
|
6
6
|
import type { V_Context } from '../context.js';
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
9
|
-
import type { Interface as ReadlineInterface } from '
|
|
10
|
-
import type {
|
|
7
|
+
import type { StreamOptions } from '../internal/filesystem.js';
|
|
8
|
+
import type { FileContents } from '../vfs/shared.js';
|
|
9
|
+
import type { Interface as ReadlineInterface } from './readline.js';
|
|
10
|
+
import type { NodeReaddirOptions } from './types.js';
|
|
11
11
|
import { Buffer } from 'buffer';
|
|
12
12
|
import '../polyfills.js';
|
|
13
|
+
import type { Handle } from '../vfs/file.js';
|
|
13
14
|
import { Dir, Dirent } from './dir.js';
|
|
14
|
-
import { SyncHandle } from './file.js';
|
|
15
15
|
import { BigIntStats, Stats } from './stats.js';
|
|
16
16
|
import { ReadStream, WriteStream } from './streams.js';
|
|
17
|
-
export * as constants from '
|
|
17
|
+
export * as constants from '../constants.js';
|
|
18
18
|
export declare class FileHandle implements promises.FileHandle {
|
|
19
19
|
protected context: V_Context;
|
|
20
20
|
readonly fd: number;
|
|
21
|
-
protected
|
|
22
|
-
/**
|
|
23
|
-
* Get the current file position.
|
|
24
|
-
*
|
|
25
|
-
* We emulate the following bug mentioned in the Node documentation:
|
|
26
|
-
*
|
|
27
|
-
* On Linux, positional writes don't work when the file is opened in append mode.
|
|
28
|
-
* The kernel ignores the position argument and always appends the data to the end of the file.
|
|
29
|
-
* @returns The current file position.
|
|
30
|
-
*/
|
|
31
|
-
get position(): number;
|
|
32
|
-
set position(value: number);
|
|
33
|
-
/**
|
|
34
|
-
* Whether the file has changes which have not been written to the FS
|
|
35
|
-
*/
|
|
36
|
-
protected dirty: boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Whether the file is open or closed
|
|
39
|
-
*/
|
|
40
|
-
protected closed: boolean;
|
|
41
|
-
/** The path relative to the context's root */
|
|
42
|
-
get path(): string;
|
|
43
|
-
/** The internal FS associated with the handle */
|
|
44
|
-
protected get fs(): FileSystem;
|
|
45
|
-
/** The path relative to the `FileSystem`'s root */
|
|
46
|
-
get internalPath(): string;
|
|
47
|
-
/** The flag the handle was opened with */
|
|
48
|
-
get flag(): number;
|
|
49
|
-
/** Stats for the handle */
|
|
50
|
-
get inode(): InodeLike;
|
|
51
|
-
protected _sync: SyncHandle;
|
|
21
|
+
protected vfs: Handle;
|
|
52
22
|
constructor(context: V_Context, fd: number);
|
|
53
|
-
private get _isSync();
|
|
54
23
|
private _emitChange;
|
|
55
24
|
/**
|
|
56
25
|
* Asynchronous fchown(2) - Change ownership of a file.
|
|
@@ -79,7 +48,7 @@ export declare class FileHandle implements promises.FileHandle {
|
|
|
79
48
|
* @param atime The last access time. If a string is provided, it will be coerced to number.
|
|
80
49
|
* @param mtime The last modified time. If a string is provided, it will be coerced to number.
|
|
81
50
|
*/
|
|
82
|
-
utimes(atime:
|
|
51
|
+
utimes(atime: fs.TimeLike, mtime: fs.TimeLike): Promise<void>;
|
|
83
52
|
/**
|
|
84
53
|
* Asynchronously append data to a file, creating the file if it does not exist. The underlying file will _not_ be closed automatically.
|
|
85
54
|
* The `FileHandle` must have been opened for appending.
|
|
@@ -90,18 +59,6 @@ export declare class FileHandle implements promises.FileHandle {
|
|
|
90
59
|
* - `flag` defaults to `'a'`.
|
|
91
60
|
*/
|
|
92
61
|
appendFile(data: string | Uint8Array, _options?: (fs.ObjectEncodingOptions & promises.FlagAndOpenMode) | BufferEncoding): Promise<void>;
|
|
93
|
-
/**
|
|
94
|
-
* Read data from the file.
|
|
95
|
-
* @param buffer The buffer that the data will be written to.
|
|
96
|
-
* @param offset The offset within the buffer where writing will start.
|
|
97
|
-
* @param length An integer specifying the number of bytes to read.
|
|
98
|
-
* @param position An integer specifying where to begin reading from in the file.
|
|
99
|
-
* If position is unset, data will be read from the current file position.
|
|
100
|
-
*/
|
|
101
|
-
protected _read<TBuffer extends ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<{
|
|
102
|
-
bytesRead: number;
|
|
103
|
-
buffer: TBuffer;
|
|
104
|
-
}>;
|
|
105
62
|
/**
|
|
106
63
|
* Asynchronously reads data from the file.
|
|
107
64
|
* The `FileHandle` must have been opened for reading.
|
|
@@ -147,15 +104,6 @@ export declare class FileHandle implements promises.FileHandle {
|
|
|
147
104
|
stat(opts?: fs.StatOptions & {
|
|
148
105
|
bigint?: false;
|
|
149
106
|
}): Promise<Stats>;
|
|
150
|
-
/**
|
|
151
|
-
* Write buffer to the file.
|
|
152
|
-
* @param buffer Uint8Array containing the data to write to the file.
|
|
153
|
-
* @param offset Offset in the buffer to start reading data from.
|
|
154
|
-
* @param length The amount of bytes to write to the file.
|
|
155
|
-
* @param position Offset from the beginning of the file where this data should be written.
|
|
156
|
-
* If position is null, the data will be written at the current position.
|
|
157
|
-
*/
|
|
158
|
-
protected _write(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<number>;
|
|
159
107
|
/**
|
|
160
108
|
* Asynchronously writes `string` to the file.
|
|
161
109
|
* The `FileHandle` must have been opened for writing.
|
|
@@ -185,10 +133,6 @@ export declare class FileHandle implements promises.FileHandle {
|
|
|
185
133
|
* Asynchronous close(2) - close a `FileHandle`.
|
|
186
134
|
*/
|
|
187
135
|
close(): Promise<void>;
|
|
188
|
-
/**
|
|
189
|
-
* Cleans up. This will *not* sync the file data to the FS
|
|
190
|
-
*/
|
|
191
|
-
protected dispose(force?: boolean): void;
|
|
192
136
|
/**
|
|
193
137
|
* Asynchronous `writev`. Writes from multiple buffers.
|
|
194
138
|
* @param buffers An array of Uint8Array buffers.
|
|
@@ -327,7 +271,7 @@ export declare function readdir(this: V_Context, path: fs.PathLike, options: {
|
|
|
327
271
|
withFileTypes: true;
|
|
328
272
|
recursive?: boolean;
|
|
329
273
|
}): Promise<Dirent<Buffer>[]>;
|
|
330
|
-
export declare function readdir(this: V_Context, path: fs.PathLike, options?:
|
|
274
|
+
export declare function readdir(this: V_Context, path: fs.PathLike, options?: NodeReaddirOptions): Promise<string[] | Dirent<any>[] | Buffer[]>;
|
|
331
275
|
export declare function link(this: V_Context, path: fs.PathLike, dest: fs.PathLike): Promise<void>;
|
|
332
276
|
/**
|
|
333
277
|
* `symlink`.
|
|
@@ -346,7 +290,7 @@ export declare function lchmod(this: V_Context, path: fs.PathLike, mode: fs.Mode
|
|
|
346
290
|
/**
|
|
347
291
|
* Change file timestamps of the file referenced by the supplied path.
|
|
348
292
|
*/
|
|
349
|
-
export declare function utimes(this: V_Context, path: fs.PathLike, atime:
|
|
293
|
+
export declare function utimes(this: V_Context, path: fs.PathLike, atime: fs.TimeLike, mtime: fs.TimeLike): Promise<void>;
|
|
350
294
|
/**
|
|
351
295
|
* Change file timestamps of the file referenced by the supplied path.
|
|
352
296
|
*/
|