@zenfs/core 0.3.0 → 0.3.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/dist/FileIndex.d.ts +3 -25
- package/dist/backends/AsyncMirror.d.ts +16 -18
- package/dist/backends/AsyncMirror.js +4 -5
- package/dist/backends/AsyncStore.d.ts +8 -21
- package/dist/backends/AsyncStore.js +3 -3
- package/dist/backends/InMemory.js +2 -2
- package/dist/backends/Locked.d.ts +1 -1
- package/dist/backends/Locked.js +3 -3
- package/dist/backends/Overlay.d.ts +1 -1
- package/dist/backends/Overlay.js +5 -5
- package/dist/backends/SyncStore.d.ts +8 -8
- package/dist/backends/SyncStore.js +3 -4
- package/dist/browser.min.js +4 -4
- package/dist/browser.min.js.map +3 -3
- package/dist/file.js +6 -6
- package/dist/filesystem.d.ts +25 -165
- package/dist/filesystem.js +15 -13
- package/package.json +1 -1
- package/readme.md +48 -70
- package/dist/backends/FolderAdapter.d.ts +0 -52
- package/dist/backends/FolderAdapter.js +0 -173
- package/dist/backends/OverlayFS.d.ts +0 -112
- package/dist/backends/OverlayFS.js +0 -542
- package/dist/emulation/fs.d.ts +0 -6
- package/dist/emulation/fs.js +0 -4
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
var _a;
|
|
2
|
-
import { BaseFileSystem } from '../filesystem.js';
|
|
3
|
-
import { relative, join } from '../emulation/path.js';
|
|
4
|
-
import { ApiError } from '../ApiError.js';
|
|
5
|
-
import { Cred } from '../cred.js';
|
|
6
|
-
import { CreateBackend } from './backend.js';
|
|
7
|
-
/**
|
|
8
|
-
* The FolderAdapter file system wraps a file system, and scopes all interactions to a subfolder of that file system.
|
|
9
|
-
*
|
|
10
|
-
* Example: Given a file system `foo` with folder `bar` and file `bar/baz`...
|
|
11
|
-
*
|
|
12
|
-
* ```javascript
|
|
13
|
-
* ZenFS.configure({
|
|
14
|
-
* fs: "FolderAdapter",
|
|
15
|
-
* options: {
|
|
16
|
-
* folder: "bar",
|
|
17
|
-
* wrapped: foo
|
|
18
|
-
* }
|
|
19
|
-
* }, function(e) {
|
|
20
|
-
* var fs = ZenFS.BFSRequire('fs');
|
|
21
|
-
* fs.readdirSync('/'); // ['baz']
|
|
22
|
-
* });
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export class FolderAdapter extends BaseFileSystem {
|
|
26
|
-
static isAvailable() {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
constructor({ folder, wrapped }) {
|
|
30
|
-
super();
|
|
31
|
-
this._folder = folder;
|
|
32
|
-
this._wrapped = wrapped;
|
|
33
|
-
this._ready = this._initialize();
|
|
34
|
-
}
|
|
35
|
-
get metadata() {
|
|
36
|
-
return { ...super.metadata, ...this._wrapped.metadata, supportsLinks: false };
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Initialize the file system. Ensures that the wrapped file system
|
|
40
|
-
* has the given folder.
|
|
41
|
-
*/
|
|
42
|
-
async _initialize() {
|
|
43
|
-
const exists = await this._wrapped.exists(this._folder, Cred.Root);
|
|
44
|
-
if (!exists && this._wrapped.metadata.readonly) {
|
|
45
|
-
throw ApiError.ENOENT(this._folder);
|
|
46
|
-
}
|
|
47
|
-
await this._wrapped.mkdir(this._folder, 0o777, Cred.Root);
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
_a = FolderAdapter;
|
|
52
|
-
FolderAdapter.Name = 'FolderAdapter';
|
|
53
|
-
FolderAdapter.Create = CreateBackend.bind(_a);
|
|
54
|
-
FolderAdapter.Options = {
|
|
55
|
-
folder: {
|
|
56
|
-
type: 'string',
|
|
57
|
-
description: 'The folder to use as the root directory',
|
|
58
|
-
},
|
|
59
|
-
wrapped: {
|
|
60
|
-
type: 'object',
|
|
61
|
-
description: 'The file system to wrap',
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* @internal
|
|
66
|
-
*/
|
|
67
|
-
function translateError(folder, e) {
|
|
68
|
-
if (e !== null && typeof e === 'object') {
|
|
69
|
-
const err = e;
|
|
70
|
-
let p = err.path;
|
|
71
|
-
if (p) {
|
|
72
|
-
p = '/' + relative(folder, p);
|
|
73
|
-
err.message = err.message.replace(err.path, p);
|
|
74
|
-
err.path = p;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return e;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* @internal
|
|
81
|
-
*/
|
|
82
|
-
function wrapCallback(folder, cb) {
|
|
83
|
-
if (typeof cb === 'function') {
|
|
84
|
-
return function (err) {
|
|
85
|
-
if (arguments.length > 0) {
|
|
86
|
-
arguments[0] = translateError(folder, err);
|
|
87
|
-
}
|
|
88
|
-
cb.apply(null, arguments);
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
return cb;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* @internal
|
|
97
|
-
*/
|
|
98
|
-
function wrapFunction(name, wrapFirst, wrapSecond) {
|
|
99
|
-
if (name.slice(name.length - 4) !== 'Sync') {
|
|
100
|
-
// Async function. Translate error in callback.
|
|
101
|
-
return function () {
|
|
102
|
-
if (arguments.length > 0) {
|
|
103
|
-
if (wrapFirst) {
|
|
104
|
-
arguments[0] = join(this._folder, arguments[0]);
|
|
105
|
-
}
|
|
106
|
-
if (wrapSecond) {
|
|
107
|
-
arguments[1] = join(this._folder, arguments[1]);
|
|
108
|
-
}
|
|
109
|
-
arguments[arguments.length - 1] = wrapCallback(this._folder, arguments[arguments.length - 1]);
|
|
110
|
-
}
|
|
111
|
-
return this._wrapped[name].apply(this._wrapped, arguments);
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
// Sync function. Translate error in catch.
|
|
116
|
-
return function () {
|
|
117
|
-
try {
|
|
118
|
-
if (wrapFirst) {
|
|
119
|
-
arguments[0] = join(this._folder, arguments[0]);
|
|
120
|
-
}
|
|
121
|
-
if (wrapSecond) {
|
|
122
|
-
arguments[1] = join(this._folder, arguments[1]);
|
|
123
|
-
}
|
|
124
|
-
return this._wrapped[name].apply(this._wrapped, arguments);
|
|
125
|
-
}
|
|
126
|
-
catch (e) {
|
|
127
|
-
throw translateError(this._folder, e);
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
// First argument is a path.
|
|
133
|
-
[
|
|
134
|
-
'diskSpace',
|
|
135
|
-
'stat',
|
|
136
|
-
'statSync',
|
|
137
|
-
'open',
|
|
138
|
-
'openSync',
|
|
139
|
-
'unlink',
|
|
140
|
-
'unlinkSync',
|
|
141
|
-
'rmdir',
|
|
142
|
-
'rmdirSync',
|
|
143
|
-
'mkdir',
|
|
144
|
-
'mkdirSync',
|
|
145
|
-
'readdir',
|
|
146
|
-
'readdirSync',
|
|
147
|
-
'exists',
|
|
148
|
-
'existsSync',
|
|
149
|
-
'realpath',
|
|
150
|
-
'realpathSync',
|
|
151
|
-
'truncate',
|
|
152
|
-
'truncateSync',
|
|
153
|
-
'readFile',
|
|
154
|
-
'readFileSync',
|
|
155
|
-
'writeFile',
|
|
156
|
-
'writeFileSync',
|
|
157
|
-
'appendFile',
|
|
158
|
-
'appendFileSync',
|
|
159
|
-
'chmod',
|
|
160
|
-
'chmodSync',
|
|
161
|
-
'chown',
|
|
162
|
-
'chownSync',
|
|
163
|
-
'utimes',
|
|
164
|
-
'utimesSync',
|
|
165
|
-
'readlink',
|
|
166
|
-
'readlinkSync',
|
|
167
|
-
].forEach((name) => {
|
|
168
|
-
FolderAdapter.prototype[name] = wrapFunction(name, true, false);
|
|
169
|
-
});
|
|
170
|
-
// First and second arguments are paths.
|
|
171
|
-
['rename', 'renameSync', 'link', 'linkSync', 'symlink', 'symlinkSync'].forEach((name) => {
|
|
172
|
-
FolderAdapter.prototype[name] = wrapFunction(name, true, true);
|
|
173
|
-
});
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { FileSystem, FileSystemMetadata } from '../filesystem.js';
|
|
2
|
-
import { File, FileFlag } from '../file.js';
|
|
3
|
-
import { Stats } from '../stats.js';
|
|
4
|
-
import LockedFS from './Locked.js';
|
|
5
|
-
import { Cred } from '../cred.js';
|
|
6
|
-
import type { Backend } from './backend.js';
|
|
7
|
-
export declare namespace OverlayFS {
|
|
8
|
-
/**
|
|
9
|
-
* Configuration options for OverlayFS instances.
|
|
10
|
-
*/
|
|
11
|
-
interface Options {
|
|
12
|
-
/**
|
|
13
|
-
* The file system to write modified files to.
|
|
14
|
-
*/
|
|
15
|
-
writable: FileSystem;
|
|
16
|
-
/**
|
|
17
|
-
* The file system that initially populates this file system.
|
|
18
|
-
*/
|
|
19
|
-
readable: FileSystem;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* OverlayFS makes a read-only filesystem writable by storing writes on a second, writable file system.
|
|
24
|
-
* Deletes are persisted via metadata stored on the writable file system.
|
|
25
|
-
*
|
|
26
|
-
* This class contains no locking whatsoever. It is wrapped in a LockedFS to prevent races.
|
|
27
|
-
*
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
export declare class UnlockedOverlayFS extends FileSystem {
|
|
31
|
-
ready(): Promise<this>;
|
|
32
|
-
private _writable;
|
|
33
|
-
private _readable;
|
|
34
|
-
private _isInitialized;
|
|
35
|
-
private _deletedFiles;
|
|
36
|
-
private _deleteLog;
|
|
37
|
-
private _deleteLogUpdatePending;
|
|
38
|
-
private _deleteLogUpdateNeeded;
|
|
39
|
-
private _deleteLogError?;
|
|
40
|
-
private _ready;
|
|
41
|
-
constructor({ writable, readable }: OverlayFS.Options);
|
|
42
|
-
get metadata(): FileSystemMetadata;
|
|
43
|
-
getOverlayedFileSystems(): OverlayFS.Options;
|
|
44
|
-
sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
|
|
45
|
-
syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
|
|
46
|
-
/**
|
|
47
|
-
* Called once to load up metadata stored on the writable file system.
|
|
48
|
-
* @internal
|
|
49
|
-
*/
|
|
50
|
-
_initialize(): Promise<void>;
|
|
51
|
-
getDeletionLog(): string;
|
|
52
|
-
restoreDeletionLog(log: string, cred: Cred): void;
|
|
53
|
-
rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
|
|
54
|
-
renameSync(oldPath: string, newPath: string, cred: Cred): void;
|
|
55
|
-
stat(p: string, cred: Cred): Promise<Stats>;
|
|
56
|
-
statSync(p: string, cred: Cred): Stats;
|
|
57
|
-
openFile(path: string, flag: FileFlag, cred: Cred): Promise<File>;
|
|
58
|
-
openFileSync(path: string, flag: FileFlag, cred: Cred): File;
|
|
59
|
-
createFile(path: string, flag: FileFlag, mode: number, cred: Cred): Promise<File>;
|
|
60
|
-
createFileSync(path: string, flag: FileFlag, mode: number, cred: Cred): File;
|
|
61
|
-
link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
|
|
62
|
-
linkSync(srcpath: string, dstpath: string, cred: Cred): void;
|
|
63
|
-
unlink(p: string, cred: Cred): Promise<void>;
|
|
64
|
-
unlinkSync(p: string, cred: Cred): void;
|
|
65
|
-
rmdir(p: string, cred: Cred): Promise<void>;
|
|
66
|
-
rmdirSync(p: string, cred: Cred): void;
|
|
67
|
-
mkdir(p: string, mode: number, cred: Cred): Promise<void>;
|
|
68
|
-
mkdirSync(p: string, mode: number, cred: Cred): void;
|
|
69
|
-
readdir(p: string, cred: Cred): Promise<string[]>;
|
|
70
|
-
readdirSync(p: string, cred: Cred): string[];
|
|
71
|
-
private deletePath;
|
|
72
|
-
private updateLog;
|
|
73
|
-
private _reparseDeletionLog;
|
|
74
|
-
private checkInitialized;
|
|
75
|
-
private checkPath;
|
|
76
|
-
/**
|
|
77
|
-
* With the given path, create the needed parent directories on the writable storage
|
|
78
|
-
* should they not exist. Use modes from the read-only storage.
|
|
79
|
-
*/
|
|
80
|
-
private createParentDirectoriesSync;
|
|
81
|
-
private createParentDirectories;
|
|
82
|
-
/**
|
|
83
|
-
* Helper function:
|
|
84
|
-
* - Ensures p is on writable before proceeding. Throws an error if it doesn't exist.
|
|
85
|
-
* - Calls f to perform operation on writable.
|
|
86
|
-
*/
|
|
87
|
-
private operateOnWritable;
|
|
88
|
-
private operateOnWritableAsync;
|
|
89
|
-
/**
|
|
90
|
-
* Copy from readable to writable storage.
|
|
91
|
-
* PRECONDITION: File does not exist on writable storage.
|
|
92
|
-
*/
|
|
93
|
-
private copyToWritableSync;
|
|
94
|
-
private copyToWritable;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* OverlayFS makes a read-only filesystem writable by storing writes on a second,
|
|
98
|
-
* writable file system. Deletes are persisted via metadata stored on the writable
|
|
99
|
-
* file system.
|
|
100
|
-
*/
|
|
101
|
-
export declare class OverlayFS extends LockedFS<UnlockedOverlayFS> {
|
|
102
|
-
ready(): Promise<this>;
|
|
103
|
-
/**
|
|
104
|
-
* @param options The options to initialize the OverlayFS with
|
|
105
|
-
*/
|
|
106
|
-
constructor(options: OverlayFS.Options);
|
|
107
|
-
getOverlayedFileSystems(): OverlayFS.Options;
|
|
108
|
-
getDeletionLog(): string;
|
|
109
|
-
resDeletionLog(): string;
|
|
110
|
-
unwrap(): UnlockedOverlayFS;
|
|
111
|
-
}
|
|
112
|
-
export declare const Overlay: Backend;
|