@componentor/fs 1.1.7
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/LICENSE +21 -0
- package/README.md +742 -0
- package/dist/index.d.ts +544 -0
- package/dist/index.js +2551 -0
- package/dist/index.js.map +1 -0
- package/dist/opfs-hybrid.d.ts +198 -0
- package/dist/opfs-hybrid.js +2552 -0
- package/dist/opfs-hybrid.js.map +1 -0
- package/dist/opfs-worker-proxy.d.ts +224 -0
- package/dist/opfs-worker-proxy.js +274 -0
- package/dist/opfs-worker-proxy.js.map +1 -0
- package/dist/opfs-worker.js +2732 -0
- package/dist/opfs-worker.js.map +1 -0
- package/package.json +66 -0
- package/src/constants.ts +52 -0
- package/src/errors.ts +88 -0
- package/src/file-handle.ts +100 -0
- package/src/global.d.ts +57 -0
- package/src/handle-manager.ts +250 -0
- package/src/index.ts +1404 -0
- package/src/opfs-hybrid.ts +265 -0
- package/src/opfs-worker-proxy.ts +374 -0
- package/src/opfs-worker.ts +253 -0
- package/src/packed-storage.ts +426 -0
- package/src/path-utils.ts +97 -0
- package/src/streams.ts +109 -0
- package/src/symlink-manager.ts +329 -0
- package/src/types.ts +285 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File system constants matching Node.js fs.constants
|
|
3
|
+
*/
|
|
4
|
+
export interface FSConstants {
|
|
5
|
+
F_OK: number
|
|
6
|
+
R_OK: number
|
|
7
|
+
W_OK: number
|
|
8
|
+
X_OK: number
|
|
9
|
+
COPYFILE_EXCL: number
|
|
10
|
+
COPYFILE_FICLONE: number
|
|
11
|
+
COPYFILE_FICLONE_FORCE: number
|
|
12
|
+
O_RDONLY: number
|
|
13
|
+
O_WRONLY: number
|
|
14
|
+
O_RDWR: number
|
|
15
|
+
O_CREAT: number
|
|
16
|
+
O_EXCL: number
|
|
17
|
+
O_TRUNC: number
|
|
18
|
+
O_APPEND: number
|
|
19
|
+
S_IFMT: number
|
|
20
|
+
S_IFREG: number
|
|
21
|
+
S_IFDIR: number
|
|
22
|
+
S_IFLNK: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Configuration options for OPFS instance
|
|
27
|
+
*/
|
|
28
|
+
export interface OPFSOptions {
|
|
29
|
+
/** Use synchronous access handles when available (default: true) */
|
|
30
|
+
useSync?: boolean
|
|
31
|
+
/** Enable verbose logging (default: false) */
|
|
32
|
+
verbose?: boolean
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Options for readFile operation
|
|
37
|
+
*/
|
|
38
|
+
export interface ReadFileOptions {
|
|
39
|
+
/** Text encoding (e.g., 'utf-8'). If not provided, returns Uint8Array */
|
|
40
|
+
encoding?: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Options for writeFile operation
|
|
45
|
+
*/
|
|
46
|
+
export interface WriteFileOptions {
|
|
47
|
+
/** Text encoding for string data */
|
|
48
|
+
encoding?: string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Entry for batch file write operation
|
|
53
|
+
*/
|
|
54
|
+
export interface BatchWriteEntry {
|
|
55
|
+
/** File path to write */
|
|
56
|
+
path: string
|
|
57
|
+
/** Data to write (string or binary) */
|
|
58
|
+
data: string | Uint8Array
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Result entry for batch file read operation
|
|
63
|
+
*/
|
|
64
|
+
export interface BatchReadResult {
|
|
65
|
+
/** File path */
|
|
66
|
+
path: string
|
|
67
|
+
/** File data (null if file doesn't exist or error occurred) */
|
|
68
|
+
data: Uint8Array | null
|
|
69
|
+
/** Error if read failed */
|
|
70
|
+
error?: Error
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Options for readdir operation
|
|
75
|
+
*/
|
|
76
|
+
export interface ReaddirOptions {
|
|
77
|
+
/** Return Dirent objects instead of strings */
|
|
78
|
+
withFileTypes?: boolean
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Directory entry (Dirent-like object)
|
|
83
|
+
*/
|
|
84
|
+
export interface Dirent {
|
|
85
|
+
name: string
|
|
86
|
+
isFile(): boolean
|
|
87
|
+
isDirectory(): boolean
|
|
88
|
+
isSymbolicLink(): boolean
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* File statistics
|
|
93
|
+
*/
|
|
94
|
+
export interface Stats {
|
|
95
|
+
type: 'file' | 'dir' | 'symlink'
|
|
96
|
+
size: number
|
|
97
|
+
mode: number
|
|
98
|
+
ctime: Date
|
|
99
|
+
ctimeMs: number
|
|
100
|
+
mtime: Date
|
|
101
|
+
mtimeMs: number
|
|
102
|
+
target?: string
|
|
103
|
+
isFile(): boolean
|
|
104
|
+
isDirectory(): boolean
|
|
105
|
+
isSymbolicLink(): boolean
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Options for rm operation
|
|
110
|
+
*/
|
|
111
|
+
export interface RmOptions {
|
|
112
|
+
/** Remove directories and their contents recursively */
|
|
113
|
+
recursive?: boolean
|
|
114
|
+
/** Ignore if path doesn't exist */
|
|
115
|
+
force?: boolean
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Options for cp operation
|
|
120
|
+
*/
|
|
121
|
+
export interface CpOptions {
|
|
122
|
+
/** Copy directories recursively */
|
|
123
|
+
recursive?: boolean
|
|
124
|
+
/** Overwrite existing files */
|
|
125
|
+
force?: boolean
|
|
126
|
+
/** Throw if destination exists */
|
|
127
|
+
errorOnExist?: boolean
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Options for watch operation
|
|
132
|
+
*/
|
|
133
|
+
export interface WatchOptions {
|
|
134
|
+
/** Keep the process running while watching (default: true) */
|
|
135
|
+
persistent?: boolean
|
|
136
|
+
/** Watch subdirectories recursively */
|
|
137
|
+
recursive?: boolean
|
|
138
|
+
/** Abort signal to stop watching */
|
|
139
|
+
signal?: AbortSignal
|
|
140
|
+
/** Encoding for filename (default: 'utf8') */
|
|
141
|
+
encoding?: string
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Watch event
|
|
146
|
+
*/
|
|
147
|
+
export interface WatchEvent {
|
|
148
|
+
eventType: 'rename' | 'change'
|
|
149
|
+
filename: string
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* File watcher
|
|
154
|
+
*/
|
|
155
|
+
export interface FSWatcher {
|
|
156
|
+
close(): void
|
|
157
|
+
ref(): FSWatcher
|
|
158
|
+
unref(): FSWatcher
|
|
159
|
+
[Symbol.asyncIterator](): AsyncIterator<WatchEvent>
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Read stream options
|
|
164
|
+
*/
|
|
165
|
+
export interface ReadStreamOptions {
|
|
166
|
+
/** Start reading from this byte position */
|
|
167
|
+
start?: number
|
|
168
|
+
/** Stop reading at this byte position */
|
|
169
|
+
end?: number
|
|
170
|
+
/** Chunk size for reading (default: 64KB) */
|
|
171
|
+
highWaterMark?: number
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Write stream options
|
|
176
|
+
*/
|
|
177
|
+
export interface WriteStreamOptions {
|
|
178
|
+
/** File open flags (default: 'w') */
|
|
179
|
+
flags?: string
|
|
180
|
+
/** Start writing at this byte position */
|
|
181
|
+
start?: number
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Symlink definition for batch operations
|
|
186
|
+
*/
|
|
187
|
+
export interface SymlinkDefinition {
|
|
188
|
+
target: string
|
|
189
|
+
path: string
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Result of read operation on FileHandle
|
|
194
|
+
*/
|
|
195
|
+
export interface ReadResult {
|
|
196
|
+
bytesRead: number
|
|
197
|
+
buffer: Uint8Array
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Result of write operation on FileHandle
|
|
202
|
+
*/
|
|
203
|
+
export interface WriteResult {
|
|
204
|
+
bytesWritten: number
|
|
205
|
+
buffer: Uint8Array
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* FileHandle interface (returned by open())
|
|
210
|
+
*/
|
|
211
|
+
export interface FileHandle {
|
|
212
|
+
fd: number
|
|
213
|
+
read(buffer: Uint8Array, offset?: number, length?: number, position?: number | null): Promise<ReadResult>
|
|
214
|
+
write(buffer: Uint8Array, offset?: number, length?: number, position?: number | null): Promise<WriteResult>
|
|
215
|
+
close(): Promise<void>
|
|
216
|
+
stat(): Promise<Stats>
|
|
217
|
+
truncate(len?: number): Promise<void>
|
|
218
|
+
sync(): Promise<void>
|
|
219
|
+
datasync(): Promise<void>
|
|
220
|
+
readFile(options?: ReadFileOptions): Promise<string | Uint8Array>
|
|
221
|
+
writeFile(data: string | Uint8Array, options?: WriteFileOptions): Promise<void>
|
|
222
|
+
appendFile(data: string | Uint8Array, options?: WriteFileOptions): Promise<void>
|
|
223
|
+
[Symbol.asyncDispose](): Promise<void>
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Directory handle (returned by opendir())
|
|
228
|
+
*/
|
|
229
|
+
export interface Dir {
|
|
230
|
+
path: string
|
|
231
|
+
read(): Promise<Dirent | null>
|
|
232
|
+
close(): Promise<void>
|
|
233
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<Dirent>
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Disk usage result
|
|
238
|
+
*/
|
|
239
|
+
export interface DiskUsage {
|
|
240
|
+
path: string
|
|
241
|
+
size: number
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Filesystem statistics (similar to Node.js fs.statfs)
|
|
246
|
+
*/
|
|
247
|
+
export interface StatFs {
|
|
248
|
+
/** Filesystem type (always 0 for OPFS) */
|
|
249
|
+
type: number
|
|
250
|
+
/** Optimal transfer block size (simulated as 4096) */
|
|
251
|
+
bsize: number
|
|
252
|
+
/** Total blocks in filesystem */
|
|
253
|
+
blocks: number
|
|
254
|
+
/** Free blocks in filesystem */
|
|
255
|
+
bfree: number
|
|
256
|
+
/** Available blocks for unprivileged users */
|
|
257
|
+
bavail: number
|
|
258
|
+
/** Total file nodes (0 - not available in browser) */
|
|
259
|
+
files: number
|
|
260
|
+
/** Free file nodes (0 - not available in browser) */
|
|
261
|
+
ffree: number
|
|
262
|
+
/** Bytes used by origin (from Storage API) */
|
|
263
|
+
usage: number
|
|
264
|
+
/** Total bytes available to origin (from Storage API) */
|
|
265
|
+
quota: number
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Internal symlink cache structure
|
|
270
|
+
*/
|
|
271
|
+
export type SymlinkCache = Record<string, string>
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Watch callback function
|
|
275
|
+
*/
|
|
276
|
+
export type WatchCallback = (eventType: string, filename: string) => void
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Internal watch registration
|
|
280
|
+
*/
|
|
281
|
+
export interface WatchRegistration {
|
|
282
|
+
path: string
|
|
283
|
+
callbacks: Set<WatchCallback>
|
|
284
|
+
recursive: boolean
|
|
285
|
+
}
|