@zenfs/core 0.4.2 → 0.5.0
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/FileIndex.d.ts +14 -18
- package/dist/FileIndex.js +5 -5
- package/dist/backends/AsyncMirror.d.ts +8 -8
- package/dist/backends/AsyncMirror.js +8 -8
- package/dist/backends/AsyncStore.d.ts +6 -6
- package/dist/backends/AsyncStore.js +2 -2
- package/dist/backends/Locked.d.ts +5 -5
- package/dist/backends/Overlay.d.ts +6 -6
- package/dist/backends/Overlay.js +12 -12
- package/dist/backends/SyncStore.d.ts +8 -8
- package/dist/backends/SyncStore.js +2 -2
- package/dist/browser.min.js +4 -4
- package/dist/browser.min.js.map +4 -4
- package/dist/config.js +1 -2
- package/dist/cred.d.ts +2 -3
- package/dist/cred.js +8 -15
- package/dist/emulation/promises.js +10 -10
- package/dist/emulation/shared.js +2 -2
- package/dist/emulation/sync.js +10 -10
- package/dist/file.d.ts +16 -100
- package/dist/file.js +113 -204
- package/dist/filesystem.d.ts +11 -11
- package/dist/stats.d.ts +2 -2
- package/dist/stats.js +10 -4
- package/package.json +1 -1
package/dist/config.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isBackend, resolveBackendConfig } from './backends/backend.js';
|
|
2
|
-
import { Cred } from './cred.js';
|
|
3
2
|
import * as fs from './emulation/index.js';
|
|
4
3
|
import { setCred } from './emulation/shared.js';
|
|
5
4
|
import { FileSystem } from './filesystem.js';
|
|
@@ -7,7 +6,7 @@ import { FileSystem } from './filesystem.js';
|
|
|
7
6
|
* Initializes ZenFS with the given file systems.
|
|
8
7
|
*/
|
|
9
8
|
export function initialize(mounts, uid = 0, gid = 0) {
|
|
10
|
-
setCred(
|
|
9
|
+
setCred({ uid, gid, suid: uid, sgid: gid, euid: uid, egid: gid });
|
|
11
10
|
fs.initialize(mounts);
|
|
12
11
|
}
|
|
13
12
|
/**
|
package/dist/cred.d.ts
CHANGED
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
* Credentials used for various operations.
|
|
3
3
|
* Similar to Linux's cred struct. See https://github.com/torvalds/linux/blob/master/include/linux/cred.h
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export interface Cred {
|
|
6
6
|
uid: number;
|
|
7
7
|
gid: number;
|
|
8
8
|
suid: number;
|
|
9
9
|
sgid: number;
|
|
10
10
|
euid: number;
|
|
11
11
|
egid: number;
|
|
12
|
-
constructor(uid: number, gid: number, suid: number, sgid: number, euid: number, egid: number);
|
|
13
|
-
static Root: Cred;
|
|
14
12
|
}
|
|
13
|
+
export declare const rootCred: Cred;
|
package/dist/cred.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.suid = suid;
|
|
10
|
-
this.sgid = sgid;
|
|
11
|
-
this.euid = euid;
|
|
12
|
-
this.egid = egid;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
Cred.Root = new Cred(0, 0, 0, 0, 0, 0);
|
|
1
|
+
export const rootCred = {
|
|
2
|
+
uid: 0,
|
|
3
|
+
gid: 0,
|
|
4
|
+
suid: 0,
|
|
5
|
+
sgid: 0,
|
|
6
|
+
euid: 0,
|
|
7
|
+
egid: 0,
|
|
8
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApiError, ErrorCode } from '../ApiError.js';
|
|
2
2
|
export * as constants from './constants.js';
|
|
3
|
-
import { ActionType,
|
|
3
|
+
import { ActionType, isReadable, isWriteable, isAppendable, parseFlag, pathExistsAction, pathNotExistsAction } from '../file.js';
|
|
4
4
|
import { normalizePath, normalizeMode, getFdForFile, normalizeOptions, fd2file, fdMap, normalizeTime, cred, nop, resolveFS, fixError, mounts } from './shared.js';
|
|
5
5
|
import { BigIntStats, FileType } from '../stats.js';
|
|
6
6
|
import { decode, encode } from '../utils.js';
|
|
@@ -248,9 +248,9 @@ unlink;
|
|
|
248
248
|
* @internal
|
|
249
249
|
*/
|
|
250
250
|
async function _open(_path, _flag, _mode = 0o644, resolveSymlinks) {
|
|
251
|
-
const path = normalizePath(_path), mode = normalizeMode(_mode, 0o644), flag =
|
|
251
|
+
const path = normalizePath(_path), mode = normalizeMode(_mode, 0o644), flag = parseFlag(_flag);
|
|
252
252
|
try {
|
|
253
|
-
switch (
|
|
253
|
+
switch (pathExistsAction(flag)) {
|
|
254
254
|
case ActionType.THROW:
|
|
255
255
|
throw ApiError.EEXIST(path);
|
|
256
256
|
case ActionType.TRUNCATE:
|
|
@@ -275,7 +275,7 @@ async function _open(_path, _flag, _mode = 0o644, resolveSymlinks) {
|
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
277
|
catch (e) {
|
|
278
|
-
switch (
|
|
278
|
+
switch (pathNotExistsAction(flag)) {
|
|
279
279
|
case ActionType.CREATE:
|
|
280
280
|
// Ensure parent exists.
|
|
281
281
|
const parentStats = await doOp('stat', resolveSymlinks, dirname(path), cred);
|
|
@@ -327,8 +327,8 @@ async function _readFile(fname, flag, resolveSymlinks) {
|
|
|
327
327
|
}
|
|
328
328
|
export async function readFile(filename, _options) {
|
|
329
329
|
const options = normalizeOptions(_options, null, 'r', null);
|
|
330
|
-
const flag =
|
|
331
|
-
if (!
|
|
330
|
+
const flag = parseFlag(options.flag);
|
|
331
|
+
if (!isReadable(flag)) {
|
|
332
332
|
throw new ApiError(ErrorCode.EINVAL, 'Flag passed must allow for reading.');
|
|
333
333
|
}
|
|
334
334
|
const data = await _readFile(filename, options.flag, true);
|
|
@@ -363,8 +363,8 @@ async function _writeFile(fname, data, flag, mode, resolveSymlinks) {
|
|
|
363
363
|
*/
|
|
364
364
|
export async function writeFile(filename, data, _options) {
|
|
365
365
|
const options = normalizeOptions(_options, 'utf8', 'w', 0o644);
|
|
366
|
-
const flag =
|
|
367
|
-
if (!
|
|
366
|
+
const flag = parseFlag(options.flag);
|
|
367
|
+
if (!isWriteable(flag)) {
|
|
368
368
|
throw new ApiError(ErrorCode.EINVAL, 'Flag passed must allow for writing.');
|
|
369
369
|
}
|
|
370
370
|
if (typeof data != 'string' && !options.encoding) {
|
|
@@ -399,8 +399,8 @@ async function _appendFile(fname, data, flag, mode, resolveSymlinks) {
|
|
|
399
399
|
*/
|
|
400
400
|
export async function appendFile(filename, data, _options) {
|
|
401
401
|
const options = normalizeOptions(_options, 'utf8', 'a', 0o644);
|
|
402
|
-
const flag =
|
|
403
|
-
if (!
|
|
402
|
+
const flag = parseFlag(options.flag);
|
|
403
|
+
if (!isAppendable(flag)) {
|
|
404
404
|
throw new ApiError(ErrorCode.EINVAL, 'Flag passed to appendFile must allow for appending.');
|
|
405
405
|
}
|
|
406
406
|
if (typeof data != 'string' && !options.encoding) {
|
package/dist/emulation/shared.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Utilities and shared data
|
|
2
2
|
import { resolve } from './path.js';
|
|
3
3
|
import { ApiError, ErrorCode } from '../ApiError.js';
|
|
4
|
-
import {
|
|
4
|
+
import { rootCred } from '../cred.js';
|
|
5
5
|
import { InMemory } from '../backends/InMemory.js';
|
|
6
6
|
/**
|
|
7
7
|
* converts Date or number to a integer UNIX timestamp
|
|
@@ -109,7 +109,7 @@ export function nop() {
|
|
|
109
109
|
// do nothing
|
|
110
110
|
}
|
|
111
111
|
// credentials
|
|
112
|
-
export let cred =
|
|
112
|
+
export let cred = rootCred;
|
|
113
113
|
export function setCred(val) {
|
|
114
114
|
cred = val;
|
|
115
115
|
}
|
package/dist/emulation/sync.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ApiError, ErrorCode } from '../ApiError.js';
|
|
2
|
-
import { ActionType,
|
|
2
|
+
import { ActionType, isAppendable, isReadable, isWriteable, parseFlag, pathExistsAction, pathNotExistsAction } from '../file.js';
|
|
3
3
|
import { BigIntStats, FileType } from '../stats.js';
|
|
4
4
|
import { normalizePath, cred, getFdForFile, normalizeMode, normalizeOptions, fdMap, fd2file, normalizeTime, resolveFS, fixError, mounts, } from './shared.js';
|
|
5
5
|
import { decode, encode } from '../utils.js';
|
|
@@ -92,7 +92,7 @@ export function unlinkSync(path) {
|
|
|
92
92
|
}
|
|
93
93
|
unlinkSync;
|
|
94
94
|
function _openSync(_path, _flag, _mode, resolveSymlinks) {
|
|
95
|
-
const path = normalizePath(_path), mode = normalizeMode(_mode, 0o644), flag =
|
|
95
|
+
const path = normalizePath(_path), mode = normalizeMode(_mode, 0o644), flag = parseFlag(_flag);
|
|
96
96
|
// Check if the path exists, and is a file.
|
|
97
97
|
let stats;
|
|
98
98
|
try {
|
|
@@ -100,7 +100,7 @@ function _openSync(_path, _flag, _mode, resolveSymlinks) {
|
|
|
100
100
|
}
|
|
101
101
|
catch (e) {
|
|
102
102
|
// File does not exist.
|
|
103
|
-
switch (
|
|
103
|
+
switch (pathNotExistsAction(flag)) {
|
|
104
104
|
case ActionType.CREATE:
|
|
105
105
|
// Ensure parent exists.
|
|
106
106
|
const parentStats = doOp('statSync', resolveSymlinks, dirname(path), cred);
|
|
@@ -118,7 +118,7 @@ function _openSync(_path, _flag, _mode, resolveSymlinks) {
|
|
|
118
118
|
throw ApiError.EACCES(path);
|
|
119
119
|
}
|
|
120
120
|
// File exists.
|
|
121
|
-
switch (
|
|
121
|
+
switch (pathExistsAction(flag)) {
|
|
122
122
|
case ActionType.THROW:
|
|
123
123
|
throw ApiError.EEXIST(path);
|
|
124
124
|
case ActionType.TRUNCATE:
|
|
@@ -176,8 +176,8 @@ function _readFileSync(fname, flag, resolveSymlinks) {
|
|
|
176
176
|
}
|
|
177
177
|
export function readFileSync(filename, arg2 = {}) {
|
|
178
178
|
const options = normalizeOptions(arg2, null, 'r', 0o644);
|
|
179
|
-
const flag =
|
|
180
|
-
if (!
|
|
179
|
+
const flag = parseFlag(options.flag);
|
|
180
|
+
if (!isReadable(flag)) {
|
|
181
181
|
throw new ApiError(ErrorCode.EINVAL, 'Flag passed to readFile must allow for reading.');
|
|
182
182
|
}
|
|
183
183
|
const data = _readFileSync(filename, options.flag, true);
|
|
@@ -201,8 +201,8 @@ function _writeFileSync(fname, data, flag, mode, resolveSymlinks) {
|
|
|
201
201
|
}
|
|
202
202
|
export function writeFileSync(filename, data, _options) {
|
|
203
203
|
const options = normalizeOptions(_options, 'utf8', 'w', 0o644);
|
|
204
|
-
const flag =
|
|
205
|
-
if (!
|
|
204
|
+
const flag = parseFlag(options.flag);
|
|
205
|
+
if (!isWriteable(flag)) {
|
|
206
206
|
throw new ApiError(ErrorCode.EINVAL, 'Flag passed to writeFile must allow for writing.');
|
|
207
207
|
}
|
|
208
208
|
if (typeof data != 'string' && !options.encoding) {
|
|
@@ -230,8 +230,8 @@ function _appendFileSync(fname, data, flag, mode, resolveSymlinks) {
|
|
|
230
230
|
}
|
|
231
231
|
export function appendFileSync(filename, data, arg3) {
|
|
232
232
|
const options = normalizeOptions(arg3, 'utf8', 'a', 0o644);
|
|
233
|
-
const flag =
|
|
234
|
-
if (!
|
|
233
|
+
const flag = parseFlag(options.flag);
|
|
234
|
+
if (!isAppendable(flag)) {
|
|
235
235
|
throw new ApiError(ErrorCode.EINVAL, 'Flag passed to appendFile must allow for appending.');
|
|
236
236
|
}
|
|
237
237
|
if (typeof data != 'string' && !options.encoding) {
|
package/dist/file.d.ts
CHANGED
|
@@ -26,102 +26,18 @@ export declare enum ActionType {
|
|
|
26
26
|
TRUNCATE = 2,
|
|
27
27
|
CREATE = 3
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
* - ax: Like 'a' but opens the file in exclusive mode.
|
|
42
|
-
* - a+: Open file for reading and appending. The file is created if it does not exist.
|
|
43
|
-
* - ax+: Like 'a+' but opens the file in exclusive mode.
|
|
44
|
-
*
|
|
45
|
-
* Exclusive mode ensures that the file path is newly created.
|
|
46
|
-
*/
|
|
47
|
-
export declare class FileFlag {
|
|
48
|
-
/**
|
|
49
|
-
* Contains cached FileMode instances.
|
|
50
|
-
*/
|
|
51
|
-
protected static cache: Map<string | number, FileFlag>;
|
|
52
|
-
/**
|
|
53
|
-
* Array of valid mode strings.
|
|
54
|
-
*/
|
|
55
|
-
protected static validStrings: string[];
|
|
56
|
-
/**
|
|
57
|
-
* Get an object representing the given file flag.
|
|
58
|
-
* @param flag The string or number representing the flag
|
|
59
|
-
* @return The FileFlag object representing the flag
|
|
60
|
-
* @throw when the flag string is invalid
|
|
61
|
-
*/
|
|
62
|
-
static Get(flag: string | number): FileFlag;
|
|
63
|
-
protected _flag: string;
|
|
64
|
-
/**
|
|
65
|
-
* @param flag The string or number representing the flag
|
|
66
|
-
* @throw when the flag is invalid
|
|
67
|
-
*/
|
|
68
|
-
protected constructor(flag: string | number);
|
|
69
|
-
/**
|
|
70
|
-
* @param flag The number representing the flag
|
|
71
|
-
* @returns The string representing the flag
|
|
72
|
-
* @throws when the flag number is invalid
|
|
73
|
-
*/
|
|
74
|
-
static StringOf(flag: number): string;
|
|
75
|
-
/**
|
|
76
|
-
* @param flag The string representing the flag
|
|
77
|
-
* @returns The number representing the flag
|
|
78
|
-
* @throws when the flag string is invalid
|
|
79
|
-
*/
|
|
80
|
-
static NumberOf(flag: string): number;
|
|
81
|
-
/**
|
|
82
|
-
* Get the underlying flag string for this flag.
|
|
83
|
-
*/
|
|
84
|
-
toString(): string;
|
|
85
|
-
/**
|
|
86
|
-
* Get the equivalent mode (0b0xxx: read, write, execute)
|
|
87
|
-
* Note: Execute will always be 0
|
|
88
|
-
*/
|
|
89
|
-
get mode(): number;
|
|
90
|
-
/**
|
|
91
|
-
* Returns true if the file is readable.
|
|
92
|
-
*/
|
|
93
|
-
isReadable(): boolean;
|
|
94
|
-
/**
|
|
95
|
-
* Returns true if the file is writeable.
|
|
96
|
-
*/
|
|
97
|
-
isWriteable(): boolean;
|
|
98
|
-
/**
|
|
99
|
-
* Returns true if the file mode should truncate.
|
|
100
|
-
*/
|
|
101
|
-
isTruncating(): boolean;
|
|
102
|
-
/**
|
|
103
|
-
* Returns true if the file is appendable.
|
|
104
|
-
*/
|
|
105
|
-
isAppendable(): boolean;
|
|
106
|
-
/**
|
|
107
|
-
* Returns true if the file is open in synchronous mode.
|
|
108
|
-
*/
|
|
109
|
-
isSynchronous(): boolean;
|
|
110
|
-
/**
|
|
111
|
-
* Returns true if the file is open in exclusive mode.
|
|
112
|
-
*/
|
|
113
|
-
isExclusive(): boolean;
|
|
114
|
-
/**
|
|
115
|
-
* Returns one of the static fields on this object that indicates the
|
|
116
|
-
* appropriate response to the path existing.
|
|
117
|
-
*/
|
|
118
|
-
pathExistsAction(): ActionType;
|
|
119
|
-
/**
|
|
120
|
-
* Returns one of the static fields on this object that indicates the
|
|
121
|
-
* appropriate response to the path not existing.
|
|
122
|
-
*/
|
|
123
|
-
pathNotExistsAction(): ActionType;
|
|
124
|
-
}
|
|
29
|
+
export declare function parseFlag(flag: string | number): string;
|
|
30
|
+
export declare function flagToString(flag: number): string;
|
|
31
|
+
export declare function flagToNumber(flag: string): number;
|
|
32
|
+
export declare function flagToMode(flag: string): number;
|
|
33
|
+
export declare function isReadable(flag: string): boolean;
|
|
34
|
+
export declare function isWriteable(flag: string): boolean;
|
|
35
|
+
export declare function isTruncating(flag: string): boolean;
|
|
36
|
+
export declare function isAppendable(flag: string): boolean;
|
|
37
|
+
export declare function isSynchronous(flag: string): boolean;
|
|
38
|
+
export declare function isExclusive(flag: string): boolean;
|
|
39
|
+
export declare function pathExistsAction(flag: string): ActionType;
|
|
40
|
+
export declare function pathNotExistsAction(flag: string): ActionType;
|
|
125
41
|
export declare abstract class File {
|
|
126
42
|
/**
|
|
127
43
|
* Get the current file position.
|
|
@@ -281,7 +197,7 @@ export declare abstract class PreloadFile<FS extends FileSystem> extends File {
|
|
|
281
197
|
* Path to the file
|
|
282
198
|
*/
|
|
283
199
|
readonly path: string;
|
|
284
|
-
readonly flag:
|
|
200
|
+
readonly flag: string;
|
|
285
201
|
readonly stats: Stats;
|
|
286
202
|
protected _buffer: Uint8Array;
|
|
287
203
|
protected _position: number;
|
|
@@ -306,7 +222,7 @@ export declare abstract class PreloadFile<FS extends FileSystem> extends File {
|
|
|
306
222
|
/**
|
|
307
223
|
* Path to the file
|
|
308
224
|
*/
|
|
309
|
-
path: string, flag:
|
|
225
|
+
path: string, flag: string, stats: Stats, _buffer?: Uint8Array);
|
|
310
226
|
/**
|
|
311
227
|
* Get the underlying buffer for this file. Mutating not recommended and will mess up dirty tracking.
|
|
312
228
|
*/
|
|
@@ -434,7 +350,7 @@ export declare abstract class PreloadFile<FS extends FileSystem> extends File {
|
|
|
434
350
|
* For synchronous file systems
|
|
435
351
|
*/
|
|
436
352
|
export declare class SyncFile<FS extends FileSystem> extends PreloadFile<FS> {
|
|
437
|
-
constructor(_fs: FS, _path: string, _flag:
|
|
353
|
+
constructor(_fs: FS, _path: string, _flag: string, _stat: Stats, contents?: Uint8Array);
|
|
438
354
|
sync(): Promise<void>;
|
|
439
355
|
syncSync(): void;
|
|
440
356
|
close(): Promise<void>;
|
|
@@ -444,7 +360,7 @@ export declare class SyncFile<FS extends FileSystem> extends PreloadFile<FS> {
|
|
|
444
360
|
* For the filesystems which do not sync to anything..
|
|
445
361
|
*/
|
|
446
362
|
export declare class NoSyncFile<T extends FileSystem> extends PreloadFile<T> {
|
|
447
|
-
constructor(_fs: T, _path: string, _flag:
|
|
363
|
+
constructor(_fs: T, _path: string, _flag: string, _stat: Stats, contents?: Uint8Array);
|
|
448
364
|
/**
|
|
449
365
|
* Asynchronous sync. Doesn't do anything, simply calls the cb.
|
|
450
366
|
*/
|