@zenfs/dom 0.0.2 → 0.0.4
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/FileSystemAccess.d.ts +6 -7
- package/dist/backends/FileSystemAccess.js +3 -4
- package/dist/backends/HTTPRequest.d.ts +4 -6
- package/dist/backends/HTTPRequest.js +5 -10
- package/dist/backends/IndexedDB.d.ts +2 -3
- package/dist/backends/IndexedDB.js +3 -16
- package/dist/backends/Storage.d.ts +4 -5
- package/dist/backends/Storage.js +2 -2
- package/dist/backends/Worker.js +4 -4
- package/dist/browser.min.js +3 -8
- package/dist/browser.min.js.map +4 -4
- package/dist/fetch.d.ts +2 -3
- package/dist/fetch.js +3 -5
- package/package.json +10 -14
- package/readme.md +2 -13
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import { Cred } from '@zenfs/core/cred.js';
|
|
3
|
-
import {
|
|
2
|
+
import { FileFlag, PreloadFile } from '@zenfs/core/file.js';
|
|
4
3
|
import { BaseFileSystem, FileSystemMetadata } from '@zenfs/core/filesystem.js';
|
|
5
4
|
import { Stats } from '@zenfs/core/stats.js';
|
|
6
5
|
import { type BackendOptions } from '@zenfs/core/backends/backend.js';
|
|
@@ -15,8 +14,8 @@ declare global {
|
|
|
15
14
|
interface FileSystemAccessFileSystemOptions {
|
|
16
15
|
handle: FileSystemDirectoryHandle;
|
|
17
16
|
}
|
|
18
|
-
export declare class FileSystemAccessFile extends PreloadFile<FileSystemAccessFileSystem>
|
|
19
|
-
constructor(_fs: FileSystemAccessFileSystem, _path: string, _flag: FileFlag, _stat: Stats, contents?:
|
|
17
|
+
export declare class FileSystemAccessFile extends PreloadFile<FileSystemAccessFileSystem> {
|
|
18
|
+
constructor(_fs: FileSystemAccessFileSystem, _path: string, _flag: FileFlag, _stat: Stats, contents?: Uint8Array);
|
|
20
19
|
sync(): Promise<void>;
|
|
21
20
|
close(): Promise<void>;
|
|
22
21
|
}
|
|
@@ -28,13 +27,13 @@ export declare class FileSystemAccessFileSystem extends BaseFileSystem {
|
|
|
28
27
|
private _handles;
|
|
29
28
|
constructor({ handle }: FileSystemAccessFileSystemOptions);
|
|
30
29
|
get metadata(): FileSystemMetadata;
|
|
31
|
-
_sync(p: string, data:
|
|
30
|
+
_sync(p: string, data: Uint8Array, stats: Stats, cred: Cred): Promise<void>;
|
|
32
31
|
rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
|
|
33
32
|
writeFile(fname: string, data: any, encoding: string | null, flag: FileFlag, mode: number, cred: Cred, createFile?: boolean): Promise<void>;
|
|
34
|
-
createFile(p: string, flag: FileFlag, mode: number, cred: Cred): Promise<
|
|
33
|
+
createFile(p: string, flag: FileFlag, mode: number, cred: Cred): Promise<FileSystemAccessFile>;
|
|
35
34
|
stat(path: string, cred: Cred): Promise<Stats>;
|
|
36
35
|
exists(p: string, cred: Cred): Promise<boolean>;
|
|
37
|
-
openFile(path: string, flags: FileFlag, cred: Cred): Promise<
|
|
36
|
+
openFile(path: string, flags: FileFlag, cred: Cred): Promise<FileSystemAccessFile>;
|
|
38
37
|
unlink(path: string, cred: Cred): Promise<void>;
|
|
39
38
|
rmdir(path: string, cred: Cred): Promise<void>;
|
|
40
39
|
mkdir(p: string, mode: any, cred: Cred): Promise<void>;
|
|
@@ -15,14 +15,13 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
15
15
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
16
16
|
};
|
|
17
17
|
var _a;
|
|
18
|
-
import { basename, dirname, join } from 'path';
|
|
18
|
+
import { basename, dirname, join } from '@zenfs/core/emulation/path.js';
|
|
19
19
|
import { ApiError, ErrorCode } from '@zenfs/core/ApiError.js';
|
|
20
20
|
import { Cred } from '@zenfs/core/cred.js';
|
|
21
21
|
import { FileFlag, PreloadFile } from '@zenfs/core/file.js';
|
|
22
22
|
import { BaseFileSystem } from '@zenfs/core/filesystem.js';
|
|
23
23
|
import { Stats, FileType } from '@zenfs/core/stats.js';
|
|
24
24
|
import { CreateBackend } from '@zenfs/core/backends/backend.js';
|
|
25
|
-
import { Buffer } from 'buffer';
|
|
26
25
|
const handleError = (path = '', error) => {
|
|
27
26
|
if (error.name === 'NotFoundError') {
|
|
28
27
|
throw ApiError.ENOENT(path);
|
|
@@ -115,7 +114,7 @@ export class FileSystemAccessFileSystem extends BaseFileSystem {
|
|
|
115
114
|
}
|
|
116
115
|
createFile(p, flag, mode, cred) {
|
|
117
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
-
yield this.writeFile(p,
|
|
117
|
+
yield this.writeFile(p, new Uint8Array(), null, flag, mode, cred, true);
|
|
119
118
|
return this.openFile(p, flag, cred);
|
|
120
119
|
});
|
|
121
120
|
}
|
|
@@ -213,7 +212,7 @@ export class FileSystemAccessFileSystem extends BaseFileSystem {
|
|
|
213
212
|
});
|
|
214
213
|
}
|
|
215
214
|
newFile(path, flag, data, size, lastModified) {
|
|
216
|
-
return new FileSystemAccessFile(this, path, flag, new Stats(FileType.FILE, size || 0, undefined, undefined, lastModified || new Date().getTime()),
|
|
215
|
+
return new FileSystemAccessFile(this, path, flag, new Stats(FileType.FILE, size || 0, undefined, undefined, lastModified || new Date().getTime()), new Uint8Array(data));
|
|
217
216
|
}
|
|
218
217
|
getHandle(path) {
|
|
219
218
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import { BaseFileSystem, FileContents, FileSystemMetadata } from '@zenfs/core/filesystem.js';
|
|
3
|
-
import {
|
|
3
|
+
import { FileFlag, NoSyncFile } from '@zenfs/core/file.js';
|
|
4
4
|
import { Stats } from '@zenfs/core/stats.js';
|
|
5
5
|
import { Cred } from '@zenfs/core/cred.js';
|
|
6
6
|
import { type BackendOptions } from '@zenfs/core/backends/backend.js';
|
|
@@ -58,19 +58,17 @@ export declare class HTTPRequest extends BaseFileSystem {
|
|
|
58
58
|
static isAvailable(): boolean;
|
|
59
59
|
readonly prefixUrl: string;
|
|
60
60
|
private _index;
|
|
61
|
-
private _requestFileInternal;
|
|
62
|
-
private _requestFileSizeInternal;
|
|
63
61
|
constructor({ index, baseUrl }: HTTPRequest.Options);
|
|
64
62
|
get metadata(): FileSystemMetadata;
|
|
65
63
|
empty(): void;
|
|
66
64
|
/**
|
|
67
65
|
* Special HTTPFS function: Preload the given file into the index.
|
|
68
66
|
* @param [String] path
|
|
69
|
-
* @param [ZenFS.
|
|
67
|
+
* @param [ZenFS.Uint8Array] buffer
|
|
70
68
|
*/
|
|
71
|
-
preloadFile(path: string, buffer:
|
|
69
|
+
preloadFile(path: string, buffer: Uint8Array): void;
|
|
72
70
|
stat(path: string, cred: Cred): Promise<Stats>;
|
|
73
|
-
open(path: string, flags: FileFlag, mode: number, cred: Cred): Promise<
|
|
71
|
+
open(path: string, flags: FileFlag, mode: number, cred: Cred): Promise<NoSyncFile<this>>;
|
|
74
72
|
readdir(path: string, cred: Cred): Promise<string[]>;
|
|
75
73
|
/**
|
|
76
74
|
* We have the entire file as a buffer; optimize readFile.
|
|
@@ -10,13 +10,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
var _a;
|
|
11
11
|
import { BaseFileSystem } from '@zenfs/core/filesystem.js';
|
|
12
12
|
import { ApiError, ErrorCode } from '@zenfs/core/ApiError.js';
|
|
13
|
-
import { copyingSlice } from '@zenfs/core/utils.js';
|
|
14
13
|
import { ActionType, NoSyncFile } from '@zenfs/core/file.js';
|
|
15
14
|
import { Stats } from '@zenfs/core/stats.js';
|
|
16
15
|
import { fetchIsAvailable, fetchFile, fetchFileSize } from '../fetch.js';
|
|
17
16
|
import { FileIndex, isIndexFileInode, isIndexDirInode } from '@zenfs/core/FileIndex.js';
|
|
18
17
|
import { CreateBackend } from '@zenfs/core/backends/backend.js';
|
|
19
18
|
import { R_OK } from '@zenfs/core/emulation/constants.js';
|
|
19
|
+
import { decode } from '@zenfs/core/utils.js';
|
|
20
20
|
/**
|
|
21
21
|
* A simple filesystem backed by HTTP downloads. You must create a directory listing using the
|
|
22
22
|
* `make_http_index` tool provided by ZenFS.
|
|
@@ -64,8 +64,6 @@ export class HTTPRequest extends BaseFileSystem {
|
|
|
64
64
|
baseUrl = baseUrl + '/';
|
|
65
65
|
}
|
|
66
66
|
this.prefixUrl = baseUrl;
|
|
67
|
-
this._requestFileInternal = fetchFile;
|
|
68
|
-
this._requestFileSizeInternal = fetchFileSize;
|
|
69
67
|
}
|
|
70
68
|
get metadata() {
|
|
71
69
|
return Object.assign(Object.assign({}, super.metadata), { name: _a.Name, readonly: true });
|
|
@@ -78,7 +76,7 @@ export class HTTPRequest extends BaseFileSystem {
|
|
|
78
76
|
/**
|
|
79
77
|
* Special HTTPFS function: Preload the given file into the index.
|
|
80
78
|
* @param [String] path
|
|
81
|
-
* @param [ZenFS.
|
|
79
|
+
* @param [ZenFS.Uint8Array] buffer
|
|
82
80
|
*/
|
|
83
81
|
preloadFile(path, buffer) {
|
|
84
82
|
const inode = this._index.getInode(path);
|
|
@@ -180,10 +178,7 @@ export class HTTPRequest extends BaseFileSystem {
|
|
|
180
178
|
try {
|
|
181
179
|
const fdCast = fd;
|
|
182
180
|
const fdBuff = fdCast.getBuffer();
|
|
183
|
-
|
|
184
|
-
return copyingSlice(fdBuff);
|
|
185
|
-
}
|
|
186
|
-
return fdBuff.toString(encoding);
|
|
181
|
+
return encoding ? decode(fdBuff) : fdBuff;
|
|
187
182
|
}
|
|
188
183
|
finally {
|
|
189
184
|
yield fd.close();
|
|
@@ -197,13 +192,13 @@ export class HTTPRequest extends BaseFileSystem {
|
|
|
197
192
|
return this.prefixUrl + filePath;
|
|
198
193
|
}
|
|
199
194
|
_requestFile(p, type) {
|
|
200
|
-
return
|
|
195
|
+
return fetchFile(this._getHTTPPath(p), type);
|
|
201
196
|
}
|
|
202
197
|
/**
|
|
203
198
|
* Only requests the HEAD content, for the file size.
|
|
204
199
|
*/
|
|
205
200
|
_requestFileSize(path) {
|
|
206
|
-
return
|
|
201
|
+
return fetchFileSize(this._getHTTPPath(path));
|
|
207
202
|
}
|
|
208
203
|
}
|
|
209
204
|
_a = HTTPRequest;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import { AsyncKeyValueROTransaction, AsyncKeyValueRWTransaction, AsyncKeyValueStore, AsyncKeyValueFileSystem } from '@zenfs/core/backends/AsyncStore.js';
|
|
3
2
|
import { type BackendOptions } from '@zenfs/core/backends/backend.js';
|
|
4
3
|
/**
|
|
@@ -8,7 +7,7 @@ export declare class IndexedDBROTransaction implements AsyncKeyValueROTransactio
|
|
|
8
7
|
tx: IDBTransaction;
|
|
9
8
|
store: IDBObjectStore;
|
|
10
9
|
constructor(tx: IDBTransaction, store: IDBObjectStore);
|
|
11
|
-
get(key: string): Promise<
|
|
10
|
+
get(key: string): Promise<Uint8Array>;
|
|
12
11
|
}
|
|
13
12
|
/**
|
|
14
13
|
* @hidden
|
|
@@ -18,7 +17,7 @@ export declare class IndexedDBRWTransaction extends IndexedDBROTransaction imple
|
|
|
18
17
|
/**
|
|
19
18
|
* @todo return false when add has a key conflict (no error)
|
|
20
19
|
*/
|
|
21
|
-
put(key: string, data:
|
|
20
|
+
put(key: string, data: Uint8Array, overwrite: boolean): Promise<boolean>;
|
|
22
21
|
del(key: string): Promise<void>;
|
|
23
22
|
commit(): Promise<void>;
|
|
24
23
|
abort(): Promise<void>;
|
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
var _a;
|
|
2
2
|
import { AsyncKeyValueFileSystem } from '@zenfs/core/backends/AsyncStore.js';
|
|
3
3
|
import { ApiError, ErrorCode } from '@zenfs/core/ApiError.js';
|
|
4
|
-
import { Buffer } from 'buffer';
|
|
5
4
|
import { CreateBackend } from '@zenfs/core/backends/backend.js';
|
|
6
|
-
/**
|
|
7
|
-
* Get the indexedDB constructor for the current browser.
|
|
8
|
-
* @hidden
|
|
9
|
-
*/
|
|
10
|
-
const indexedDB = (() => {
|
|
11
|
-
try {
|
|
12
|
-
return globalThis.indexedDB || globalThis.mozIndexedDB || globalThis.webkitIndexedDB || globalThis.msIndexedDB;
|
|
13
|
-
}
|
|
14
|
-
catch (_b) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
})();
|
|
18
5
|
/**
|
|
19
6
|
* Converts a DOMException or a DOMError from an IndexedDB event into a
|
|
20
7
|
* standardized ZenFS API error.
|
|
@@ -65,8 +52,8 @@ export class IndexedDBROTransaction {
|
|
|
65
52
|
resolve(result);
|
|
66
53
|
}
|
|
67
54
|
else {
|
|
68
|
-
// IDB data is stored as an
|
|
69
|
-
resolve(
|
|
55
|
+
// IDB data is stored as an ArrayUint8Array
|
|
56
|
+
resolve(Uint8Array.from(result));
|
|
70
57
|
}
|
|
71
58
|
};
|
|
72
59
|
}
|
|
@@ -195,7 +182,7 @@ export class IndexedDBFileSystem extends AsyncKeyValueFileSystem {
|
|
|
195
182
|
if (!(idbFactory instanceof IDBFactory)) {
|
|
196
183
|
return false;
|
|
197
184
|
}
|
|
198
|
-
const req =
|
|
185
|
+
const req = idbFactory.open('__zenfs_test__');
|
|
199
186
|
if (!req) {
|
|
200
187
|
return false;
|
|
201
188
|
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import { SyncKeyValueStore, SimpleSyncStore, SyncKeyValueFileSystem, SyncKeyValueRWTransaction } from '@zenfs/core/backends/SyncStore.js';
|
|
3
2
|
import { type BackendOptions } from '@zenfs/core/backends/backend.js';
|
|
4
3
|
/**
|
|
5
4
|
* A synchronous key-value store backed by Storage.
|
|
6
5
|
*/
|
|
7
6
|
export declare class StorageStore implements SyncKeyValueStore, SimpleSyncStore {
|
|
8
|
-
protected _storage:
|
|
7
|
+
protected _storage: Storage;
|
|
9
8
|
name(): string;
|
|
10
|
-
constructor(_storage:
|
|
9
|
+
constructor(_storage: Storage);
|
|
11
10
|
clear(): void;
|
|
12
11
|
beginTransaction(type: string): SyncKeyValueRWTransaction;
|
|
13
|
-
get(key: string):
|
|
14
|
-
put(key: string, data:
|
|
12
|
+
get(key: string): Uint8Array | undefined;
|
|
13
|
+
put(key: string, data: Uint8Array, overwrite: boolean): boolean;
|
|
15
14
|
del(key: string): void;
|
|
16
15
|
}
|
|
17
16
|
export declare namespace StorageFileSystem {
|
package/dist/backends/Storage.js
CHANGED
|
@@ -2,7 +2,7 @@ var _a;
|
|
|
2
2
|
import { SyncKeyValueFileSystem, SimpleSyncRWTransaction } from '@zenfs/core/backends/SyncStore.js';
|
|
3
3
|
import { ApiError, ErrorCode } from '@zenfs/core/ApiError.js';
|
|
4
4
|
import { CreateBackend } from '@zenfs/core/backends/backend.js';
|
|
5
|
-
import {
|
|
5
|
+
import { encode } from '@zenfs/core/utils.js';
|
|
6
6
|
/**
|
|
7
7
|
* A synchronous key-value store backed by Storage.
|
|
8
8
|
*/
|
|
@@ -25,7 +25,7 @@ export class StorageStore {
|
|
|
25
25
|
if (typeof data != 'string') {
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
return
|
|
28
|
+
return encode(data);
|
|
29
29
|
}
|
|
30
30
|
put(key, data, overwrite) {
|
|
31
31
|
try {
|
package/dist/backends/Worker.js
CHANGED
|
@@ -159,11 +159,11 @@ WorkerFS.Options = {
|
|
|
159
159
|
worker: {
|
|
160
160
|
type: 'object',
|
|
161
161
|
description: 'The target worker that you want to connect to, or the current worker if in a worker context.',
|
|
162
|
-
validator
|
|
162
|
+
validator(worker) {
|
|
163
163
|
// Check for a `postMessage` function.
|
|
164
|
-
if (typeof (
|
|
165
|
-
throw new ApiError(ErrorCode.EINVAL,
|
|
164
|
+
if (typeof (worker === null || worker === void 0 ? void 0 : worker.postMessage) != 'function') {
|
|
165
|
+
throw new ApiError(ErrorCode.EINVAL, 'option must be a Web Worker instance.');
|
|
166
166
|
}
|
|
167
|
-
}
|
|
167
|
+
},
|
|
168
168
|
},
|
|
169
169
|
};
|