memfs 4.26.0 → 4.28.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/README.md +4 -5
- package/lib/fsa/CoreFileSystemDirectoryHandle.d.ts +73 -0
- package/lib/fsa/CoreFileSystemDirectoryHandle.js +286 -0
- package/lib/fsa/CoreFileSystemDirectoryHandle.js.map +1 -0
- package/lib/fsa/CoreFileSystemFileHandle.d.ts +25 -0
- package/lib/fsa/CoreFileSystemFileHandle.js +67 -0
- package/lib/fsa/CoreFileSystemFileHandle.js.map +1 -0
- package/lib/fsa/CoreFileSystemHandle.d.ts +34 -0
- package/lib/fsa/CoreFileSystemHandle.js +53 -0
- package/lib/fsa/CoreFileSystemHandle.js.map +1 -0
- package/lib/fsa/CoreFileSystemSyncAccessHandle.d.ts +38 -0
- package/lib/fsa/CoreFileSystemSyncAccessHandle.js +121 -0
- package/lib/fsa/CoreFileSystemSyncAccessHandle.js.map +1 -0
- package/lib/fsa/CoreFileSystemWritableFileStream.d.ts +29 -0
- package/lib/fsa/CoreFileSystemWritableFileStream.js +155 -0
- package/lib/fsa/CoreFileSystemWritableFileStream.js.map +1 -0
- package/lib/fsa/CorePermissionStatus.d.ts +9 -0
- package/lib/fsa/CorePermissionStatus.js +14 -0
- package/lib/fsa/CorePermissionStatus.js.map +1 -0
- package/lib/fsa/index.d.ts +27 -0
- package/lib/fsa/index.js +36 -0
- package/lib/fsa/index.js.map +1 -0
- package/lib/fsa/types.d.ts +13 -0
- package/lib/fsa/util.d.ts +11 -0
- package/lib/fsa/util.js +36 -0
- package/lib/fsa/util.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
# memfs
|
|
2
2
|
|
|
3
|
-
[![][
|
|
3
|
+
[![][npm-badge]][npm-url]
|
|
4
4
|
|
|
5
|
-
[chat]: https://onp4.com/@vadim/~memfs
|
|
6
|
-
[chat-badge]: https://img.shields.io/badge/Chat-%F0%9F%92%AC-green?style=flat&logo=chat&link=https://onp4.com/@vadim/~memfs
|
|
7
5
|
[npm-url]: https://www.npmjs.com/package/memfs
|
|
8
6
|
[npm-badge]: https://img.shields.io/npm/v/memfs.svg
|
|
9
7
|
|
|
@@ -19,8 +17,9 @@ npm i memfs
|
|
|
19
17
|
|
|
20
18
|
- Documentation
|
|
21
19
|
- [In-memory Node.js `fs` API](./docs/node/index.md)
|
|
22
|
-
-
|
|
23
|
-
- `
|
|
20
|
+
- [In-memory browser FSA (File System Access) API](./docs/fsa/fsa.md)
|
|
21
|
+
- [`fs` to File System Access API adapter](./docs/fsa/fs-to-fsa.md)
|
|
22
|
+
- [File System Access API to `fs` adapter](./docs/fsa/fsa-to-fs.md)
|
|
24
23
|
- `experimental` [`crudfs` a CRUD-like file system abstraction](./docs/crudfs/index.md)
|
|
25
24
|
- `experimental` [`casfs` Content Addressable Storage file system abstraction](./docs/casfs/index.md)
|
|
26
25
|
- [Directory `snapshot` utility](./docs/snapshot/index.md)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { CoreFileSystemHandle } from './CoreFileSystemHandle';
|
|
2
|
+
import type { CoreFsaContext, GetDirectoryHandleOptions, GetFileHandleOptions, IFileSystemDirectoryHandle, IFileSystemFileHandle, IFileSystemHandle, RemoveEntryOptions } from './types';
|
|
3
|
+
import type { Superblock } from '../core/Superblock';
|
|
4
|
+
/**
|
|
5
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle
|
|
6
|
+
*/
|
|
7
|
+
export declare class CoreFileSystemDirectoryHandle extends CoreFileSystemHandle implements IFileSystemDirectoryHandle {
|
|
8
|
+
protected readonly _core: Superblock;
|
|
9
|
+
protected readonly ctx: CoreFsaContext;
|
|
10
|
+
/** Directory path with trailing slash. */
|
|
11
|
+
readonly __path: string;
|
|
12
|
+
constructor(_core: Superblock, path: string, ctx?: Partial<CoreFsaContext>);
|
|
13
|
+
/**
|
|
14
|
+
* Returns a new array iterator containing the keys for each item in
|
|
15
|
+
* {@link CoreFileSystemDirectoryHandle} object.
|
|
16
|
+
*
|
|
17
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/keys
|
|
18
|
+
*/
|
|
19
|
+
keys(): AsyncIterableIterator<string>;
|
|
20
|
+
/**
|
|
21
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/entries
|
|
22
|
+
*/
|
|
23
|
+
entries(): AsyncIterableIterator<[string, CoreFileSystemHandle]>;
|
|
24
|
+
/**
|
|
25
|
+
* Returns a new array iterator containing the values for each index in the
|
|
26
|
+
* {@link FileSystemDirectoryHandle} object.
|
|
27
|
+
*
|
|
28
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/values
|
|
29
|
+
*/
|
|
30
|
+
values(): AsyncIterableIterator<CoreFileSystemHandle>;
|
|
31
|
+
/**
|
|
32
|
+
* Returns a {@link CoreFileSystemDirectoryHandle} for a subdirectory with the specified
|
|
33
|
+
* name within the directory handle on which the method is called.
|
|
34
|
+
*
|
|
35
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/getDirectoryHandle
|
|
36
|
+
* @param name A string representing the {@link CoreFileSystemHandle} name of
|
|
37
|
+
* the subdirectory you wish to retrieve.
|
|
38
|
+
* @param options An optional object containing options for the retrieved
|
|
39
|
+
* subdirectory.
|
|
40
|
+
*/
|
|
41
|
+
getDirectoryHandle(name: string, options?: GetDirectoryHandleOptions): Promise<IFileSystemDirectoryHandle>;
|
|
42
|
+
/**
|
|
43
|
+
* Returns a {@link CoreFileSystemFileHandle} for a file with the specified name,
|
|
44
|
+
* within the directory the method is called.
|
|
45
|
+
*
|
|
46
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/getFileHandle
|
|
47
|
+
* @param name A string representing the {@link CoreFileSystemHandle} name of
|
|
48
|
+
* the file you wish to retrieve.
|
|
49
|
+
* @param options An optional object containing options for the retrieved file.
|
|
50
|
+
*/
|
|
51
|
+
getFileHandle(name: string, options?: GetFileHandleOptions): Promise<IFileSystemFileHandle>;
|
|
52
|
+
/**
|
|
53
|
+
* Attempts to remove an entry if the directory handle contains a file or
|
|
54
|
+
* directory called the name specified.
|
|
55
|
+
*
|
|
56
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/removeEntry
|
|
57
|
+
* @param name A string representing the {@link CoreFileSystemHandle} name of the
|
|
58
|
+
* entry you wish to remove.
|
|
59
|
+
* @param options An optional object containing options.
|
|
60
|
+
*/
|
|
61
|
+
removeEntry(name: string, { recursive }?: RemoveEntryOptions): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* The `resolve()` method of the {@link FileSystemDirectoryHandle} interface
|
|
64
|
+
* returns an {@link Array} of directory names from the parent handle to the specified
|
|
65
|
+
* child entry, with the name of the child entry as the last array item.
|
|
66
|
+
*
|
|
67
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/resolve
|
|
68
|
+
* @param possibleDescendant The {@link CoreFileSystemHandle} from which
|
|
69
|
+
* to return the relative path.
|
|
70
|
+
*/
|
|
71
|
+
resolve(possibleDescendant: IFileSystemHandle): Promise<string[] | null>;
|
|
72
|
+
private _handleError;
|
|
73
|
+
}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoreFileSystemDirectoryHandle = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const CoreFileSystemHandle_1 = require("./CoreFileSystemHandle");
|
|
6
|
+
const util_1 = require("./util");
|
|
7
|
+
const CoreFileSystemFileHandle_1 = require("./CoreFileSystemFileHandle");
|
|
8
|
+
const buffer_1 = require("../internal/buffer");
|
|
9
|
+
const constants_1 = require("../node/constants");
|
|
10
|
+
/**
|
|
11
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle
|
|
12
|
+
*/
|
|
13
|
+
class CoreFileSystemDirectoryHandle extends CoreFileSystemHandle_1.CoreFileSystemHandle {
|
|
14
|
+
constructor(_core, path, ctx = {}) {
|
|
15
|
+
const fullCtx = (0, util_1.ctx)(ctx);
|
|
16
|
+
super('directory', (0, util_1.basename)(path, fullCtx.separator), fullCtx);
|
|
17
|
+
this._core = _core;
|
|
18
|
+
this.ctx = fullCtx;
|
|
19
|
+
this.__path = path[path.length - 1] === this.ctx.separator ? path : path + this.ctx.separator;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns a new array iterator containing the keys for each item in
|
|
23
|
+
* {@link CoreFileSystemDirectoryHandle} object.
|
|
24
|
+
*
|
|
25
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/keys
|
|
26
|
+
*/
|
|
27
|
+
keys() {
|
|
28
|
+
return tslib_1.__asyncGenerator(this, arguments, function* keys_1() {
|
|
29
|
+
try {
|
|
30
|
+
const link = this._core.getResolvedLinkOrThrow(this.__path);
|
|
31
|
+
const children = link.children;
|
|
32
|
+
for (const [name] of children) {
|
|
33
|
+
if (name !== '.' && name !== '..') {
|
|
34
|
+
yield yield tslib_1.__await(name);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
this._handleError(error, 'keys');
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/entries
|
|
45
|
+
*/
|
|
46
|
+
entries() {
|
|
47
|
+
return tslib_1.__asyncGenerator(this, arguments, function* entries_1() {
|
|
48
|
+
const { __path: path, _core, ctx } = this;
|
|
49
|
+
try {
|
|
50
|
+
const link = _core.getResolvedLinkOrThrow(path);
|
|
51
|
+
const children = link.children;
|
|
52
|
+
for (const [name, childLink] of children) {
|
|
53
|
+
if (name !== '.' && name !== '..' && childLink) {
|
|
54
|
+
const childPath = path + name;
|
|
55
|
+
const node = childLink.getNode();
|
|
56
|
+
if (node.isDirectory()) {
|
|
57
|
+
yield yield tslib_1.__await([name, new CoreFileSystemDirectoryHandle(_core, childPath, ctx)]);
|
|
58
|
+
}
|
|
59
|
+
else if (node.isFile()) {
|
|
60
|
+
yield yield tslib_1.__await([name, new CoreFileSystemFileHandle_1.CoreFileSystemFileHandle(_core, childPath, ctx)]);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
this._handleError(error, 'entries');
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns a new array iterator containing the values for each index in the
|
|
72
|
+
* {@link FileSystemDirectoryHandle} object.
|
|
73
|
+
*
|
|
74
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/values
|
|
75
|
+
*/
|
|
76
|
+
values() {
|
|
77
|
+
return tslib_1.__asyncGenerator(this, arguments, function* values_1() {
|
|
78
|
+
var _a, e_1, _b, _c;
|
|
79
|
+
try {
|
|
80
|
+
for (var _d = true, _e = tslib_1.__asyncValues(this.entries()), _f; _f = yield tslib_1.__await(_e.next()), _a = _f.done, !_a; _d = true) {
|
|
81
|
+
_c = _f.value;
|
|
82
|
+
_d = false;
|
|
83
|
+
const [, value] = _c;
|
|
84
|
+
yield yield tslib_1.__await(value);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
88
|
+
finally {
|
|
89
|
+
try {
|
|
90
|
+
if (!_d && !_a && (_b = _e.return)) yield tslib_1.__await(_b.call(_e));
|
|
91
|
+
}
|
|
92
|
+
finally { if (e_1) throw e_1.error; }
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Returns a {@link CoreFileSystemDirectoryHandle} for a subdirectory with the specified
|
|
98
|
+
* name within the directory handle on which the method is called.
|
|
99
|
+
*
|
|
100
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/getDirectoryHandle
|
|
101
|
+
* @param name A string representing the {@link CoreFileSystemHandle} name of
|
|
102
|
+
* the subdirectory you wish to retrieve.
|
|
103
|
+
* @param options An optional object containing options for the retrieved
|
|
104
|
+
* subdirectory.
|
|
105
|
+
*/
|
|
106
|
+
async getDirectoryHandle(name, options) {
|
|
107
|
+
(0, util_1.assertName)(name, 'getDirectoryHandle', 'FileSystemDirectoryHandle');
|
|
108
|
+
const filename = this.__path + name;
|
|
109
|
+
try {
|
|
110
|
+
const link = this._core.getResolvedLink(filename);
|
|
111
|
+
if (link) {
|
|
112
|
+
const node = link.getNode();
|
|
113
|
+
if (!node.isDirectory())
|
|
114
|
+
throw (0, util_1.newTypeMismatchError)();
|
|
115
|
+
return new CoreFileSystemDirectoryHandle(this._core, filename, this.ctx);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
throw new Error('ENOENT'); // Simulate error for consistency with catch block
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
if (error instanceof DOMException)
|
|
123
|
+
throw error;
|
|
124
|
+
if (error && typeof error === 'object') {
|
|
125
|
+
if (error.code === "ENOENT" /* ERROR_CODE.ENOENT */ || error.message === 'ENOENT') {
|
|
126
|
+
if (options === null || options === void 0 ? void 0 : options.create) {
|
|
127
|
+
(0, util_1.assertCanWrite)(this.ctx.mode);
|
|
128
|
+
try {
|
|
129
|
+
this._core.mkdir(filename, 0o755);
|
|
130
|
+
return new CoreFileSystemDirectoryHandle(this._core, filename, this.ctx);
|
|
131
|
+
}
|
|
132
|
+
catch (createError) {
|
|
133
|
+
if (createError && typeof createError === 'object' && createError.code === "EACCES" /* ERROR_CODE.EACCES */) {
|
|
134
|
+
throw (0, util_1.newNotAllowedError)();
|
|
135
|
+
}
|
|
136
|
+
throw createError;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
throw (0, util_1.newNotFoundError)();
|
|
140
|
+
}
|
|
141
|
+
if (error.code === "EACCES" /* ERROR_CODE.EACCES */) {
|
|
142
|
+
throw (0, util_1.newNotAllowedError)();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Returns a {@link CoreFileSystemFileHandle} for a file with the specified name,
|
|
150
|
+
* within the directory the method is called.
|
|
151
|
+
*
|
|
152
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/getFileHandle
|
|
153
|
+
* @param name A string representing the {@link CoreFileSystemHandle} name of
|
|
154
|
+
* the file you wish to retrieve.
|
|
155
|
+
* @param options An optional object containing options for the retrieved file.
|
|
156
|
+
*/
|
|
157
|
+
async getFileHandle(name, options) {
|
|
158
|
+
(0, util_1.assertName)(name, 'getFileHandle', 'FileSystemDirectoryHandle');
|
|
159
|
+
const filename = this.__path + name;
|
|
160
|
+
try {
|
|
161
|
+
const link = this._core.getResolvedLink(filename);
|
|
162
|
+
if (link) {
|
|
163
|
+
const node = link.getNode();
|
|
164
|
+
if (!node.isFile())
|
|
165
|
+
throw (0, util_1.newTypeMismatchError)();
|
|
166
|
+
return new CoreFileSystemFileHandle_1.CoreFileSystemFileHandle(this._core, filename, this.ctx);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
throw new Error('ENOENT'); // Simulate error for consistency with catch block
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
if (error instanceof DOMException)
|
|
174
|
+
throw error;
|
|
175
|
+
if (error && typeof error === 'object') {
|
|
176
|
+
if (error.code === "ENOENT" /* ERROR_CODE.ENOENT */ || error.message === 'ENOENT') {
|
|
177
|
+
if (options === null || options === void 0 ? void 0 : options.create) {
|
|
178
|
+
(0, util_1.assertCanWrite)(this.ctx.mode);
|
|
179
|
+
try {
|
|
180
|
+
this._core.writeFile(filename, buffer_1.Buffer.alloc(0), constants_1.FLAGS.w, 438 /* MODE.FILE */);
|
|
181
|
+
return new CoreFileSystemFileHandle_1.CoreFileSystemFileHandle(this._core, filename, this.ctx);
|
|
182
|
+
}
|
|
183
|
+
catch (createError) {
|
|
184
|
+
if (createError && typeof createError === 'object' && createError.code === "EACCES" /* ERROR_CODE.EACCES */) {
|
|
185
|
+
throw (0, util_1.newNotAllowedError)();
|
|
186
|
+
}
|
|
187
|
+
throw createError;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
throw (0, util_1.newNotFoundError)();
|
|
191
|
+
}
|
|
192
|
+
if (error.code === "EACCES" /* ERROR_CODE.EACCES */) {
|
|
193
|
+
throw (0, util_1.newNotAllowedError)();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Attempts to remove an entry if the directory handle contains a file or
|
|
201
|
+
* directory called the name specified.
|
|
202
|
+
*
|
|
203
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/removeEntry
|
|
204
|
+
* @param name A string representing the {@link CoreFileSystemHandle} name of the
|
|
205
|
+
* entry you wish to remove.
|
|
206
|
+
* @param options An optional object containing options.
|
|
207
|
+
*/
|
|
208
|
+
async removeEntry(name, { recursive = false } = {}) {
|
|
209
|
+
(0, util_1.assertCanWrite)(this.ctx.mode);
|
|
210
|
+
(0, util_1.assertName)(name, 'removeEntry', 'FileSystemDirectoryHandle');
|
|
211
|
+
const filename = this.__path + name;
|
|
212
|
+
try {
|
|
213
|
+
const link = this._core.getResolvedLinkOrThrow(filename);
|
|
214
|
+
const node = link.getNode();
|
|
215
|
+
if (node.isFile()) {
|
|
216
|
+
this._core.unlink(filename);
|
|
217
|
+
}
|
|
218
|
+
else if (node.isDirectory()) {
|
|
219
|
+
this._core.rmdir(filename, recursive);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
throw (0, util_1.newTypeMismatchError)();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
if (error instanceof DOMException)
|
|
227
|
+
throw error;
|
|
228
|
+
if (error && typeof error === 'object') {
|
|
229
|
+
switch (error.code) {
|
|
230
|
+
case "ENOENT" /* ERROR_CODE.ENOENT */: {
|
|
231
|
+
throw (0, util_1.newNotFoundError)();
|
|
232
|
+
}
|
|
233
|
+
case "EACCES" /* ERROR_CODE.EACCES */:
|
|
234
|
+
throw (0, util_1.newNotAllowedError)();
|
|
235
|
+
case "ENOTEMPTY" /* ERROR_CODE.ENOTEMPTY */:
|
|
236
|
+
throw new DOMException('The object can not be modified in this way.', 'InvalidModificationError');
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
throw error;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* The `resolve()` method of the {@link FileSystemDirectoryHandle} interface
|
|
244
|
+
* returns an {@link Array} of directory names from the parent handle to the specified
|
|
245
|
+
* child entry, with the name of the child entry as the last array item.
|
|
246
|
+
*
|
|
247
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/resolve
|
|
248
|
+
* @param possibleDescendant The {@link CoreFileSystemHandle} from which
|
|
249
|
+
* to return the relative path.
|
|
250
|
+
*/
|
|
251
|
+
async resolve(possibleDescendant) {
|
|
252
|
+
if (possibleDescendant instanceof CoreFileSystemDirectoryHandle ||
|
|
253
|
+
possibleDescendant instanceof CoreFileSystemFileHandle_1.CoreFileSystemFileHandle) {
|
|
254
|
+
// First check if they are from the same core instance
|
|
255
|
+
if (possibleDescendant._core !== this._core)
|
|
256
|
+
return null;
|
|
257
|
+
const path = this.__path;
|
|
258
|
+
const childPath = possibleDescendant.__path;
|
|
259
|
+
if (!childPath.startsWith(path))
|
|
260
|
+
return null;
|
|
261
|
+
let relative = childPath.slice(path.length);
|
|
262
|
+
if (relative === '')
|
|
263
|
+
return [];
|
|
264
|
+
const separator = this.ctx.separator;
|
|
265
|
+
if (relative[0] === separator)
|
|
266
|
+
relative = relative.slice(1);
|
|
267
|
+
return relative.split(separator);
|
|
268
|
+
}
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
_handleError(error, method) {
|
|
272
|
+
if (error instanceof DOMException)
|
|
273
|
+
throw error;
|
|
274
|
+
if (error && typeof error === 'object') {
|
|
275
|
+
switch (error.code) {
|
|
276
|
+
case "ENOENT" /* ERROR_CODE.ENOENT */:
|
|
277
|
+
throw (0, util_1.newNotFoundError)();
|
|
278
|
+
case "EACCES" /* ERROR_CODE.EACCES */:
|
|
279
|
+
throw (0, util_1.newNotAllowedError)();
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
throw error;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
exports.CoreFileSystemDirectoryHandle = CoreFileSystemDirectoryHandle;
|
|
286
|
+
//# sourceMappingURL=CoreFileSystemDirectoryHandle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoreFileSystemDirectoryHandle.js","sourceRoot":"","sources":["../../src/fsa/CoreFileSystemDirectoryHandle.ts"],"names":[],"mappings":";;;;AAAA,iEAA8D;AAC9D,iCAQgB;AAChB,yEAAsE;AAatE,+CAA4C;AAC5C,iDAAgD;AAEhD;;GAEG;AACH,MAAa,6BAA8B,SAAQ,2CAAoB;IAKrE,YACqB,KAAiB,EACpC,IAAY,EACZ,MAA+B,EAAE;QAEjC,MAAM,OAAO,GAAG,IAAA,UAAS,EAAC,GAAG,CAAC,CAAC;QAC/B,KAAK,CAAC,WAAW,EAAE,IAAA,eAAQ,EAAC,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CAAC;QAL5C,UAAK,GAAL,KAAK,CAAY;QAMp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SAAS;gBAAE,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAC5D,OAAO,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,YAAY,CAAC,KAAU,EAAE,MAAc;QAC7C,IAAI,KAAK,YAAY,YAAY;YAAE,MAAM,KAAK,CAAC;QAC/C,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACvC,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;gBACnB;oBACE,MAAM,IAAA,uBAAgB,GAAE,CAAC;gBAC3B;oBACE,MAAM,IAAA,yBAAkB,GAAE,CAAC;YAC/B,CAAC;QACH,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;CACF;AAzPD,sEAyPC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CoreFileSystemHandle } from './CoreFileSystemHandle';
|
|
2
|
+
import { CoreFileSystemWritableFileStream } from './CoreFileSystemWritableFileStream';
|
|
3
|
+
import type { CoreFsaContext, CreateWritableOptions, IFileSystemFileHandle, IFileSystemSyncAccessHandle } from './types';
|
|
4
|
+
import type { Superblock } from '../core/Superblock';
|
|
5
|
+
export declare class CoreFileSystemFileHandle extends CoreFileSystemHandle implements IFileSystemFileHandle {
|
|
6
|
+
protected readonly _core: Superblock;
|
|
7
|
+
readonly __path: string;
|
|
8
|
+
protected readonly ctx: CoreFsaContext;
|
|
9
|
+
constructor(_core: Superblock, __path: string, ctx?: Partial<CoreFsaContext>);
|
|
10
|
+
/**
|
|
11
|
+
* Returns a {@link Promise} which resolves to a {@link File} object
|
|
12
|
+
* representing the state on disk of the entry represented by the handle.
|
|
13
|
+
*
|
|
14
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/getFile
|
|
15
|
+
*/
|
|
16
|
+
getFile(): Promise<File>;
|
|
17
|
+
/**
|
|
18
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/createSyncAccessHandle
|
|
19
|
+
*/
|
|
20
|
+
get createSyncAccessHandle(): undefined | (() => Promise<IFileSystemSyncAccessHandle>);
|
|
21
|
+
/**
|
|
22
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/createWritable
|
|
23
|
+
*/
|
|
24
|
+
createWritable({ keepExistingData }?: CreateWritableOptions): Promise<CoreFileSystemWritableFileStream>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoreFileSystemFileHandle = void 0;
|
|
4
|
+
const CoreFileSystemHandle_1 = require("./CoreFileSystemHandle");
|
|
5
|
+
const CoreFileSystemSyncAccessHandle_1 = require("./CoreFileSystemSyncAccessHandle");
|
|
6
|
+
const util_1 = require("./util");
|
|
7
|
+
const CoreFileSystemWritableFileStream_1 = require("./CoreFileSystemWritableFileStream");
|
|
8
|
+
class CoreFileSystemFileHandle extends CoreFileSystemHandle_1.CoreFileSystemHandle {
|
|
9
|
+
constructor(_core, __path, ctx = {}) {
|
|
10
|
+
const fullCtx = (0, util_1.ctx)(ctx);
|
|
11
|
+
super('file', (0, util_1.basename)(__path, fullCtx.separator), fullCtx);
|
|
12
|
+
this._core = _core;
|
|
13
|
+
this.__path = __path;
|
|
14
|
+
this.ctx = fullCtx;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns a {@link Promise} which resolves to a {@link File} object
|
|
18
|
+
* representing the state on disk of the entry represented by the handle.
|
|
19
|
+
*
|
|
20
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/getFile
|
|
21
|
+
*/
|
|
22
|
+
async getFile() {
|
|
23
|
+
try {
|
|
24
|
+
const path = this.__path;
|
|
25
|
+
const link = this._core.getResolvedLinkOrThrow(path);
|
|
26
|
+
const node = link.getNode();
|
|
27
|
+
if (!node.isFile()) {
|
|
28
|
+
throw new Error('Not a file');
|
|
29
|
+
}
|
|
30
|
+
// Get file stats for lastModified
|
|
31
|
+
const lastModified = node.mtime ? node.mtime.getTime() : Date.now();
|
|
32
|
+
// Read file content
|
|
33
|
+
const buffer = node.getBuffer();
|
|
34
|
+
const data = new Uint8Array(buffer);
|
|
35
|
+
const file = new File([data], this.name, { lastModified });
|
|
36
|
+
return file;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (error instanceof DOMException)
|
|
40
|
+
throw error;
|
|
41
|
+
if (error && typeof error === 'object') {
|
|
42
|
+
switch (error.code) {
|
|
43
|
+
case "EACCES" /* ERROR_CODE.EACCES */:
|
|
44
|
+
throw (0, util_1.newNotAllowedError)();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/createSyncAccessHandle
|
|
52
|
+
*/
|
|
53
|
+
get createSyncAccessHandle() {
|
|
54
|
+
if (!this.ctx.syncHandleAllowed)
|
|
55
|
+
return undefined;
|
|
56
|
+
return async () => new CoreFileSystemSyncAccessHandle_1.CoreFileSystemSyncAccessHandle(this._core, this.__path, this.ctx);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/createWritable
|
|
60
|
+
*/
|
|
61
|
+
async createWritable({ keepExistingData = false } = { keepExistingData: false }) {
|
|
62
|
+
(0, util_1.assertCanWrite)(this.ctx.mode);
|
|
63
|
+
return new CoreFileSystemWritableFileStream_1.CoreFileSystemWritableFileStream(this._core, this.__path, keepExistingData);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.CoreFileSystemFileHandle = CoreFileSystemFileHandle;
|
|
67
|
+
//# sourceMappingURL=CoreFileSystemFileHandle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AI,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC;YAC3D,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,YAAY;gBAAE,MAAM,KAAK,CAAC;YAC/C,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBACvC,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;oBACnB;wBACE,MAAM,IAAA,yBAAkB,GAAE,CAAC;gBAC/B,CAAC;YACH,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED;;OAEG;IACH,IAAW,sBAAsB;QAC/B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,iBAAiB;YAAE,OAAO,SAAS,CAAC;QAClD,OAAO,KAAK,IAAI,EAAE,CAAC,IAAI,+DAA8B,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3F,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,cAAc,CACzB,EAAE,gBAAgB,GAAG,KAAK,KAA4B,EAAE,gBAAgB,EAAE,KAAK,EAAE;QAEjF,IAAA,qBAAc,EAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC9B,OAAO,IAAI,mEAAgC,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACzF,CAAC;CACF;AAnED,4DAmEC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CorePermissionStatus } from './CorePermissionStatus';
|
|
2
|
+
import type { IFileSystemHandle, FileSystemHandlePermissionDescriptor, CoreFsaContext } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a File System Access API file handle `FileSystemHandle` object,
|
|
5
|
+
* which was created from a core `Superblock`.
|
|
6
|
+
*
|
|
7
|
+
* @see [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle)
|
|
8
|
+
*/
|
|
9
|
+
export declare abstract class CoreFileSystemHandle implements IFileSystemHandle {
|
|
10
|
+
readonly kind: 'file' | 'directory';
|
|
11
|
+
readonly name: string;
|
|
12
|
+
protected readonly ctx: CoreFsaContext;
|
|
13
|
+
constructor(kind: 'file' | 'directory', name: string, ctx: CoreFsaContext);
|
|
14
|
+
/**
|
|
15
|
+
* Compares two handles to see if the associated entries (either a file or directory) match.
|
|
16
|
+
*
|
|
17
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/isSameEntry
|
|
18
|
+
*/
|
|
19
|
+
isSameEntry(fileSystemHandle: CoreFileSystemHandle): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/queryPermission
|
|
22
|
+
*/
|
|
23
|
+
queryPermission(fileSystemHandlePermissionDescriptor: FileSystemHandlePermissionDescriptor): CorePermissionStatus;
|
|
24
|
+
/**
|
|
25
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/remove
|
|
26
|
+
*/
|
|
27
|
+
remove({ recursive }?: {
|
|
28
|
+
recursive?: boolean;
|
|
29
|
+
}): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/requestPermission
|
|
32
|
+
*/
|
|
33
|
+
requestPermission(fileSystemHandlePermissionDescriptor: FileSystemHandlePermissionDescriptor): CorePermissionStatus;
|
|
34
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoreFileSystemHandle = void 0;
|
|
4
|
+
const CorePermissionStatus_1 = require("./CorePermissionStatus");
|
|
5
|
+
/**
|
|
6
|
+
* Represents a File System Access API file handle `FileSystemHandle` object,
|
|
7
|
+
* which was created from a core `Superblock`.
|
|
8
|
+
*
|
|
9
|
+
* @see [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle)
|
|
10
|
+
*/
|
|
11
|
+
class CoreFileSystemHandle {
|
|
12
|
+
constructor(kind, name, ctx) {
|
|
13
|
+
this.kind = kind;
|
|
14
|
+
this.name = name;
|
|
15
|
+
this.ctx = ctx;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Compares two handles to see if the associated entries (either a file or directory) match.
|
|
19
|
+
*
|
|
20
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/isSameEntry
|
|
21
|
+
*/
|
|
22
|
+
isSameEntry(fileSystemHandle) {
|
|
23
|
+
return (this.constructor === fileSystemHandle.constructor && this.__path === fileSystemHandle.__path);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/queryPermission
|
|
27
|
+
*/
|
|
28
|
+
queryPermission(fileSystemHandlePermissionDescriptor) {
|
|
29
|
+
// Check if the requested mode is compatible with the context mode
|
|
30
|
+
const requestedMode = fileSystemHandlePermissionDescriptor.mode;
|
|
31
|
+
const contextMode = this.ctx.mode;
|
|
32
|
+
// If requesting readwrite but context only allows read, deny
|
|
33
|
+
if (requestedMode === 'readwrite' && contextMode === 'read') {
|
|
34
|
+
return new CorePermissionStatus_1.CorePermissionStatus('denied', requestedMode);
|
|
35
|
+
}
|
|
36
|
+
// Otherwise grant the permission
|
|
37
|
+
return new CorePermissionStatus_1.CorePermissionStatus('granted', requestedMode);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/remove
|
|
41
|
+
*/
|
|
42
|
+
async remove({ recursive } = { recursive: false }) {
|
|
43
|
+
throw new Error('Not implemented');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/requestPermission
|
|
47
|
+
*/
|
|
48
|
+
requestPermission(fileSystemHandlePermissionDescriptor) {
|
|
49
|
+
throw new Error('Not implemented');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.CoreFileSystemHandle = CoreFileSystemHandle;
|
|
53
|
+
//# sourceMappingURL=CoreFileSystemHandle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoreFileSystemHandle.js","sourceRoot":"","sources":["../../src/fsa/CoreFileSystemHandle.ts"],"names":[],"mappings":";;;AAAA,iEAA8D;AAG9D;;;;;GAKG;AACH,MAAsB,oBAAoB;IAGxC,YACkB,IAA0B,EAC1B,IAAY,EAC5B,GAAmB;QAFH,SAAI,GAAJ,IAAI,CAAsB;QAC1B,SAAI,GAAJ,IAAI,CAAQ;QAG5B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAC,gBAAsC;QACvD,OAAO,CACL,IAAI,CAAC,WAAW,KAAK,gBAAgB,CAAC,WAAW,IAAK,IAAY,CAAC,MAAM,KAAM,gBAAwB,CAAC,MAAM,CAC/G,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,eAAe,CACpB,oCAA0E;QAE1E,kEAAkE;QAClE,MAAM,aAAa,GAAG,oCAAoC,CAAC,IAAI,CAAC;QAChE,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;QAElC,6DAA6D;QAC7D,IAAI,aAAa,KAAK,WAAW,IAAI,WAAW,KAAK,MAAM,EAAE,CAAC;YAC5D,OAAO,IAAI,2CAAoB,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;QAC3D,CAAC;QAED,iCAAiC;QACjC,OAAO,IAAI,2CAAoB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IAC5D,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,MAAM,CAAC,EAAE,SAAS,KAA8B,EAAE,SAAS,EAAE,KAAK,EAAE;QAC/E,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACI,iBAAiB,CACtB,oCAA0E;QAE1E,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;CACF;AAxDD,oDAwDC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { IFileSystemSyncAccessHandle, FileSystemReadWriteOptions, CoreFsaContext } from './types';
|
|
2
|
+
import type { Superblock } from '../core/Superblock';
|
|
3
|
+
/**
|
|
4
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle
|
|
5
|
+
*/
|
|
6
|
+
export declare class CoreFileSystemSyncAccessHandle implements IFileSystemSyncAccessHandle {
|
|
7
|
+
private readonly _core;
|
|
8
|
+
private readonly _path;
|
|
9
|
+
private readonly _ctx;
|
|
10
|
+
private _fd;
|
|
11
|
+
private _closed;
|
|
12
|
+
constructor(_core: Superblock, _path: string, _ctx: CoreFsaContext);
|
|
13
|
+
private _ensureOpen;
|
|
14
|
+
/**
|
|
15
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/close
|
|
16
|
+
*/
|
|
17
|
+
close(): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/flush
|
|
20
|
+
*/
|
|
21
|
+
flush(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/getSize
|
|
24
|
+
*/
|
|
25
|
+
getSize(): Promise<number>;
|
|
26
|
+
/**
|
|
27
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/read
|
|
28
|
+
*/
|
|
29
|
+
read(buffer: ArrayBuffer | ArrayBufferView, options?: FileSystemReadWriteOptions): Promise<number>;
|
|
30
|
+
/**
|
|
31
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/truncate
|
|
32
|
+
*/
|
|
33
|
+
truncate(newSize: number): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/write
|
|
36
|
+
*/
|
|
37
|
+
write(buffer: ArrayBuffer | ArrayBufferView | DataView, options?: FileSystemReadWriteOptions): Promise<number>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoreFileSystemSyncAccessHandle = void 0;
|
|
4
|
+
const buffer_1 = require("../internal/buffer");
|
|
5
|
+
const util_1 = require("./util");
|
|
6
|
+
const constants_1 = require("../node/constants");
|
|
7
|
+
/**
|
|
8
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle
|
|
9
|
+
*/
|
|
10
|
+
class CoreFileSystemSyncAccessHandle {
|
|
11
|
+
constructor(_core, _path, _ctx) {
|
|
12
|
+
this._core = _core;
|
|
13
|
+
this._path = _path;
|
|
14
|
+
this._ctx = _ctx;
|
|
15
|
+
this._fd = null;
|
|
16
|
+
this._closed = false;
|
|
17
|
+
}
|
|
18
|
+
_ensureOpen() {
|
|
19
|
+
if (this._closed) {
|
|
20
|
+
throw new DOMException('The file handle is closed.', 'InvalidStateError');
|
|
21
|
+
}
|
|
22
|
+
if (this._fd === null) {
|
|
23
|
+
// Open file for read/write
|
|
24
|
+
const flags = this._ctx.mode === 'readwrite' ? constants_1.FLAGS['r+'] : constants_1.FLAGS.r;
|
|
25
|
+
this._fd = this._core.open(this._path, flags, 0o644);
|
|
26
|
+
}
|
|
27
|
+
return this._fd;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/close
|
|
31
|
+
*/
|
|
32
|
+
async close() {
|
|
33
|
+
if (this._fd !== null) {
|
|
34
|
+
this._core.close(this._fd);
|
|
35
|
+
this._fd = null;
|
|
36
|
+
}
|
|
37
|
+
this._closed = true;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/flush
|
|
41
|
+
*/
|
|
42
|
+
async flush() {
|
|
43
|
+
const fd = this._ensureOpen();
|
|
44
|
+
// Core doesn't have an explicit flush method, but we can try to sync if available
|
|
45
|
+
// For now, this is a no-op as the core writes are synchronous
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/getSize
|
|
49
|
+
*/
|
|
50
|
+
async getSize() {
|
|
51
|
+
try {
|
|
52
|
+
const link = this._core.getResolvedLinkOrThrow(this._path);
|
|
53
|
+
const node = link.getNode();
|
|
54
|
+
return node.getSize();
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (error && typeof error === 'object' && error.code === "EACCES" /* ERROR_CODE.EACCES */) {
|
|
58
|
+
throw (0, util_1.newNotAllowedError)();
|
|
59
|
+
}
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/read
|
|
65
|
+
*/
|
|
66
|
+
async read(buffer, options = {}) {
|
|
67
|
+
const fd = this._ensureOpen();
|
|
68
|
+
const { at: position = 0 } = options;
|
|
69
|
+
const buf = buffer_1.Buffer.from(buffer);
|
|
70
|
+
try {
|
|
71
|
+
return this._core.read(fd, buf, 0, buf.length, position);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (error && typeof error === 'object' && error.code === "EACCES" /* ERROR_CODE.EACCES */) {
|
|
75
|
+
throw (0, util_1.newNotAllowedError)();
|
|
76
|
+
}
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/truncate
|
|
82
|
+
*/
|
|
83
|
+
async truncate(newSize) {
|
|
84
|
+
if (this._ctx.mode !== 'readwrite') {
|
|
85
|
+
throw (0, util_1.newNotAllowedError)();
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
const link = this._core.getResolvedLinkOrThrow(this._path);
|
|
89
|
+
const node = link.getNode();
|
|
90
|
+
node.truncate(newSize);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
if (error && typeof error === 'object' && error.code === "EACCES" /* ERROR_CODE.EACCES */) {
|
|
94
|
+
throw (0, util_1.newNotAllowedError)();
|
|
95
|
+
}
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/write
|
|
101
|
+
*/
|
|
102
|
+
async write(buffer, options = {}) {
|
|
103
|
+
if (this._ctx.mode !== 'readwrite') {
|
|
104
|
+
throw (0, util_1.newNotAllowedError)();
|
|
105
|
+
}
|
|
106
|
+
const fd = this._ensureOpen();
|
|
107
|
+
const { at: position = 0 } = options;
|
|
108
|
+
const buf = buffer_1.Buffer.from(buffer);
|
|
109
|
+
try {
|
|
110
|
+
return this._core.write(fd, buf, 0, buf.length, position);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (error && typeof error === 'object' && error.code === "EACCES" /* ERROR_CODE.EACCES */) {
|
|
114
|
+
throw (0, util_1.newNotAllowedError)();
|
|
115
|
+
}
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.CoreFileSystemSyncAccessHandle = CoreFileSystemSyncAccessHandle;
|
|
121
|
+
//# sourceMappingURL=CoreFileSystemSyncAccessHandle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoreFileSystemSyncAccessHandle.js","sourceRoot":"","sources":["../../src/fsa/CoreFileSystemSyncAccessHandle.ts"],"names":[],"mappings":";;;AAEA,+CAA4C;AAE5C,iCAA4C;AAC5C,iDAA0C;AAE1C;;GAEG;AACH,MAAa,8BAA8B;IAIzC,YACmB,KAAiB,EACjB,KAAa,EACb,IAAoB;QAFpB,UAAK,GAAL,KAAK,CAAY;QACjB,UAAK,GAAL,KAAK,CAAQ;QACb,SAAI,GAAJ,IAAI,CAAgB;QAN/B,QAAG,GAAkB,IAAI,CAAC;QAC1B,YAAO,GAAG,KAAK,CAAC;IAMrB,CAAC;IAEI,WAAW;QACjB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,IAAI,YAAY,CAAC,4BAA4B,EAAE,mBAAmB,CAAC,CAAC;QAC5E,CAAC;QACD,IAAI,IAAI,CAAC,GAAG,KAAK,IAAI,EAAE,CAAC;YACtB,2BAA2B;YAC3B,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,iBAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,iBAAK,CAAC,CAAC,CAAC;YACrE,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,KAAK;QAChB,IAAI,IAAI,CAAC,GAAG,KAAK,IAAI,EAAE,CAAC;YACtB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC3B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC;QAClB,CAAC;Q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KAAK,EAAE,CAAC;YACf,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,qCAAsB,EAAE,CAAC;gBAC3E,MAAM,IAAA,yBAAkB,GAAE,CAAC;YAC7B,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AAxHD,wEAwHC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IFileSystemWritableFileStream, FileSystemWritableFileStreamParams, Data } from './types';
|
|
2
|
+
import type { Superblock } from '../core/Superblock';
|
|
3
|
+
/**
|
|
4
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream
|
|
5
|
+
*/
|
|
6
|
+
export declare class CoreFileSystemWritableFileStream extends WritableStream implements IFileSystemWritableFileStream {
|
|
7
|
+
private _fd;
|
|
8
|
+
private _position;
|
|
9
|
+
private _closed;
|
|
10
|
+
private readonly _core;
|
|
11
|
+
private readonly _path;
|
|
12
|
+
constructor(core: Superblock, path: string, keepExistingData?: boolean);
|
|
13
|
+
/**
|
|
14
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/seek
|
|
15
|
+
*/
|
|
16
|
+
seek(position: number): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/truncate
|
|
19
|
+
*/
|
|
20
|
+
truncate(size: number): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/write
|
|
23
|
+
*/
|
|
24
|
+
write(chunk: Data): Promise<void>;
|
|
25
|
+
write(params: FileSystemWritableFileStreamParams): Promise<void>;
|
|
26
|
+
private _write;
|
|
27
|
+
private _isParams;
|
|
28
|
+
private _dataToBuffer;
|
|
29
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoreFileSystemWritableFileStream = void 0;
|
|
4
|
+
const buffer_1 = require("../internal/buffer");
|
|
5
|
+
const util_1 = require("./util");
|
|
6
|
+
const constants_1 = require("../node/constants");
|
|
7
|
+
/**
|
|
8
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream
|
|
9
|
+
*/
|
|
10
|
+
class CoreFileSystemWritableFileStream extends WritableStream {
|
|
11
|
+
constructor(core, path, keepExistingData = false) {
|
|
12
|
+
let fd;
|
|
13
|
+
super({
|
|
14
|
+
start: controller => {
|
|
15
|
+
// Open file for writing
|
|
16
|
+
const flags = keepExistingData ? constants_1.FLAGS['r+'] : constants_1.FLAGS.w;
|
|
17
|
+
try {
|
|
18
|
+
fd = core.open(path, flags, 438 /* MODE.FILE */);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (error && typeof error === 'object' && error.code === "EACCES" /* ERROR_CODE.EACCES */) {
|
|
22
|
+
throw (0, util_1.newNotAllowedError)();
|
|
23
|
+
}
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
write: async (chunk) => {
|
|
28
|
+
await this._write(chunk);
|
|
29
|
+
},
|
|
30
|
+
close: async () => {
|
|
31
|
+
if (!this._closed && this._fd !== undefined) {
|
|
32
|
+
core.close(this._fd);
|
|
33
|
+
this._closed = true;
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
abort: async () => {
|
|
37
|
+
if (!this._closed && this._fd !== undefined) {
|
|
38
|
+
core.close(this._fd);
|
|
39
|
+
this._closed = true;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
this._position = 0;
|
|
44
|
+
this._closed = false;
|
|
45
|
+
this._core = core;
|
|
46
|
+
this._path = path;
|
|
47
|
+
this._fd = fd;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/seek
|
|
51
|
+
*/
|
|
52
|
+
async seek(position) {
|
|
53
|
+
if (this._closed) {
|
|
54
|
+
throw new DOMException('The stream is closed.', 'InvalidStateError');
|
|
55
|
+
}
|
|
56
|
+
this._position = position;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/truncate
|
|
60
|
+
*/
|
|
61
|
+
async truncate(size) {
|
|
62
|
+
if (this._closed) {
|
|
63
|
+
throw new DOMException('The stream is closed.', 'InvalidStateError');
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const link = this._core.getResolvedLinkOrThrow(this._path);
|
|
67
|
+
const node = link.getNode();
|
|
68
|
+
node.truncate(size);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (error && typeof error === 'object' && error.code === "EACCES" /* ERROR_CODE.EACCES */) {
|
|
72
|
+
throw (0, util_1.newNotAllowedError)();
|
|
73
|
+
}
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async write(chunkOrParams) {
|
|
78
|
+
await this._write(chunkOrParams);
|
|
79
|
+
}
|
|
80
|
+
async _write(chunkOrParams) {
|
|
81
|
+
if (this._closed) {
|
|
82
|
+
throw new DOMException('The stream is closed.', 'InvalidStateError');
|
|
83
|
+
}
|
|
84
|
+
if (this._fd === undefined) {
|
|
85
|
+
throw new DOMException('The stream is not ready.', 'InvalidStateError');
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
if (this._isParams(chunkOrParams)) {
|
|
89
|
+
const params = chunkOrParams;
|
|
90
|
+
switch (params.type) {
|
|
91
|
+
case 'write': {
|
|
92
|
+
if (params.data !== undefined) {
|
|
93
|
+
const buffer = this._dataToBuffer(params.data);
|
|
94
|
+
const position = params.position !== undefined ? params.position : this._position;
|
|
95
|
+
const written = this._core.write(this._fd, buffer, 0, buffer.length, position);
|
|
96
|
+
if (params.position === undefined) {
|
|
97
|
+
this._position += written;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case 'seek': {
|
|
103
|
+
if (params.position !== undefined) {
|
|
104
|
+
this._position = params.position;
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
case 'truncate': {
|
|
109
|
+
if (params.size !== undefined) {
|
|
110
|
+
await this.truncate(params.size);
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
// Direct data write
|
|
118
|
+
const buffer = this._dataToBuffer(chunkOrParams);
|
|
119
|
+
const written = this._core.write(this._fd, buffer, 0, buffer.length, this._position);
|
|
120
|
+
this._position += written;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (error && typeof error === 'object' && error.code === "EACCES" /* ERROR_CODE.EACCES */) {
|
|
125
|
+
throw (0, util_1.newNotAllowedError)();
|
|
126
|
+
}
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
_isParams(chunk) {
|
|
131
|
+
return !!(chunk && typeof chunk === 'object' && 'type' in chunk);
|
|
132
|
+
}
|
|
133
|
+
_dataToBuffer(data) {
|
|
134
|
+
if (typeof data === 'string') {
|
|
135
|
+
return buffer_1.Buffer.from(data, 'utf8');
|
|
136
|
+
}
|
|
137
|
+
if (data instanceof buffer_1.Buffer) {
|
|
138
|
+
return data;
|
|
139
|
+
}
|
|
140
|
+
if (data instanceof ArrayBuffer) {
|
|
141
|
+
return buffer_1.Buffer.from(data);
|
|
142
|
+
}
|
|
143
|
+
if (ArrayBuffer.isView(data)) {
|
|
144
|
+
return buffer_1.Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
145
|
+
}
|
|
146
|
+
if (data instanceof Blob) {
|
|
147
|
+
// For Blob, we would need to read it asynchronously
|
|
148
|
+
// This is a simplified implementation
|
|
149
|
+
throw new Error('Blob data type not fully supported in this implementation');
|
|
150
|
+
}
|
|
151
|
+
throw new Error('Unsupported data type');
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.CoreFileSystemWritableFileStream = CoreFileSystemWritableFileStream;
|
|
155
|
+
//# sourceMappingURL=CoreFileSystemWritableFileStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoreFileSystemWritableFileStream.js","sourceRoot":"","sources":["../../src/fsa/CoreFileSystemWritableFileStream.ts"],"names":[],"mappings":";;;AAEA,+CAA4C;AAE5C,iCAA4C;AAC5C,iDAAgD;AAEhD;;GAEG;AACH,MAAa,gCAAiC,SAAQ,cAAc;IAOlE,YAAY,IAAgB,EAAE,IAAY,EAAE,mBAA4B,KAAK;QAC3E,IAAI,EAAsB,CAAC;QAE3B,KAAK,CAAC;YACJ,KAAK,EAAE,UAAU,CAAC,EAAE;gBAClB,wBAAwB;gBACxB,MAAM,KAAK,GAAG,gBAAgB,CAAC,CAAC,CAAC,iBAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,iBAAK,CAAC,CAAC,CAAC;gBACvD,IAAI,CAAC;oBACH,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,sBAAY,CAAC;gBACzC,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,qCAAsB,EAAE,CAAC;wBAC3E,MAAM,IAAA,yBAAkB,GAAE,CAAC;oBAC7B,CAAC;oBACD,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;YACD,KAAK,EAAE,KAAK,EAAE,KAAgD,EAAE,EAAE;gBAChE,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC;YACD,KAAK,EAAE,KAAK,IAAI,EAAE;gBAChB,IA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AAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC;IACnE,CAAC;IAEO,aAAa,CAAC,IAAU;QAC9B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,OAAO,eAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACnC,CAAC;QACD,IAAI,IAAI,YAAY,eAAM,EAAE,CAAC;YAC3B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,IAAI,YAAY,WAAW,EAAE,CAAC;YAChC,OAAO,eAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC;QACD,IAAI,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7B,OAAO,eAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QACpE,CAAC;QACD,IAAI,IAAI,YAAY,IAAI,EAAE,CAAC;YACzB,oDAAoD;YACpD,sCAAsC;YACtC,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;QAC/E,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC3C,CAAC;CACF;AA9JD,4EA8JC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IPermissionStatus } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/PermissionStatus
|
|
4
|
+
*/
|
|
5
|
+
export declare class CorePermissionStatus implements IPermissionStatus {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly state: 'granted' | 'denied' | 'prompt';
|
|
8
|
+
constructor(state: 'granted' | 'denied' | 'prompt', name?: string);
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CorePermissionStatus = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/PermissionStatus
|
|
6
|
+
*/
|
|
7
|
+
class CorePermissionStatus {
|
|
8
|
+
constructor(state, name = '') {
|
|
9
|
+
this.name = name;
|
|
10
|
+
this.state = state;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.CorePermissionStatus = CorePermissionStatus;
|
|
14
|
+
//# sourceMappingURL=CorePermissionStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CorePermissionStatus.js","sourceRoot":"","sources":["../../src/fsa/CorePermissionStatus.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,oBAAoB;IAI/B,YAAY,KAAsC,EAAE,OAAe,EAAE;QACnE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AARD,oDAQC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CoreFileSystemDirectoryHandle } from './CoreFileSystemDirectoryHandle';
|
|
2
|
+
import { CoreFsaContext } from './types';
|
|
3
|
+
import { Superblock } from '../core/Superblock';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export * from './CoreFileSystemHandle';
|
|
6
|
+
export * from './CoreFileSystemDirectoryHandle';
|
|
7
|
+
export * from './CoreFileSystemFileHandle';
|
|
8
|
+
export * from './CoreFileSystemSyncAccessHandle';
|
|
9
|
+
export * from './CoreFileSystemWritableFileStream';
|
|
10
|
+
export * from './CorePermissionStatus';
|
|
11
|
+
/**
|
|
12
|
+
* Creates a File System Access API implementation on top of a Superblock.
|
|
13
|
+
*/
|
|
14
|
+
export declare const coreToFsa: (core: Superblock, dirPath?: string, ctx?: Partial<CoreFsaContext>) => CoreFileSystemDirectoryHandle;
|
|
15
|
+
/**
|
|
16
|
+
* Create a new instance of an in-memory File System Access API
|
|
17
|
+
* implementation rooted at the root directory of the filesystem.
|
|
18
|
+
*
|
|
19
|
+
* @param ctx Optional context for the File System Access API.
|
|
20
|
+
* @returns A File System Access API implementation `dir` rooted at
|
|
21
|
+
* the root directory of the filesystem, as well as the `core`
|
|
22
|
+
* file system itself.
|
|
23
|
+
*/
|
|
24
|
+
export declare const fsa: (ctx?: Partial<CoreFsaContext>) => {
|
|
25
|
+
dir: CoreFileSystemDirectoryHandle;
|
|
26
|
+
core: Superblock;
|
|
27
|
+
};
|
package/lib/fsa/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fsa = exports.coreToFsa = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const CoreFileSystemDirectoryHandle_1 = require("./CoreFileSystemDirectoryHandle");
|
|
6
|
+
const Superblock_1 = require("../core/Superblock");
|
|
7
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./CoreFileSystemHandle"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./CoreFileSystemDirectoryHandle"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./CoreFileSystemFileHandle"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./CoreFileSystemSyncAccessHandle"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./CoreFileSystemWritableFileStream"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./CorePermissionStatus"), exports);
|
|
14
|
+
/**
|
|
15
|
+
* Creates a File System Access API implementation on top of a Superblock.
|
|
16
|
+
*/
|
|
17
|
+
const coreToFsa = (core, dirPath = '/', ctx) => {
|
|
18
|
+
return new CoreFileSystemDirectoryHandle_1.CoreFileSystemDirectoryHandle(core, dirPath, ctx);
|
|
19
|
+
};
|
|
20
|
+
exports.coreToFsa = coreToFsa;
|
|
21
|
+
/**
|
|
22
|
+
* Create a new instance of an in-memory File System Access API
|
|
23
|
+
* implementation rooted at the root directory of the filesystem.
|
|
24
|
+
*
|
|
25
|
+
* @param ctx Optional context for the File System Access API.
|
|
26
|
+
* @returns A File System Access API implementation `dir` rooted at
|
|
27
|
+
* the root directory of the filesystem, as well as the `core`
|
|
28
|
+
* file system itself.
|
|
29
|
+
*/
|
|
30
|
+
const fsa = (ctx) => {
|
|
31
|
+
const core = new Superblock_1.Superblock();
|
|
32
|
+
const dir = new CoreFileSystemDirectoryHandle_1.CoreFileSystemDirectoryHandle(core, '/', ctx);
|
|
33
|
+
return { dir, core };
|
|
34
|
+
};
|
|
35
|
+
exports.fsa = fsa;
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fsa/index.ts"],"names":[],"mappings":";;;;AAAA,mFAAgF;AAEhF,mDAAgD;AAEhD,kDAAwB;AACxB,iEAAuC;AACvC,0EAAgD;AAChD,qEAA2C;AAC3C,2EAAiD;AACjD,6EAAmD;AACnD,iEAAuC;AAEvC;;GAEG;AACI,MAAM,SAAS,GAAG,CACvB,IAAgB,EAChB,UAAkB,GAAG,EACrB,GAA6B,EACE,EAAE;IACjC,OAAO,IAAI,6DAA6B,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;AAC/D,CAAC,CAAC;AANW,QAAA,SAAS,aAMpB;AAEF;;;;;;;;GAQG;AACI,MAAM,GAAG,GAAG,CAAC,GAA6B,EAAE,EAAE;IACnD,MAAM,IAAI,GAAG,IAAI,uBAAU,EAAE,CAAC;IAC9B,MAAM,GAAG,GAAG,IAAI,6DAA6B,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAC9D,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;AACvB,CAAC,CAAC;AAJW,QAAA,GAAG,OAId"}
|
package/lib/fsa/types.d.ts
CHANGED
|
@@ -24,6 +24,19 @@ export interface IFileSystemDirectoryHandle extends IFileSystemHandle {
|
|
|
24
24
|
removeEntry(name: string, options?: RemoveEntryOptions): Promise<void>;
|
|
25
25
|
resolve(possibleDescendant: IFileSystemHandle): Promise<string[] | null>;
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Context for Core FSA operations - similar to NodeFsaContext but for Superblock
|
|
29
|
+
*/
|
|
30
|
+
export interface CoreFsaContext {
|
|
31
|
+
separator: '/' | '\\';
|
|
32
|
+
/** Whether synchronous file handles are allowed. */
|
|
33
|
+
syncHandleAllowed: boolean;
|
|
34
|
+
/** Whether writes are allowed, defaults to `read`. */
|
|
35
|
+
mode: 'read' | 'readwrite';
|
|
36
|
+
}
|
|
37
|
+
export interface CreateWritableOptions {
|
|
38
|
+
keepExistingData?: boolean;
|
|
39
|
+
}
|
|
27
40
|
export interface GetDirectoryHandleOptions {
|
|
28
41
|
/**
|
|
29
42
|
* A boolean value, which defaults to `false`. When set to `true` if the directory
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CoreFsaContext } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new {@link CoreFsaContext}.
|
|
4
|
+
*/
|
|
5
|
+
export declare const ctx: (partial?: Partial<CoreFsaContext>) => CoreFsaContext;
|
|
6
|
+
export declare const basename: (path: string, separator: string) => string;
|
|
7
|
+
export declare const assertName: (name: string, method: string, klass: string) => void;
|
|
8
|
+
export declare const assertCanWrite: (mode: "read" | "readwrite") => void;
|
|
9
|
+
export declare const newNotFoundError: () => DOMException;
|
|
10
|
+
export declare const newTypeMismatchError: () => DOMException;
|
|
11
|
+
export declare const newNotAllowedError: () => DOMException;
|
package/lib/fsa/util.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.newNotAllowedError = exports.newTypeMismatchError = exports.newNotFoundError = exports.assertCanWrite = exports.assertName = exports.basename = exports.ctx = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new {@link CoreFsaContext}.
|
|
6
|
+
*/
|
|
7
|
+
const ctx = (partial = {}) => {
|
|
8
|
+
return Object.assign({ separator: '/', syncHandleAllowed: false, mode: 'read' }, partial);
|
|
9
|
+
};
|
|
10
|
+
exports.ctx = ctx;
|
|
11
|
+
const basename = (path, separator) => {
|
|
12
|
+
if (path[path.length - 1] === separator)
|
|
13
|
+
path = path.slice(0, -1);
|
|
14
|
+
const lastSlashIndex = path.lastIndexOf(separator);
|
|
15
|
+
return lastSlashIndex === -1 ? path : path.slice(lastSlashIndex + 1);
|
|
16
|
+
};
|
|
17
|
+
exports.basename = basename;
|
|
18
|
+
const nameRegex = /^(\.{1,2})$|[\/\\]/;
|
|
19
|
+
const assertName = (name, method, klass) => {
|
|
20
|
+
const isInvalid = !name || nameRegex.test(name);
|
|
21
|
+
if (isInvalid)
|
|
22
|
+
throw new TypeError(`Failed to execute '${method}' on '${klass}': Name is not allowed.`);
|
|
23
|
+
};
|
|
24
|
+
exports.assertName = assertName;
|
|
25
|
+
const assertCanWrite = (mode) => {
|
|
26
|
+
if (mode !== 'readwrite')
|
|
27
|
+
throw new DOMException('The request is not allowed by the user agent or the platform in the current context.', 'NotAllowedError');
|
|
28
|
+
};
|
|
29
|
+
exports.assertCanWrite = assertCanWrite;
|
|
30
|
+
const newNotFoundError = () => new DOMException('A requested file or directory could not be found at the time an operation was processed.', 'NotFoundError');
|
|
31
|
+
exports.newNotFoundError = newNotFoundError;
|
|
32
|
+
const newTypeMismatchError = () => new DOMException('The path supplied exists, but was not an entry of requested type.', 'TypeMismatchError');
|
|
33
|
+
exports.newTypeMismatchError = newTypeMismatchError;
|
|
34
|
+
const newNotAllowedError = () => new DOMException('Permission not granted.', 'NotAllowedError');
|
|
35
|
+
exports.newNotAllowedError = newNotAllowedError;
|
|
36
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/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