@componentor/fs 1.2.7 → 2.0.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 +398 -634
- package/dist/index.cjs +2637 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +606 -0
- package/dist/index.d.ts +539 -481
- package/dist/index.js +2358 -2480
- package/dist/index.js.map +1 -1
- package/dist/kernel.js +496 -0
- package/dist/kernel.js.map +1 -0
- package/package.json +39 -45
- package/dist/opfs-hybrid.d.ts +0 -198
- package/dist/opfs-hybrid.js +0 -2743
- package/dist/opfs-hybrid.js.map +0 -1
- package/dist/opfs-worker-proxy.d.ts +0 -224
- package/dist/opfs-worker-proxy.js +0 -274
- package/dist/opfs-worker-proxy.js.map +0 -1
- package/dist/opfs-worker.js +0 -2923
- package/dist/opfs-worker.js.map +0 -1
- package/src/constants.ts +0 -52
- package/src/errors.ts +0 -88
- package/src/file-handle.ts +0 -100
- package/src/global.d.ts +0 -57
- package/src/handle-manager.ts +0 -302
- package/src/index.ts +0 -1416
- package/src/opfs-hybrid.ts +0 -265
- package/src/opfs-worker-proxy.ts +0 -374
- package/src/opfs-worker.ts +0 -253
- package/src/packed-storage.ts +0 -604
- package/src/path-utils.ts +0 -97
- package/src/streams.ts +0 -109
- package/src/symlink-manager.ts +0 -338
- package/src/types.ts +0 -289
package/src/opfs-worker.ts
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OPFS Worker Script
|
|
3
|
-
* Runs OPFS operations in a dedicated Web Worker for non-blocking main thread
|
|
4
|
-
*
|
|
5
|
-
* Usage: Create a worker with this script and communicate via postMessage
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import OPFS from './index.js'
|
|
9
|
-
import type { BatchWriteEntry, SymlinkDefinition } from './types.js'
|
|
10
|
-
|
|
11
|
-
// Message types
|
|
12
|
-
interface WorkerRequest {
|
|
13
|
-
id: number
|
|
14
|
-
method: string
|
|
15
|
-
args: unknown[]
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface WorkerResponse {
|
|
19
|
-
id: number
|
|
20
|
-
result?: unknown
|
|
21
|
-
error?: { message: string; code?: string }
|
|
22
|
-
// For transferable arrays
|
|
23
|
-
transfer?: ArrayBuffer[]
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Initialize OPFS with sync mode (available in workers)
|
|
27
|
-
let fs: OPFS | null = null
|
|
28
|
-
|
|
29
|
-
function getFS(): OPFS {
|
|
30
|
-
if (!fs) {
|
|
31
|
-
fs = new OPFS({ useSync: true, verbose: false })
|
|
32
|
-
}
|
|
33
|
-
return fs
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Handle incoming messages
|
|
37
|
-
self.onmessage = async (event: MessageEvent<WorkerRequest>) => {
|
|
38
|
-
const { id, method, args } = event.data
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
const opfs = getFS()
|
|
42
|
-
let result: unknown
|
|
43
|
-
const transfer: ArrayBuffer[] = []
|
|
44
|
-
|
|
45
|
-
// Route to appropriate method
|
|
46
|
-
switch (method) {
|
|
47
|
-
// File operations
|
|
48
|
-
case 'readFile': {
|
|
49
|
-
const data = await opfs.readFile(args[0] as string, args[1] as { encoding?: string })
|
|
50
|
-
if (data instanceof Uint8Array) {
|
|
51
|
-
// Transfer the buffer for zero-copy
|
|
52
|
-
result = data
|
|
53
|
-
transfer.push(data.buffer)
|
|
54
|
-
} else {
|
|
55
|
-
result = data
|
|
56
|
-
}
|
|
57
|
-
break
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
case 'writeFile':
|
|
61
|
-
await opfs.writeFile(args[0] as string, args[1] as string | Uint8Array, args[2] as object)
|
|
62
|
-
result = undefined
|
|
63
|
-
break
|
|
64
|
-
|
|
65
|
-
case 'readFileBatch': {
|
|
66
|
-
const results = await opfs.readFileBatch(args[0] as string[])
|
|
67
|
-
// Transfer all buffers
|
|
68
|
-
for (const r of results) {
|
|
69
|
-
if (r.data) {
|
|
70
|
-
transfer.push(r.data.buffer)
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
result = results
|
|
74
|
-
break
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
case 'writeFileBatch':
|
|
78
|
-
await opfs.writeFileBatch(args[0] as BatchWriteEntry[])
|
|
79
|
-
result = undefined
|
|
80
|
-
break
|
|
81
|
-
|
|
82
|
-
case 'appendFile':
|
|
83
|
-
await opfs.appendFile(args[0] as string, args[1] as string | Uint8Array, args[2] as object)
|
|
84
|
-
result = undefined
|
|
85
|
-
break
|
|
86
|
-
|
|
87
|
-
case 'copyFile':
|
|
88
|
-
await opfs.copyFile(args[0] as string, args[1] as string, args[2] as number)
|
|
89
|
-
result = undefined
|
|
90
|
-
break
|
|
91
|
-
|
|
92
|
-
case 'unlink':
|
|
93
|
-
await opfs.unlink(args[0] as string)
|
|
94
|
-
result = undefined
|
|
95
|
-
break
|
|
96
|
-
|
|
97
|
-
case 'truncate':
|
|
98
|
-
await opfs.truncate(args[0] as string, args[1] as number)
|
|
99
|
-
result = undefined
|
|
100
|
-
break
|
|
101
|
-
|
|
102
|
-
// Directory operations
|
|
103
|
-
case 'mkdir':
|
|
104
|
-
await opfs.mkdir(args[0] as string)
|
|
105
|
-
result = undefined
|
|
106
|
-
break
|
|
107
|
-
|
|
108
|
-
case 'rmdir':
|
|
109
|
-
await opfs.rmdir(args[0] as string)
|
|
110
|
-
result = undefined
|
|
111
|
-
break
|
|
112
|
-
|
|
113
|
-
case 'readdir':
|
|
114
|
-
result = await opfs.readdir(args[0] as string, args[1] as object)
|
|
115
|
-
break
|
|
116
|
-
|
|
117
|
-
case 'cp':
|
|
118
|
-
await opfs.cp(args[0] as string, args[1] as string, args[2] as object)
|
|
119
|
-
result = undefined
|
|
120
|
-
break
|
|
121
|
-
|
|
122
|
-
case 'rm':
|
|
123
|
-
await opfs.rm(args[0] as string, args[1] as object)
|
|
124
|
-
result = undefined
|
|
125
|
-
break
|
|
126
|
-
|
|
127
|
-
// Stat operations
|
|
128
|
-
case 'stat':
|
|
129
|
-
result = serializeStats(await opfs.stat(args[0] as string))
|
|
130
|
-
break
|
|
131
|
-
|
|
132
|
-
case 'lstat':
|
|
133
|
-
result = serializeStats(await opfs.lstat(args[0] as string))
|
|
134
|
-
break
|
|
135
|
-
|
|
136
|
-
case 'exists':
|
|
137
|
-
result = await opfs.exists(args[0] as string)
|
|
138
|
-
break
|
|
139
|
-
|
|
140
|
-
case 'access':
|
|
141
|
-
await opfs.access(args[0] as string, args[1] as number)
|
|
142
|
-
result = undefined
|
|
143
|
-
break
|
|
144
|
-
|
|
145
|
-
case 'statfs':
|
|
146
|
-
result = await opfs.statfs(args[0] as string | undefined)
|
|
147
|
-
break
|
|
148
|
-
|
|
149
|
-
case 'du':
|
|
150
|
-
result = await opfs.du(args[0] as string)
|
|
151
|
-
break
|
|
152
|
-
|
|
153
|
-
// Symlink operations
|
|
154
|
-
case 'symlink':
|
|
155
|
-
await opfs.symlink(args[0] as string, args[1] as string)
|
|
156
|
-
result = undefined
|
|
157
|
-
break
|
|
158
|
-
|
|
159
|
-
case 'readlink':
|
|
160
|
-
result = await opfs.readlink(args[0] as string)
|
|
161
|
-
break
|
|
162
|
-
|
|
163
|
-
case 'symlinkBatch':
|
|
164
|
-
await opfs.symlinkBatch(args[0] as SymlinkDefinition[])
|
|
165
|
-
result = undefined
|
|
166
|
-
break
|
|
167
|
-
|
|
168
|
-
case 'realpath':
|
|
169
|
-
result = await opfs.realpath(args[0] as string)
|
|
170
|
-
break
|
|
171
|
-
|
|
172
|
-
// Other operations
|
|
173
|
-
case 'rename':
|
|
174
|
-
await opfs.rename(args[0] as string, args[1] as string)
|
|
175
|
-
result = undefined
|
|
176
|
-
break
|
|
177
|
-
|
|
178
|
-
case 'mkdtemp':
|
|
179
|
-
result = await opfs.mkdtemp(args[0] as string)
|
|
180
|
-
break
|
|
181
|
-
|
|
182
|
-
case 'chmod':
|
|
183
|
-
await opfs.chmod(args[0] as string, args[1] as number)
|
|
184
|
-
result = undefined
|
|
185
|
-
break
|
|
186
|
-
|
|
187
|
-
case 'chown':
|
|
188
|
-
await opfs.chown(args[0] as string, args[1] as number, args[2] as number)
|
|
189
|
-
result = undefined
|
|
190
|
-
break
|
|
191
|
-
|
|
192
|
-
case 'utimes':
|
|
193
|
-
await opfs.utimes(args[0] as string, args[1] as Date | number, args[2] as Date | number)
|
|
194
|
-
result = undefined
|
|
195
|
-
break
|
|
196
|
-
|
|
197
|
-
case 'lutimes':
|
|
198
|
-
await opfs.lutimes(args[0] as string, args[1] as Date | number, args[2] as Date | number)
|
|
199
|
-
result = undefined
|
|
200
|
-
break
|
|
201
|
-
|
|
202
|
-
case 'resetCache':
|
|
203
|
-
opfs.resetCache()
|
|
204
|
-
result = undefined
|
|
205
|
-
break
|
|
206
|
-
|
|
207
|
-
case 'gc':
|
|
208
|
-
// Force full garbage collection by completely reinitializing the OPFS instance
|
|
209
|
-
// This releases all handles and caches, allowing browser to clean up resources
|
|
210
|
-
fs = null
|
|
211
|
-
fs = new OPFS({ useSync: true, verbose: false })
|
|
212
|
-
result = undefined
|
|
213
|
-
break
|
|
214
|
-
|
|
215
|
-
default:
|
|
216
|
-
throw new Error(`Unknown method: ${method}`)
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const response: WorkerResponse = { id, result }
|
|
220
|
-
if (transfer.length > 0) {
|
|
221
|
-
self.postMessage(response, transfer)
|
|
222
|
-
} else {
|
|
223
|
-
self.postMessage(response)
|
|
224
|
-
}
|
|
225
|
-
} catch (err) {
|
|
226
|
-
const error = err as Error & { code?: string }
|
|
227
|
-
const response: WorkerResponse = {
|
|
228
|
-
id,
|
|
229
|
-
error: {
|
|
230
|
-
message: error.message,
|
|
231
|
-
code: error.code
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
self.postMessage(response)
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// Serialize Stats object (functions can't be transferred)
|
|
239
|
-
function serializeStats(stats: { type: string; size: number; mode: number; ctime: Date; ctimeMs: number; mtime: Date; mtimeMs: number; target?: string }) {
|
|
240
|
-
return {
|
|
241
|
-
type: stats.type,
|
|
242
|
-
size: stats.size,
|
|
243
|
-
mode: stats.mode,
|
|
244
|
-
ctime: stats.ctime.toISOString(),
|
|
245
|
-
ctimeMs: stats.ctimeMs,
|
|
246
|
-
mtime: stats.mtime.toISOString(),
|
|
247
|
-
mtimeMs: stats.mtimeMs,
|
|
248
|
-
target: stats.target
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// Signal that worker is ready
|
|
253
|
-
self.postMessage({ type: 'ready' })
|