@zenfs/core 0.12.2 → 0.12.3
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/dist/backends/backend.d.ts +1 -1
- package/dist/backends/fetch.d.ts +1 -1
- package/dist/backends/index/fs.d.ts +2 -2
- package/dist/backends/index/index.d.ts +2 -1
- package/dist/backends/overlay.d.ts +4 -3
- package/dist/backends/port/fs.d.ts +5 -2
- package/dist/backends/port/fs.js +13 -10
- package/dist/browser.min.js +4 -4
- package/dist/browser.min.js.map +3 -3
- package/dist/config.d.ts +1 -1
- package/dist/config.js +1 -1
- package/dist/cred.d.ts +2 -1
- package/dist/emulation/async.d.ts +2 -1
- package/dist/emulation/promises.d.ts +1 -1
- package/dist/emulation/promises.js +27 -35
- package/dist/emulation/shared.d.ts +2 -2
- package/dist/emulation/shared.js +1 -2
- package/dist/emulation/streams.d.ts +1 -1
- package/dist/emulation/sync.d.ts +1 -1
- package/dist/emulation/sync.js +24 -32
- package/dist/error.d.ts +1 -1
- package/dist/error.js +1 -1
- package/dist/file.d.ts +2 -13
- package/dist/file.js +3 -33
- package/dist/filesystem.d.ts +18 -36
- package/dist/filesystem.js +9 -13
- package/dist/stats.d.ts +1 -1
- package/dist/utils.d.ts +2 -2
- package/license.md +2 -26
- package/package.json +2 -2
- package/readme.md +1 -1
- package/src/backends/backend.ts +1 -1
- package/src/backends/fetch.ts +1 -1
- package/src/backends/index/fs.ts +2 -1
- package/src/backends/index/index.ts +2 -1
- package/src/backends/overlay.ts +6 -3
- package/src/backends/port/fs.ts +14 -10
- package/src/config.ts +1 -1
- package/src/cred.ts +2 -1
- package/src/emulation/async.ts +2 -1
- package/src/emulation/promises.ts +28 -33
- package/src/emulation/shared.ts +4 -4
- package/src/emulation/streams.ts +1 -1
- package/src/emulation/sync.ts +28 -33
- package/src/error.ts +1 -1
- package/src/file.ts +5 -39
- package/src/filesystem.ts +19 -38
- package/src/stats.ts +1 -1
- package/src/utils.ts +2 -2
package/dist/config.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { AbsolutePath } from './emulation/path.js';
|
|
|
6
6
|
export type MountConfiguration<T extends Backend> = FilesystemOf<T> | BackendConfiguration<T> | T;
|
|
7
7
|
/**
|
|
8
8
|
* Retrieve a file system with the given configuration.
|
|
9
|
-
* @
|
|
9
|
+
* @see MountConfiguration
|
|
10
10
|
*/
|
|
11
11
|
export declare function resolveMountConfig<T extends Backend>(config: MountConfiguration<T>, _depth?: number): Promise<FilesystemOf<T>>;
|
|
12
12
|
type ConfigMounts = {
|
package/dist/config.js
CHANGED
|
@@ -8,7 +8,7 @@ function isMountConfig(arg) {
|
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Retrieve a file system with the given configuration.
|
|
11
|
-
* @
|
|
11
|
+
* @see MountConfiguration
|
|
12
12
|
*/
|
|
13
13
|
export async function resolveMountConfig(config, _depth = 0) {
|
|
14
14
|
if (typeof config !== 'object' || config == null) {
|
package/dist/cred.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Credentials used for various operations.
|
|
3
|
-
* Similar to Linux's cred struct.
|
|
3
|
+
* Similar to Linux's cred struct.
|
|
4
|
+
* @see https://github.com/torvalds/linux/blob/master/include/linux/cred.h
|
|
4
5
|
*/
|
|
5
6
|
export interface Cred {
|
|
6
7
|
uid: number;
|
|
@@ -6,7 +6,8 @@ import type * as fs from 'node:fs';
|
|
|
6
6
|
import type { FileContents } from '../filesystem.js';
|
|
7
7
|
import { BigIntStats, type Stats } from '../stats.js';
|
|
8
8
|
import { type Callback } from '../utils.js';
|
|
9
|
-
import { Dirent
|
|
9
|
+
import type { Dirent } from './dir.js';
|
|
10
|
+
import { type Dir } from './dir.js';
|
|
10
11
|
import * as promises from './promises.js';
|
|
11
12
|
import { ReadStream, WriteStream } from './streams.js';
|
|
12
13
|
/**
|
|
@@ -12,7 +12,7 @@ import type { CreateReadStreamOptions, CreateWriteStreamOptions, FileChangeInfo,
|
|
|
12
12
|
import type { Stream } from 'node:stream';
|
|
13
13
|
import type { ReadableStream as TReadableStream } from 'node:stream/web';
|
|
14
14
|
import type { Interface as ReadlineInterface } from 'readline';
|
|
15
|
-
import { File } from '../file.js';
|
|
15
|
+
import type { File } from '../file.js';
|
|
16
16
|
import type { FileContents } from '../filesystem.js';
|
|
17
17
|
import { BigIntStats, type Stats } from '../stats.js';
|
|
18
18
|
import { Dir, Dirent } from './dir.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
2
|
import { Errno, ErrnoError } from '../error.js';
|
|
3
|
-
import {
|
|
3
|
+
import { isAppendable, isExclusive, isReadable, isTruncating, isWriteable, parseFlag } from '../file.js';
|
|
4
4
|
import { BigIntStats, FileType } from '../stats.js';
|
|
5
5
|
import { normalizeMode, normalizeOptions, normalizePath, normalizeTime } from '../utils.js';
|
|
6
6
|
import * as constants from './constants.js';
|
|
@@ -83,7 +83,7 @@ export class FileHandle {
|
|
|
83
83
|
throw new ErrnoError(Errno.EINVAL, 'Encoding not specified');
|
|
84
84
|
}
|
|
85
85
|
const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : data;
|
|
86
|
-
await this.file.write(encodedData, 0, encodedData.length
|
|
86
|
+
await this.file.write(encodedData, 0, encodedData.length);
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* Asynchronously reads data from the file.
|
|
@@ -387,40 +387,32 @@ async function _open(path, _flag, _mode = 0o644, resolveSymlinks) {
|
|
|
387
387
|
path = resolveSymlinks && (await exists(path)) ? await realpath(path) : path;
|
|
388
388
|
const { fs, path: resolved } = resolveMount(path);
|
|
389
389
|
if (!(await fs.exists(path, cred))) {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
// Ensure parent exists.
|
|
393
|
-
const parentStats = await fs.stat(dirname(resolved), cred);
|
|
394
|
-
if (parentStats && !parentStats.isDirectory()) {
|
|
395
|
-
throw ErrnoError.With('ENOTDIR', dirname(path), '_open');
|
|
396
|
-
}
|
|
397
|
-
return new FileHandle(await fs.createFile(resolved, flag, mode, cred));
|
|
398
|
-
case ActionType.THROW:
|
|
399
|
-
throw ErrnoError.With('ENOENT', path, '_open');
|
|
400
|
-
default:
|
|
401
|
-
throw new ErrnoError(Errno.EINVAL, 'Invalid file flag');
|
|
390
|
+
if ((!isWriteable(flag) && !isAppendable(flag)) || flag == 'r+') {
|
|
391
|
+
throw ErrnoError.With('ENOENT', path, '_open');
|
|
402
392
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
throw ErrnoError.With('
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
393
|
+
// Create the file
|
|
394
|
+
const parentStats = await fs.stat(dirname(resolved), cred);
|
|
395
|
+
if (parentStats && !parentStats.isDirectory()) {
|
|
396
|
+
throw ErrnoError.With('ENOTDIR', dirname(path), '_open');
|
|
397
|
+
}
|
|
398
|
+
return new FileHandle(await fs.createFile(resolved, flag, mode, cred));
|
|
399
|
+
}
|
|
400
|
+
if (isExclusive(flag)) {
|
|
401
|
+
throw ErrnoError.With('EEXIST', path, '_open');
|
|
402
|
+
}
|
|
403
|
+
if (!isTruncating(flag)) {
|
|
404
|
+
return new FileHandle(await fs.openFile(resolved, flag, cred));
|
|
405
|
+
}
|
|
406
|
+
/*
|
|
407
|
+
In a previous implementation, we deleted the file and
|
|
408
|
+
re-created it. However, this created a race condition if another
|
|
409
|
+
asynchronous request was trying to read the file, as the file
|
|
410
|
+
would not exist for a small period of time.
|
|
411
|
+
*/
|
|
412
|
+
const file = await fs.openFile(resolved, flag, cred);
|
|
413
|
+
await file.truncate(0);
|
|
414
|
+
await file.sync();
|
|
415
|
+
return new FileHandle(file);
|
|
424
416
|
}
|
|
425
417
|
/**
|
|
426
418
|
* Asynchronous file open.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import type { BigIntStatsFs, StatsFs } from 'node:fs';
|
|
3
|
-
import { Cred } from '../cred.js';
|
|
3
|
+
import type { Cred } from '../cred.js';
|
|
4
4
|
import type { File } from '../file.js';
|
|
5
|
-
import { FileSystem } from '../filesystem.js';
|
|
5
|
+
import type { FileSystem } from '../filesystem.js';
|
|
6
6
|
import { type AbsolutePath } from './path.js';
|
|
7
7
|
export declare let cred: Cred;
|
|
8
8
|
export declare function setCred(val: Cred): void;
|
package/dist/emulation/shared.js
CHANGED
|
@@ -3,7 +3,6 @@ import { InMemory } from '../backends/memory.js';
|
|
|
3
3
|
import { rootCred } from '../cred.js';
|
|
4
4
|
import { Errno, ErrnoError } from '../error.js';
|
|
5
5
|
import { size_max } from '../inode.js';
|
|
6
|
-
import { ZenFsType } from '../stats.js';
|
|
7
6
|
import { normalizePath } from '../utils.js';
|
|
8
7
|
import { resolve } from './path.js';
|
|
9
8
|
// credentials
|
|
@@ -109,7 +108,7 @@ export function _statfs(fs, bigint) {
|
|
|
109
108
|
const md = fs.metadata();
|
|
110
109
|
const bs = md.blockSize || 4096;
|
|
111
110
|
return {
|
|
112
|
-
type: (bigint ? BigInt : Number)(md.type
|
|
111
|
+
type: (bigint ? BigInt : Number)(md.type),
|
|
113
112
|
bsize: (bigint ? BigInt : Number)(bs),
|
|
114
113
|
ffree: (bigint ? BigInt : Number)(md.freeNodes || size_max),
|
|
115
114
|
files: (bigint ? BigInt : Number)(md.totalNodes || size_max),
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
3
|
import type * as Node from 'fs';
|
|
4
4
|
import { Readable, Writable } from 'readable-stream';
|
|
5
|
-
import { Callback } from '../utils.js';
|
|
5
|
+
import type { Callback } from '../utils.js';
|
|
6
6
|
export declare class ReadStream extends Readable implements Node.ReadStream {
|
|
7
7
|
close(callback?: Callback): void;
|
|
8
8
|
bytesRead: number;
|
package/dist/emulation/sync.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/// <reference types="node" resolution-mode="require"/>
|
|
4
4
|
import { Buffer } from 'buffer';
|
|
5
5
|
import type * as fs from 'node:fs';
|
|
6
|
-
import { FileContents } from '../filesystem.js';
|
|
6
|
+
import type { FileContents } from '../filesystem.js';
|
|
7
7
|
import { BigIntStats, type Stats } from '../stats.js';
|
|
8
8
|
import { Dir, Dirent } from './dir.js';
|
|
9
9
|
/**
|
package/dist/emulation/sync.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
2
|
import { Errno, ErrnoError } from '../error.js';
|
|
3
|
-
import {
|
|
3
|
+
import { isAppendable, isExclusive, isReadable, isTruncating, isWriteable, parseFlag } from '../file.js';
|
|
4
4
|
import { BigIntStats, FileType } from '../stats.js';
|
|
5
5
|
import { normalizeMode, normalizeOptions, normalizePath, normalizeTime } from '../utils.js';
|
|
6
6
|
import { COPYFILE_EXCL, F_OK, S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK } from './constants.js';
|
|
@@ -108,43 +108,35 @@ function _openSync(path, _flag, _mode, resolveSymlinks = true) {
|
|
|
108
108
|
path = resolveSymlinks && existsSync(path) ? realpathSync(path) : path;
|
|
109
109
|
const { fs, path: resolved } = resolveMount(path);
|
|
110
110
|
if (!fs.existsSync(resolved, cred)) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return fs.createFileSync(resolved, flag, mode, cred);
|
|
119
|
-
case ActionType.THROW:
|
|
120
|
-
throw ErrnoError.With('ENOENT', path, '_open');
|
|
121
|
-
default:
|
|
122
|
-
throw new ErrnoError(Errno.EINVAL, 'Invalid FileFlag object.');
|
|
111
|
+
if ((!isWriteable(flag) && !isAppendable(flag)) || flag == 'r+') {
|
|
112
|
+
throw ErrnoError.With('ENOENT', path, '_open');
|
|
113
|
+
}
|
|
114
|
+
// Create the file
|
|
115
|
+
const parentStats = fs.statSync(dirname(resolved), cred);
|
|
116
|
+
if (!parentStats.isDirectory()) {
|
|
117
|
+
throw ErrnoError.With('ENOTDIR', dirname(path), '_open');
|
|
123
118
|
}
|
|
119
|
+
return fs.createFileSync(resolved, flag, mode, cred);
|
|
124
120
|
}
|
|
125
121
|
const stats = fs.statSync(resolved, cred);
|
|
126
122
|
if (!stats.hasAccess(mode, cred)) {
|
|
127
123
|
throw ErrnoError.With('EACCES', path, '_open');
|
|
128
124
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
// Delete file.
|
|
135
|
-
fs.unlinkSync(resolved, cred);
|
|
136
|
-
/*
|
|
137
|
-
Create file. Use the same mode as the old file.
|
|
138
|
-
Node itself modifies the ctime when this occurs, so this action
|
|
139
|
-
will preserve that behavior if the underlying file system
|
|
140
|
-
supports those properties.
|
|
141
|
-
*/
|
|
142
|
-
return fs.createFileSync(resolved, flag, stats.mode, cred);
|
|
143
|
-
case ActionType.NOP:
|
|
144
|
-
return fs.openFileSync(resolved, flag, cred);
|
|
145
|
-
default:
|
|
146
|
-
throw new ErrnoError(Errno.EINVAL, 'Invalid FileFlag object.');
|
|
125
|
+
if (isExclusive(flag)) {
|
|
126
|
+
throw ErrnoError.With('EEXIST', path, '_open');
|
|
127
|
+
}
|
|
128
|
+
if (!isTruncating(flag)) {
|
|
129
|
+
return fs.openFileSync(resolved, flag, cred);
|
|
147
130
|
}
|
|
131
|
+
// Delete file.
|
|
132
|
+
fs.unlinkSync(resolved, cred);
|
|
133
|
+
/*
|
|
134
|
+
Create file. Use the same mode as the old file.
|
|
135
|
+
Node itself modifies the ctime when this occurs, so this action
|
|
136
|
+
will preserve that behavior if the underlying file system
|
|
137
|
+
supports those properties.
|
|
138
|
+
*/
|
|
139
|
+
return fs.createFileSync(resolved, flag, stats.mode, cred);
|
|
148
140
|
}
|
|
149
141
|
/**
|
|
150
142
|
* Synchronous file open.
|
|
@@ -238,7 +230,7 @@ export function appendFileSync(filename, data, _options = {}) {
|
|
|
238
230
|
const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
239
231
|
const file = _openSync(typeof filename == 'number' ? fd2file(filename).path : filename.toString(), flag, options.mode, true);
|
|
240
232
|
try {
|
|
241
|
-
file.writeSync(encodedData, 0, encodedData.byteLength
|
|
233
|
+
file.writeSync(encodedData, 0, encodedData.byteLength);
|
|
242
234
|
}
|
|
243
235
|
finally {
|
|
244
236
|
file.closeSync();
|
package/dist/error.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Standard libc error codes. More will be added to this enum and error strings as they are
|
|
4
4
|
* needed.
|
|
5
|
-
* @
|
|
5
|
+
* @see https://en.wikipedia.org/wiki/Errno.h
|
|
6
6
|
*/
|
|
7
7
|
export declare enum Errno {
|
|
8
8
|
/** Operation not permitted */
|
package/dist/error.js
CHANGED
package/dist/file.d.ts
CHANGED
|
@@ -20,15 +20,6 @@ declare global {
|
|
|
20
20
|
}): ArrayBuffer;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
* @hidden
|
|
25
|
-
*/
|
|
26
|
-
export declare enum ActionType {
|
|
27
|
-
NOP = 0,
|
|
28
|
-
THROW = 1,
|
|
29
|
-
TRUNCATE = 2,
|
|
30
|
-
CREATE = 3
|
|
31
|
-
}
|
|
32
23
|
export declare function parseFlag(flag: string | number): string;
|
|
33
24
|
export declare function flagToString(flag: number): string;
|
|
34
25
|
export declare function flagToNumber(flag: string): number;
|
|
@@ -43,8 +34,6 @@ export declare function isTruncating(flag: string): boolean;
|
|
|
43
34
|
export declare function isAppendable(flag: string): boolean;
|
|
44
35
|
export declare function isSynchronous(flag: string): boolean;
|
|
45
36
|
export declare function isExclusive(flag: string): boolean;
|
|
46
|
-
export declare function pathExistsAction(flag: string): ActionType;
|
|
47
|
-
export declare function pathNotExistsAction(flag: string): ActionType;
|
|
48
37
|
export declare abstract class File {
|
|
49
38
|
/**
|
|
50
39
|
* Get the current file position.
|
|
@@ -101,7 +90,7 @@ export declare abstract class File {
|
|
|
101
90
|
* the current position.
|
|
102
91
|
* @returns Promise resolving to the new length of the buffer
|
|
103
92
|
*/
|
|
104
|
-
abstract write(buffer: Uint8Array, offset?: number, length?: number, position?: number
|
|
93
|
+
abstract write(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<number>;
|
|
105
94
|
/**
|
|
106
95
|
* Write buffer to the file.
|
|
107
96
|
* Note that it is unsafe to use fs.writeSync multiple times on the same file
|
|
@@ -114,7 +103,7 @@ export declare abstract class File {
|
|
|
114
103
|
* data should be written. If position is null, the data will be written at
|
|
115
104
|
* the current position.
|
|
116
105
|
*/
|
|
117
|
-
abstract writeSync(buffer: Uint8Array, offset?: number, length?: number, position?: number
|
|
106
|
+
abstract writeSync(buffer: Uint8Array, offset?: number, length?: number, position?: number): number;
|
|
118
107
|
/**
|
|
119
108
|
* Read data from the file.
|
|
120
109
|
* @param buffer The buffer that the data will be
|
package/dist/file.js
CHANGED
|
@@ -1,21 +1,7 @@
|
|
|
1
|
-
import { ErrnoError, Errno } from './error.js';
|
|
2
1
|
import { O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY, S_IFMT } from './emulation/constants.js';
|
|
2
|
+
import { Errno, ErrnoError } from './error.js';
|
|
3
3
|
import { size_max } from './inode.js';
|
|
4
4
|
import { Stats } from './stats.js';
|
|
5
|
-
/**
|
|
6
|
-
* @hidden
|
|
7
|
-
*/
|
|
8
|
-
export var ActionType;
|
|
9
|
-
(function (ActionType) {
|
|
10
|
-
// Indicates that the code should not do anything.
|
|
11
|
-
ActionType[ActionType["NOP"] = 0] = "NOP";
|
|
12
|
-
// Indicates that the code should throw an exception.
|
|
13
|
-
ActionType[ActionType["THROW"] = 1] = "THROW";
|
|
14
|
-
// Indicates that the code should truncate the file, but only if it is a file.
|
|
15
|
-
ActionType[ActionType["TRUNCATE"] = 2] = "TRUNCATE";
|
|
16
|
-
// Indicates that the code should create the file.
|
|
17
|
-
ActionType[ActionType["CREATE"] = 3] = "CREATE";
|
|
18
|
-
})(ActionType || (ActionType = {}));
|
|
19
5
|
const validFlags = ['r', 'r+', 'rs', 'rs+', 'w', 'wx', 'w+', 'wx+', 'a', 'ax', 'a+', 'ax+'];
|
|
20
6
|
export function parseFlag(flag) {
|
|
21
7
|
if (typeof flag === 'number') {
|
|
@@ -117,21 +103,6 @@ export function isSynchronous(flag) {
|
|
|
117
103
|
export function isExclusive(flag) {
|
|
118
104
|
return flag.indexOf('x') !== -1;
|
|
119
105
|
}
|
|
120
|
-
export function pathExistsAction(flag) {
|
|
121
|
-
if (isExclusive(flag)) {
|
|
122
|
-
return ActionType.THROW;
|
|
123
|
-
}
|
|
124
|
-
if (isTruncating(flag)) {
|
|
125
|
-
return ActionType.TRUNCATE;
|
|
126
|
-
}
|
|
127
|
-
return ActionType.NOP;
|
|
128
|
-
}
|
|
129
|
-
export function pathNotExistsAction(flag) {
|
|
130
|
-
if ((isWriteable(flag) || isAppendable(flag)) && flag !== 'r+') {
|
|
131
|
-
return ActionType.CREATE;
|
|
132
|
-
}
|
|
133
|
-
return ActionType.THROW;
|
|
134
|
-
}
|
|
135
106
|
export class File {
|
|
136
107
|
[Symbol.asyncDispose]() {
|
|
137
108
|
return this.close();
|
|
@@ -306,7 +277,7 @@ export class PreloadFile extends File {
|
|
|
306
277
|
* data should be written. If position is null, the data will be written at
|
|
307
278
|
* the current position.
|
|
308
279
|
*/
|
|
309
|
-
async write(buffer, offset = 0, length = this.stats.size, position =
|
|
280
|
+
async write(buffer, offset = 0, length = this.stats.size, position = this.position) {
|
|
310
281
|
const bytesWritten = this.writeSync(buffer, offset, length, position);
|
|
311
282
|
await this.sync();
|
|
312
283
|
return bytesWritten;
|
|
@@ -324,9 +295,8 @@ export class PreloadFile extends File {
|
|
|
324
295
|
* the current position.
|
|
325
296
|
* @returns bytes written
|
|
326
297
|
*/
|
|
327
|
-
writeSync(buffer, offset = 0, length = this.stats.size, position =
|
|
298
|
+
writeSync(buffer, offset = 0, length = this.stats.size, position = this.position) {
|
|
328
299
|
this.dirty = true;
|
|
329
|
-
position ?? (position = this.position);
|
|
330
300
|
if (!isWriteable(this.flag)) {
|
|
331
301
|
throw new ErrnoError(Errno.EPERM, 'File not opened with a writeable mode.');
|
|
332
302
|
}
|
package/dist/filesystem.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Cred } from './cred.js';
|
|
2
2
|
import { type File } from './file.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type Stats } from './stats.js';
|
|
4
4
|
export type FileContents = ArrayBufferView | string;
|
|
5
5
|
/**
|
|
6
6
|
* Metadata about a FileSystem
|
|
@@ -50,24 +50,16 @@ export interface FileSystemMetadata {
|
|
|
50
50
|
/**
|
|
51
51
|
* The type of the FS
|
|
52
52
|
*/
|
|
53
|
-
type
|
|
53
|
+
type: number;
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
56
|
* Structure for a filesystem. All ZenFS backends must extend this.
|
|
57
57
|
*
|
|
58
|
-
* This class includes
|
|
58
|
+
* This class includes default implementations for `exists` and `existsSync`
|
|
59
59
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* - Every path is an absolute path. `.`, `..`, and other items are resolved into an absolute form.
|
|
63
|
-
* - All arguments are present. Any optional arguments at the Node API level have been passed in with their default values.
|
|
60
|
+
* If you are extending this class, note that every path is an absolute path and all arguments are present.
|
|
64
61
|
*/
|
|
65
62
|
export declare abstract class FileSystem {
|
|
66
|
-
/**
|
|
67
|
-
* Numeric type, used for statfs
|
|
68
|
-
* @internal @protected
|
|
69
|
-
*/
|
|
70
|
-
_type?: number;
|
|
71
63
|
/**
|
|
72
64
|
* Get metadata about the current file system
|
|
73
65
|
*/
|
|
@@ -75,8 +67,7 @@ export declare abstract class FileSystem {
|
|
|
75
67
|
constructor();
|
|
76
68
|
ready(): Promise<void>;
|
|
77
69
|
/**
|
|
78
|
-
* Asynchronous rename.
|
|
79
|
-
* are given to the completion callback.
|
|
70
|
+
* Asynchronous rename.
|
|
80
71
|
*/
|
|
81
72
|
abstract rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
|
|
82
73
|
/**
|
|
@@ -92,26 +83,24 @@ export declare abstract class FileSystem {
|
|
|
92
83
|
*/
|
|
93
84
|
abstract statSync(path: string, cred: Cred): Stats;
|
|
94
85
|
/**
|
|
95
|
-
* Opens the file at path
|
|
96
|
-
* @param
|
|
86
|
+
* Opens the file at `path` with the given flag. The file must exist.
|
|
87
|
+
* @param path The path to open.
|
|
97
88
|
* @param flag The flag to use when opening the file.
|
|
98
89
|
*/
|
|
99
90
|
abstract openFile(path: string, flag: string, cred: Cred): Promise<File>;
|
|
100
91
|
/**
|
|
101
|
-
* Opens the file at path
|
|
102
|
-
* @param
|
|
92
|
+
* Opens the file at `path` with the given flag. The file must exist.
|
|
93
|
+
* @param path The path to open.
|
|
103
94
|
* @param flag The flag to use when opening the file.
|
|
104
95
|
* @return A File object corresponding to the opened file.
|
|
105
96
|
*/
|
|
106
97
|
abstract openFileSync(path: string, flag: string, cred: Cred): File;
|
|
107
98
|
/**
|
|
108
|
-
* Create the file at path
|
|
109
|
-
* flag.
|
|
99
|
+
* Create the file at `path` with the given mode. Then, open it with the given flag.
|
|
110
100
|
*/
|
|
111
101
|
abstract createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File>;
|
|
112
102
|
/**
|
|
113
|
-
* Create the file at path
|
|
114
|
-
* flag.
|
|
103
|
+
* Create the file at `path` with the given mode. Then, open it with the given flag.
|
|
115
104
|
*/
|
|
116
105
|
abstract createFileSync(path: string, flag: string, mode: number, cred: Cred): File;
|
|
117
106
|
/**
|
|
@@ -132,21 +121,16 @@ export declare abstract class FileSystem {
|
|
|
132
121
|
abstract rmdirSync(path: string, cred: Cred): void;
|
|
133
122
|
/**
|
|
134
123
|
* Asynchronous `mkdir`.
|
|
135
|
-
* @param mode Mode to make the directory using.
|
|
136
|
-
* the filesystem doesn't support permissions.
|
|
124
|
+
* @param mode Mode to make the directory using.
|
|
137
125
|
*/
|
|
138
126
|
abstract mkdir(path: string, mode: number, cred: Cred): Promise<void>;
|
|
139
127
|
/**
|
|
140
128
|
* Synchronous `mkdir`.
|
|
141
|
-
* @param mode Mode to make the directory using.
|
|
142
|
-
* the filesystem doesn't support permissions.
|
|
129
|
+
* @param mode Mode to make the directory using.
|
|
143
130
|
*/
|
|
144
131
|
abstract mkdirSync(path: string, mode: number, cred: Cred): void;
|
|
145
132
|
/**
|
|
146
133
|
* Asynchronous `readdir`. Reads the contents of a directory.
|
|
147
|
-
*
|
|
148
|
-
* The callback gets two arguments `(err, files)` where `files` is an array of
|
|
149
|
-
* the names of the files in the directory excluding `'.'` and `'..'`.
|
|
150
134
|
*/
|
|
151
135
|
abstract readdir(path: string, cred: Cred): Promise<string[]>;
|
|
152
136
|
/**
|
|
@@ -233,13 +217,11 @@ declare abstract class AsyncFS extends FileSystem {
|
|
|
233
217
|
/**
|
|
234
218
|
* Async() implements synchronous methods on an asynchronous file system
|
|
235
219
|
*
|
|
236
|
-
* Implementing classes must define
|
|
237
|
-
* by:
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
* - During application loading, the contents of the async file system can be reloaded into
|
|
242
|
-
* the synchronous store, if desired.
|
|
220
|
+
* Implementing classes must define `_sync` for the synchronous file system used as a cache.
|
|
221
|
+
* Synchronous methods on an asynchronous FS are implemented by:
|
|
222
|
+
* - Performing operations over the in-memory copy,
|
|
223
|
+
* while asynchronously pipelining them to the backing store.
|
|
224
|
+
* - During loading, the contents of the async file system are eloaded into the synchronous store.
|
|
243
225
|
*
|
|
244
226
|
*/
|
|
245
227
|
export declare function Async<T extends abstract new (...args: any[]) => FileSystem>(FS: T): (abstract new (...args: any[]) => AsyncFS) & T;
|
package/dist/filesystem.js
CHANGED
|
@@ -2,15 +2,13 @@ import { ErrnoError, Errno } from './error.js';
|
|
|
2
2
|
import { rootCred } from './cred.js';
|
|
3
3
|
import { join } from './emulation/path.js';
|
|
4
4
|
import { PreloadFile, parseFlag } from './file.js';
|
|
5
|
+
import { ZenFsType } from './stats.js';
|
|
5
6
|
/**
|
|
6
7
|
* Structure for a filesystem. All ZenFS backends must extend this.
|
|
7
8
|
*
|
|
8
|
-
* This class includes
|
|
9
|
+
* This class includes default implementations for `exists` and `existsSync`
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* - Every path is an absolute path. `.`, `..`, and other items are resolved into an absolute form.
|
|
13
|
-
* - All arguments are present. Any optional arguments at the Node API level have been passed in with their default values.
|
|
11
|
+
* If you are extending this class, note that every path is an absolute path and all arguments are present.
|
|
14
12
|
*/
|
|
15
13
|
export class FileSystem {
|
|
16
14
|
/**
|
|
@@ -24,7 +22,7 @@ export class FileSystem {
|
|
|
24
22
|
freeSpace: 0,
|
|
25
23
|
noResizableBuffers: false,
|
|
26
24
|
noAsyncCache: false,
|
|
27
|
-
type:
|
|
25
|
+
type: ZenFsType,
|
|
28
26
|
};
|
|
29
27
|
}
|
|
30
28
|
constructor() { }
|
|
@@ -99,13 +97,11 @@ export function Sync(FS) {
|
|
|
99
97
|
/**
|
|
100
98
|
* Async() implements synchronous methods on an asynchronous file system
|
|
101
99
|
*
|
|
102
|
-
* Implementing classes must define
|
|
103
|
-
* by:
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* - During application loading, the contents of the async file system can be reloaded into
|
|
108
|
-
* the synchronous store, if desired.
|
|
100
|
+
* Implementing classes must define `_sync` for the synchronous file system used as a cache.
|
|
101
|
+
* Synchronous methods on an asynchronous FS are implemented by:
|
|
102
|
+
* - Performing operations over the in-memory copy,
|
|
103
|
+
* while asynchronously pipelining them to the backing store.
|
|
104
|
+
* - During loading, the contents of the async file system are eloaded into the synchronous store.
|
|
109
105
|
*
|
|
110
106
|
*/
|
|
111
107
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/dist/stats.d.ts
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
3
|
import type { OptionalTuple } from 'utilium';
|
|
4
4
|
import { ErrnoError } from './error.js';
|
|
5
|
-
import { Cred } from './cred.js';
|
|
5
|
+
import type { Cred } from './cred.js';
|
|
6
6
|
import { type AbsolutePath } from './emulation/path.js';
|
|
7
|
-
import { FileSystem } from './filesystem.js';
|
|
7
|
+
import type { FileSystem } from './filesystem.js';
|
|
8
8
|
import type * as fs from 'node:fs';
|
|
9
9
|
declare global {
|
|
10
10
|
function atob(data: string): string;
|
package/license.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Copyright (c)
|
|
2
|
-
|
|
1
|
+
Copyright (c) James P. and other ZenFS contributors.
|
|
3
2
|
Copyright (c) 2013-2023 John Vilk and other BrowserFS contributors.
|
|
3
|
+
Copyright (c) Joyent, Inc. and other Node contributors for `test/fixtures/node`.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
6
|
this software and associated documentation files (the "Software"), to deal in
|
|
@@ -19,27 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
|
22
|
-
|
|
23
|
-
This license applies to all parts of ZenFS, except for the following items:
|
|
24
|
-
|
|
25
|
-
- The test fixtures located in `test/fixtures/node`. Their license follows:
|
|
26
|
-
"""
|
|
27
|
-
Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|
28
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
29
|
-
of this software and associated documentation files (the "Software"), to
|
|
30
|
-
deal in the Software without restriction, including without limitation the
|
|
31
|
-
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
32
|
-
sell copies of the Software, and to permit persons to whom the Software is
|
|
33
|
-
furnished to do so, subject to the following conditions:
|
|
34
|
-
|
|
35
|
-
The above copyright notice and this permission notice shall be included in
|
|
36
|
-
all copies or substantial portions of the Software.
|
|
37
|
-
|
|
38
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
39
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
40
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
41
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
42
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
43
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
44
|
-
IN THE SOFTWARE.
|
|
45
|
-
"""
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenfs/core",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.3",
|
|
4
4
|
"description": "A filesystem in your browser",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"scripts": {
|
|
39
39
|
"format": "prettier --write .",
|
|
40
40
|
"format:check": "prettier --check .",
|
|
41
|
-
"lint": "
|
|
41
|
+
"lint": "tsc -p tsconfig.json --noEmit && eslint src tests",
|
|
42
42
|
"test": "npm run build && tsc -p tests/tsconfig.json --noEmit && cross-env NODE_OPTIONS=--experimental-vm-modules npx jest",
|
|
43
43
|
"build": "node scripts/build.js --globalName=ZenFS --entry src/index.ts",
|
|
44
44
|
"build:docs": "typedoc --out docs --name ZenFS src/index.ts",
|