@zenfs/dom 1.1.5 → 1.1.6
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/IndexedDB.d.ts +1 -1
- package/dist/IndexedDB.js +3 -4
- package/dist/access.d.ts +2 -2
- package/dist/access.js +5 -5
- package/dist/devices/dsp.js +2 -2
- package/dist/devices/framebuffer.js +2 -2
- package/dist/storage.d.ts +2 -2
- package/dist/storage.js +6 -5
- package/dist/xml.d.ts +8 -8
- package/dist/xml.js +29 -33
- package/package.json +3 -3
package/dist/IndexedDB.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ declare const _IndexedDB: {
|
|
|
52
52
|
readonly required: false;
|
|
53
53
|
};
|
|
54
54
|
};
|
|
55
|
-
readonly isAvailable: (idbFactory
|
|
55
|
+
readonly isAvailable: ({ idbFactory }: IndexedDBOptions) => Promise<boolean>;
|
|
56
56
|
readonly create: (options: IndexedDBOptions & Partial<SharedConfig>) => Promise<StoreFS<IndexedDBStore>>;
|
|
57
57
|
};
|
|
58
58
|
type _IndexedDB = typeof _IndexedDB;
|
package/dist/IndexedDB.js
CHANGED
|
@@ -89,11 +89,10 @@ const _IndexedDB = {
|
|
|
89
89
|
storeName: { type: 'string', required: false },
|
|
90
90
|
idbFactory: { type: 'object', required: false },
|
|
91
91
|
},
|
|
92
|
-
async isAvailable(idbFactory = globalThis.indexedDB) {
|
|
92
|
+
async isAvailable({ idbFactory = globalThis.indexedDB }) {
|
|
93
93
|
try {
|
|
94
|
-
if (!(idbFactory instanceof IDBFactory))
|
|
94
|
+
if (!(idbFactory instanceof IDBFactory))
|
|
95
95
|
return false;
|
|
96
|
-
}
|
|
97
96
|
const req = idbFactory.open('__zenfs_test');
|
|
98
97
|
await wrap(req);
|
|
99
98
|
return true;
|
|
@@ -102,7 +101,7 @@ const _IndexedDB = {
|
|
|
102
101
|
return false;
|
|
103
102
|
}
|
|
104
103
|
finally {
|
|
105
|
-
idbFactory
|
|
104
|
+
idbFactory?.deleteDatabase('__zenfs_test');
|
|
106
105
|
}
|
|
107
106
|
},
|
|
108
107
|
async create(options) {
|
package/dist/access.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CreationOptions, FileSystem } from '@zenfs/core';
|
|
1
|
+
import type { CreationOptions, FileSystem, InodeLike } from '@zenfs/core';
|
|
2
2
|
import { IndexFS } from '@zenfs/core';
|
|
3
3
|
export interface WebAccessOptions {
|
|
4
4
|
handle: FileSystemDirectoryHandle;
|
|
@@ -32,7 +32,7 @@ export declare class WebAccessFS extends WebAccessFS_base {
|
|
|
32
32
|
* @deprecated @internal @hidden
|
|
33
33
|
*/
|
|
34
34
|
writeFile(path: string, data: Uint8Array): Promise<void>;
|
|
35
|
-
mkdir(path: string,
|
|
35
|
+
mkdir(path: string, options: CreationOptions): Promise<InodeLike>;
|
|
36
36
|
protected get<const T extends FileSystemHandleKind | null>(kind: T | undefined, path: string, syscall?: string): T extends FileSystemHandleKind ? HKindToType<T> : FileSystemHandle;
|
|
37
37
|
}
|
|
38
38
|
declare const _WebAccess: {
|
package/dist/access.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Async, constants, Errno, ErrnoError, IndexFS, InMemory, Inode, log } from '@zenfs/core';
|
|
2
|
+
import { basename, dirname, join } from '@zenfs/core/path.js';
|
|
2
3
|
import { S_IFDIR, S_IFMT } from '@zenfs/core/vfs/constants.js';
|
|
3
|
-
import { basename, dirname, join } from '@zenfs/core/vfs/path.js';
|
|
4
4
|
import { _throw } from 'utilium';
|
|
5
5
|
import { convertException } from './utils.js';
|
|
6
6
|
function isResizable(buffer) {
|
|
@@ -59,9 +59,8 @@ export class WebAccessFS extends Async(IndexFS) {
|
|
|
59
59
|
/**
|
|
60
60
|
* @hidden
|
|
61
61
|
*/
|
|
62
|
-
this._sync = InMemory.create({
|
|
62
|
+
this._sync = InMemory.create({ label: 'accessfs-cache' });
|
|
63
63
|
this.attributes.set('no_buffer_resize');
|
|
64
|
-
this.attributes.set('setid');
|
|
65
64
|
this._handles.set('/', handle);
|
|
66
65
|
}
|
|
67
66
|
async remove(path) {
|
|
@@ -126,11 +125,12 @@ export class WebAccessFS extends Async(IndexFS) {
|
|
|
126
125
|
async writeFile(path, data) {
|
|
127
126
|
return this.write(path, data, 0);
|
|
128
127
|
}
|
|
129
|
-
async mkdir(path,
|
|
130
|
-
await super.mkdir(path,
|
|
128
|
+
async mkdir(path, options) {
|
|
129
|
+
const inode = await super.mkdir(path, options);
|
|
131
130
|
const handle = this.get('directory', dirname(path), 'mkdir');
|
|
132
131
|
const dir = await handle.getDirectoryHandle(basename(path), { create: true }).catch((ex) => _throw(convertException(ex, path)));
|
|
133
132
|
this._handles.set(path, dir);
|
|
133
|
+
return inode;
|
|
134
134
|
}
|
|
135
135
|
get(kind = null, path, syscall) {
|
|
136
136
|
const handle = this._handles.get(path);
|
package/dist/devices/dsp.js
CHANGED
|
@@ -44,10 +44,10 @@ export async function dsp(options = {}) {
|
|
|
44
44
|
init(ino, options) {
|
|
45
45
|
return { data: dsp, major: 14, minor: 3 };
|
|
46
46
|
},
|
|
47
|
-
|
|
47
|
+
read() {
|
|
48
48
|
return;
|
|
49
49
|
},
|
|
50
|
-
|
|
50
|
+
write(device, buffer, offset) {
|
|
51
51
|
device.data.port.postMessage(buffer.buffer);
|
|
52
52
|
},
|
|
53
53
|
};
|
|
@@ -27,8 +27,8 @@ export const framebuffer = {
|
|
|
27
27
|
name: 'fb',
|
|
28
28
|
};
|
|
29
29
|
},
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
read() { },
|
|
31
|
+
write({ data: { image, context } }, buffer, offset) {
|
|
32
32
|
image.data.set(buffer, offset);
|
|
33
33
|
context.putImageData(image, 0, 0);
|
|
34
34
|
return buffer.byteLength;
|
package/dist/storage.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Store, SyncMapStore } from '@zenfs/core';
|
|
2
2
|
import { StoreFS, SyncMapTransaction } from '@zenfs/core';
|
|
3
3
|
/**
|
|
4
4
|
* A synchronous key-value store backed by Storage.
|
|
@@ -39,7 +39,7 @@ declare const _WebStorage: {
|
|
|
39
39
|
/**
|
|
40
40
|
* @todo Consider replacing `instanceof` with a duck-typing check?
|
|
41
41
|
*/
|
|
42
|
-
readonly isAvailable: (
|
|
42
|
+
readonly isAvailable: (config?: WebStorageOptions) => boolean;
|
|
43
43
|
readonly create: ({ storage }: WebStorageOptions) => StoreFS<WebStorageStore>;
|
|
44
44
|
};
|
|
45
45
|
type _WebStorage = typeof _WebStorage;
|
package/dist/storage.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Errno, ErrnoError, StoreFS, SyncMapTransaction } from '@zenfs/core';
|
|
2
|
+
import { decodeASCII, encodeASCII } from 'utilium';
|
|
2
3
|
/**
|
|
3
4
|
* A synchronous key-value store backed by Storage.
|
|
4
5
|
*/
|
|
@@ -28,11 +29,11 @@ export class WebStorageStore {
|
|
|
28
29
|
if (typeof data != 'string') {
|
|
29
30
|
return;
|
|
30
31
|
}
|
|
31
|
-
return
|
|
32
|
+
return encodeASCII(data);
|
|
32
33
|
}
|
|
33
34
|
set(key, data) {
|
|
34
35
|
try {
|
|
35
|
-
this.storage.setItem(key.toString(),
|
|
36
|
+
this.storage.setItem(key.toString(), decodeASCII(data));
|
|
36
37
|
}
|
|
37
38
|
catch {
|
|
38
39
|
throw new ErrnoError(Errno.ENOSPC, 'Storage is full.');
|
|
@@ -58,8 +59,8 @@ const _WebStorage = {
|
|
|
58
59
|
/**
|
|
59
60
|
* @todo Consider replacing `instanceof` with a duck-typing check?
|
|
60
61
|
*/
|
|
61
|
-
isAvailable(
|
|
62
|
-
return storage instanceof globalThis.Storage;
|
|
62
|
+
isAvailable(config) {
|
|
63
|
+
return (config?.storage ?? globalThis.localStorage) instanceof globalThis.Storage;
|
|
63
64
|
},
|
|
64
65
|
create({ storage = globalThis.localStorage }) {
|
|
65
66
|
return new StoreFS(new WebStorageStore(storage));
|
package/dist/xml.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CreationOptions,
|
|
2
|
-
import { FileSystem,
|
|
1
|
+
import type { CreationOptions, InodeLike, StatsLike } from '@zenfs/core';
|
|
2
|
+
import { FileSystem, Inode } from '@zenfs/core';
|
|
3
3
|
export interface XMLOptions {
|
|
4
4
|
/**
|
|
5
5
|
* The root `fs` element
|
|
@@ -18,15 +18,15 @@ export declare class XMLFS extends XMLFS_base {
|
|
|
18
18
|
*/
|
|
19
19
|
root?: Element);
|
|
20
20
|
renameSync(oldPath: string, newPath: string): void;
|
|
21
|
-
statSync(path: string):
|
|
22
|
-
|
|
23
|
-
createFileSync(path: string, flag: string, mode: number, { uid, gid }: CreationOptions): File;
|
|
21
|
+
statSync(path: string): Inode;
|
|
22
|
+
createFileSync(path: string, options: CreationOptions): Inode;
|
|
24
23
|
unlinkSync(path: string): void;
|
|
25
24
|
rmdirSync(path: string): void;
|
|
26
|
-
mkdirSync(path: string,
|
|
25
|
+
mkdirSync(path: string, options: CreationOptions): InodeLike;
|
|
27
26
|
readdirSync(path: string): string[];
|
|
28
27
|
linkSync(target: string, link: string): void;
|
|
29
|
-
|
|
28
|
+
touchSync(path: string, metadata: Partial<InodeLike>): void;
|
|
29
|
+
syncSync(): void;
|
|
30
30
|
readSync(path: string, buffer: Uint8Array, offset: number, end: number): void;
|
|
31
31
|
writeSync(path: string, buffer: Uint8Array, offset: number): void;
|
|
32
32
|
toString(): string;
|
|
@@ -39,7 +39,7 @@ declare const _XML: {
|
|
|
39
39
|
name: string;
|
|
40
40
|
options: {
|
|
41
41
|
root: {
|
|
42
|
-
type:
|
|
42
|
+
type: string;
|
|
43
43
|
required: false;
|
|
44
44
|
};
|
|
45
45
|
};
|
package/dist/xml.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { _inode_fields, constants,
|
|
2
|
-
import { basename, dirname } from '@zenfs/core/
|
|
1
|
+
import { _inode_fields, constants, Errno, ErrnoError, FileSystem, Inode, Sync } from '@zenfs/core';
|
|
2
|
+
import { basename, dirname } from '@zenfs/core/path.js';
|
|
3
|
+
import { decodeASCII, encodeASCII } from 'utilium';
|
|
3
4
|
function get_stats(node) {
|
|
4
5
|
const stats = {};
|
|
5
6
|
for (const key of _inode_fields) {
|
|
@@ -7,7 +8,7 @@ function get_stats(node) {
|
|
|
7
8
|
if (value !== null && value !== undefined)
|
|
8
9
|
stats[key] = parseInt(value, 16);
|
|
9
10
|
}
|
|
10
|
-
return new
|
|
11
|
+
return new Inode(stats);
|
|
11
12
|
}
|
|
12
13
|
function set_stats(node, stats) {
|
|
13
14
|
for (const key of Object.keys(stats)) {
|
|
@@ -35,9 +36,8 @@ export class XMLFS extends Sync(FileSystem) {
|
|
|
35
36
|
root = new DOMParser().parseFromString('<fs></fs>', 'application/xml').documentElement) {
|
|
36
37
|
super(0x20786d6c, 'xmltmpfs');
|
|
37
38
|
this.root = root;
|
|
38
|
-
this.attributes.set('setid');
|
|
39
39
|
try {
|
|
40
|
-
this.mkdirSync('/',
|
|
40
|
+
this.mkdirSync('/', { uid: 0, gid: 0, mode: 0o777 });
|
|
41
41
|
}
|
|
42
42
|
catch (e) {
|
|
43
43
|
const error = e;
|
|
@@ -53,23 +53,19 @@ export class XMLFS extends Sync(FileSystem) {
|
|
|
53
53
|
statSync(path) {
|
|
54
54
|
return get_stats(this.get('stat', path));
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
const node = this.get('openFile', path);
|
|
58
|
-
return new LazyFile(this, path, flag, get_stats(node));
|
|
59
|
-
}
|
|
60
|
-
createFileSync(path, flag, mode, { uid, gid }) {
|
|
56
|
+
createFileSync(path, options) {
|
|
61
57
|
const parent = this.statSync(dirname(path));
|
|
62
|
-
const
|
|
63
|
-
mode: mode | constants.S_IFREG,
|
|
64
|
-
uid: parent.mode & constants.S_ISUID ? parent.uid : uid,
|
|
65
|
-
gid: parent.mode & constants.S_ISGID ? parent.gid : gid,
|
|
58
|
+
const inode = new Inode({
|
|
59
|
+
mode: options.mode | constants.S_IFREG,
|
|
60
|
+
uid: parent.mode & constants.S_ISUID ? parent.uid : options.uid,
|
|
61
|
+
gid: parent.mode & constants.S_ISGID ? parent.gid : options.gid,
|
|
66
62
|
});
|
|
67
|
-
this.create('createFile', path,
|
|
68
|
-
return
|
|
63
|
+
this.create('createFile', path, inode);
|
|
64
|
+
return inode;
|
|
69
65
|
}
|
|
70
66
|
unlinkSync(path) {
|
|
71
67
|
const node = this.get('unlink', path);
|
|
72
|
-
if (get_stats(node).
|
|
68
|
+
if (get_stats(node).mode & constants.S_IFDIR)
|
|
73
69
|
throw ErrnoError.With('EISDIR', path, 'unlink');
|
|
74
70
|
this.remove('unlink', node, path);
|
|
75
71
|
}
|
|
@@ -77,22 +73,23 @@ export class XMLFS extends Sync(FileSystem) {
|
|
|
77
73
|
const node = this.get('rmdir', path);
|
|
78
74
|
if (node.textContent?.length)
|
|
79
75
|
throw ErrnoError.With('ENOTEMPTY', path, 'rmdir');
|
|
80
|
-
if (!get_stats(node).
|
|
76
|
+
if (!(get_stats(node).mode & constants.S_IFDIR))
|
|
81
77
|
throw ErrnoError.With('ENOTDIR', path, 'rmdir');
|
|
82
78
|
this.remove('rmdir', node, path);
|
|
83
79
|
}
|
|
84
|
-
mkdirSync(path,
|
|
80
|
+
mkdirSync(path, options) {
|
|
85
81
|
const parent = this.statSync(dirname(path));
|
|
86
|
-
const
|
|
87
|
-
mode: mode | constants.S_IFDIR,
|
|
88
|
-
uid: parent.mode & constants.S_ISUID ? parent.uid : uid,
|
|
89
|
-
gid: parent.mode & constants.S_ISGID ? parent.gid : gid,
|
|
82
|
+
const inode = new Inode({
|
|
83
|
+
mode: options.mode | constants.S_IFDIR,
|
|
84
|
+
uid: parent.mode & constants.S_ISUID ? parent.uid : options.uid,
|
|
85
|
+
gid: parent.mode & constants.S_ISGID ? parent.gid : options.gid,
|
|
90
86
|
});
|
|
91
|
-
|
|
87
|
+
this.create('mkdir', path, inode).textContent = '[]';
|
|
88
|
+
return inode;
|
|
92
89
|
}
|
|
93
90
|
readdirSync(path) {
|
|
94
91
|
const node = this.get('readdir', path);
|
|
95
|
-
if (!get_stats(node).
|
|
92
|
+
if (!(get_stats(node).mode & constants.S_IFDIR))
|
|
96
93
|
throw ErrnoError.With('ENOTDIR', path, 'rmdir');
|
|
97
94
|
try {
|
|
98
95
|
return JSON.parse(node.textContent);
|
|
@@ -105,20 +102,19 @@ export class XMLFS extends Sync(FileSystem) {
|
|
|
105
102
|
const node = this.get('link', target);
|
|
106
103
|
this.add('link', node, link);
|
|
107
104
|
}
|
|
108
|
-
|
|
109
|
-
const node = this.get('
|
|
110
|
-
|
|
111
|
-
node.textContent = decodeRaw(data);
|
|
112
|
-
set_stats(node, stats);
|
|
105
|
+
touchSync(path, metadata) {
|
|
106
|
+
const node = this.get('touch', path);
|
|
107
|
+
set_stats(node, metadata);
|
|
113
108
|
}
|
|
109
|
+
syncSync() { }
|
|
114
110
|
readSync(path, buffer, offset, end) {
|
|
115
111
|
const node = this.get('read', path);
|
|
116
|
-
const raw =
|
|
112
|
+
const raw = encodeASCII(node.textContent.slice(offset, end));
|
|
117
113
|
buffer.set(raw);
|
|
118
114
|
}
|
|
119
115
|
writeSync(path, buffer, offset) {
|
|
120
116
|
const node = this.get('write', path);
|
|
121
|
-
const data =
|
|
117
|
+
const data = decodeASCII(buffer);
|
|
122
118
|
const after = node.textContent.slice(offset + data.length);
|
|
123
119
|
node.textContent = node.textContent.slice(0, offset) + data + after;
|
|
124
120
|
}
|
|
@@ -140,7 +136,7 @@ export class XMLFS extends Sync(FileSystem) {
|
|
|
140
136
|
throw ErrnoError.With('EEXIST', path, syscall);
|
|
141
137
|
const node = document.createElement('file');
|
|
142
138
|
this.add(syscall, node, path);
|
|
143
|
-
set_stats(node, new
|
|
139
|
+
set_stats(node, new Inode({
|
|
144
140
|
...stats,
|
|
145
141
|
uid: stats.mode,
|
|
146
142
|
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenfs/dom",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"description": "DOM backends for ZenFS",
|
|
5
5
|
"funding": {
|
|
6
6
|
"type": "individual",
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
"typescript-eslint": "^8.8.1"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
-
"@zenfs/core": "^
|
|
65
|
-
"utilium": "^1.
|
|
64
|
+
"@zenfs/core": "^2.0.0",
|
|
65
|
+
"utilium": "^1.9.0"
|
|
66
66
|
},
|
|
67
67
|
"keywords": [
|
|
68
68
|
"filesystem",
|