@mikestools/usefilesystem 0.0.1 → 0.0.3
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 +516 -114
- package/dist/index.d.ts +150 -191
- package/dist/usefilesystem.js +595 -425
- package/dist/usefilesystem.umd.cjs +1 -1
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
import { ComputedRef } from 'vue';
|
|
2
|
-
import { Ref } from 'vue';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Compresses data using DEFLATE (native CompressionStream).
|
|
6
|
-
*/
|
|
7
|
-
export declare function compress(data: Uint8Array): Promise<Uint8Array>;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Computes CRC-32 checksum for data.
|
|
11
|
-
*/
|
|
12
|
-
export declare function computeCrc32(data: Uint8Array): number;
|
|
13
2
|
|
|
14
3
|
/**
|
|
15
4
|
* Options for copying files.
|
|
@@ -72,7 +61,7 @@ export declare function createFileSystem(): {
|
|
|
72
61
|
clear: () => void;
|
|
73
62
|
find: (pattern: string) => readonly string[];
|
|
74
63
|
findByExtension: (extension: string) => readonly string[];
|
|
75
|
-
watch: (callback: FileSystemWatcher) => () => void;
|
|
64
|
+
watch: (callback: FileSystemWatcher, options?: WatchOptions) => () => void;
|
|
76
65
|
toJSON: () => Record<string, {
|
|
77
66
|
content: string;
|
|
78
67
|
mimeType: string;
|
|
@@ -84,31 +73,19 @@ export declare function createFileSystem(): {
|
|
|
84
73
|
};
|
|
85
74
|
|
|
86
75
|
/**
|
|
87
|
-
*
|
|
76
|
+
* Built-in OPFS (Origin Private File System) storage adapter.
|
|
77
|
+
* Provides high-performance persistence using the browser's native file system.
|
|
78
|
+
*
|
|
79
|
+
* OPFS is available in modern browsers and provides fast, synchronous-like
|
|
80
|
+
* access to a private file system sandboxed to the origin.
|
|
88
81
|
*
|
|
89
82
|
* @example
|
|
90
83
|
* ```ts
|
|
91
|
-
* const
|
|
92
|
-
*
|
|
93
|
-
* { path: 'data/config.json', content: JSON.stringify({ enabled: true }) },
|
|
94
|
-
* { path: 'images/logo.png', content: pngBytes }
|
|
95
|
-
* ])
|
|
84
|
+
* const adapter = createOPFSAdapter()
|
|
85
|
+
* const filesystem = useFileSystem({ adapter, autoPersist: true })
|
|
96
86
|
* ```
|
|
97
87
|
*/
|
|
98
|
-
export declare function
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Options for creating a ZIP archive.
|
|
102
|
-
*/
|
|
103
|
-
export declare interface CreateZipOptions extends ZipCompressionOptions {
|
|
104
|
-
/** Comment to include in the ZIP archive */
|
|
105
|
-
readonly comment?: string;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Decompresses DEFLATE data (native DecompressionStream).
|
|
110
|
-
*/
|
|
111
|
-
export declare function decompress(data: Uint8Array): Promise<Uint8Array>;
|
|
88
|
+
export declare function createOPFSAdapter(): StorageAdapter;
|
|
112
89
|
|
|
113
90
|
/**
|
|
114
91
|
* Directory entry for listing.
|
|
@@ -127,42 +104,16 @@ export declare interface DirectoryMetadata {
|
|
|
127
104
|
readonly name: string;
|
|
128
105
|
readonly path: string;
|
|
129
106
|
readonly createdAt: number;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
|
|
134
|
-
*/
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
export declare function downloadBlob(blob: Blob, fileName: string): void;
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Extracts a single file from a ZIP archive.
|
|
144
|
-
*/
|
|
145
|
-
export declare function extractFile(zipData: Uint8Array | Blob, filePath: string): Promise<Uint8Array | undefined>;
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Extracts all files from a ZIP archive.
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```ts
|
|
152
|
-
* const entries = await extractZip(zipBlob)
|
|
153
|
-
* for (const entry of entries) {
|
|
154
|
-
* console.log(entry.path, entry.content.length)
|
|
155
|
-
* }
|
|
156
|
-
* ```
|
|
157
|
-
*/
|
|
158
|
-
export declare function extractZip(zipData: Uint8Array | Blob, options?: ExtractZipOptions): Promise<readonly ZipEntry[]>;
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Options for extracting from a ZIP archive.
|
|
162
|
-
*/
|
|
163
|
-
export declare interface ExtractZipOptions {
|
|
164
|
-
/** Filter function to select which entries to extract */
|
|
165
|
-
readonly filter?: (entry: ZipEntryMetadata) => boolean;
|
|
107
|
+
/** Parent directory path */
|
|
108
|
+
readonly parentPath: string;
|
|
109
|
+
/** Directory depth from root (root = 0) */
|
|
110
|
+
readonly depth: number;
|
|
111
|
+
/** Count of direct children files */
|
|
112
|
+
readonly fileCount: number;
|
|
113
|
+
/** Count of direct children directories */
|
|
114
|
+
readonly directoryCount: number;
|
|
115
|
+
/** Recursive total size of all contents in bytes */
|
|
116
|
+
readonly totalSize: number;
|
|
166
117
|
}
|
|
167
118
|
|
|
168
119
|
/**
|
|
@@ -175,6 +126,16 @@ export declare interface FileMetadata {
|
|
|
175
126
|
readonly mimeType: string;
|
|
176
127
|
readonly createdAt: number;
|
|
177
128
|
readonly modifiedAt: number;
|
|
129
|
+
/** File extension including leading dot, or empty string if none */
|
|
130
|
+
readonly extension: string;
|
|
131
|
+
/** True if MIME type indicates text content */
|
|
132
|
+
readonly isText: boolean;
|
|
133
|
+
/** True if MIME type indicates binary content */
|
|
134
|
+
readonly isBinary: boolean;
|
|
135
|
+
/** Parent directory path */
|
|
136
|
+
readonly parentPath: string;
|
|
137
|
+
/** Directory depth from root (root = 0) */
|
|
138
|
+
readonly depth: number;
|
|
178
139
|
}
|
|
179
140
|
|
|
180
141
|
/**
|
|
@@ -203,8 +164,10 @@ export declare interface FileSystemStats {
|
|
|
203
164
|
|
|
204
165
|
/**
|
|
205
166
|
* Watcher callback for filesystem changes.
|
|
167
|
+
* When using watch options, receives a WatchEvent object.
|
|
168
|
+
* When using simple watch (no options), receives individual parameters.
|
|
206
169
|
*/
|
|
207
|
-
export declare type FileSystemWatcher = (event: 'create' | 'modify' | 'delete', path: string, type: 'file' | 'directory') => void;
|
|
170
|
+
export declare type FileSystemWatcher = ((event: WatchEvent) => void) | ((event: 'create' | 'modify' | 'delete', path: string, type: 'file' | 'directory') => void);
|
|
208
171
|
|
|
209
172
|
/**
|
|
210
173
|
* Options for listing directory contents.
|
|
@@ -215,11 +178,6 @@ export declare interface ListOptions {
|
|
|
215
178
|
readonly directoriesOnly?: boolean;
|
|
216
179
|
}
|
|
217
180
|
|
|
218
|
-
/**
|
|
219
|
-
* Reads entries from a ZIP archive without extracting content.
|
|
220
|
-
*/
|
|
221
|
-
export declare function listZip(zipData: Uint8Array | Blob): Promise<readonly ZipEntryMetadata[]>;
|
|
222
|
-
|
|
223
181
|
/**
|
|
224
182
|
* Options for moving files.
|
|
225
183
|
*/
|
|
@@ -245,6 +203,51 @@ export declare interface StorageAdapter {
|
|
|
245
203
|
clear(): Promise<void>;
|
|
246
204
|
}
|
|
247
205
|
|
|
206
|
+
/**
|
|
207
|
+
* Storage usage estimate.
|
|
208
|
+
*/
|
|
209
|
+
declare interface StorageEstimate_2 {
|
|
210
|
+
/** Estimated available space (virtual limit) */
|
|
211
|
+
readonly quota: number;
|
|
212
|
+
/** Current usage in bytes */
|
|
213
|
+
readonly usage: number;
|
|
214
|
+
/** Available space (quota - usage) */
|
|
215
|
+
readonly available: number;
|
|
216
|
+
/** Usage percentage (0-100) */
|
|
217
|
+
readonly percentage: number;
|
|
218
|
+
}
|
|
219
|
+
export { StorageEstimate_2 as StorageEstimate }
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Options for Web Streams API operations.
|
|
223
|
+
*/
|
|
224
|
+
export declare interface StreamOptions {
|
|
225
|
+
/** Chunk size in bytes for streaming (default: 64KB) */
|
|
226
|
+
readonly chunkSize?: number;
|
|
227
|
+
/** High water mark for backpressure (default: 3 chunks) */
|
|
228
|
+
readonly highWaterMark?: number;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Transaction for atomic multi-file operations.
|
|
233
|
+
*/
|
|
234
|
+
export declare interface Transaction {
|
|
235
|
+
/** Queue a file write operation */
|
|
236
|
+
writeFile(path: string, content: string | Uint8Array, options?: WriteFileOptions): Transaction;
|
|
237
|
+
/** Queue a file removal */
|
|
238
|
+
remove(path: string): Transaction;
|
|
239
|
+
/** Queue a directory creation */
|
|
240
|
+
mkdir(path: string): Transaction;
|
|
241
|
+
/** Queue a file copy operation */
|
|
242
|
+
copy(source: string, destination: string): Transaction;
|
|
243
|
+
/** Queue a file move operation */
|
|
244
|
+
move(source: string, destination: string): Transaction;
|
|
245
|
+
/** Execute all operations atomically (all or nothing) */
|
|
246
|
+
commit(): FileSystemResult;
|
|
247
|
+
/** Discard all pending operations */
|
|
248
|
+
rollback(): void;
|
|
249
|
+
}
|
|
250
|
+
|
|
248
251
|
/**
|
|
249
252
|
* Vue composable wrapper for the virtual filesystem with reactivity.
|
|
250
253
|
*
|
|
@@ -268,6 +271,14 @@ export declare function useFileSystem(options?: UseFileSystemOptions): UseFileSy
|
|
|
268
271
|
export declare interface UseFileSystemOptions {
|
|
269
272
|
readonly adapter?: StorageAdapter;
|
|
270
273
|
readonly autoPersist?: boolean;
|
|
274
|
+
/** Maximum total size in bytes (default: unlimited) */
|
|
275
|
+
readonly maxSize?: number;
|
|
276
|
+
/** Maximum number of files (default: unlimited) */
|
|
277
|
+
readonly maxFiles?: number;
|
|
278
|
+
/** Maximum single file size in bytes (default: unlimited) */
|
|
279
|
+
readonly maxFileSize?: number;
|
|
280
|
+
/** Trigger warning at this usage percentage (default: 90) */
|
|
281
|
+
readonly warnAtPercentage?: number;
|
|
271
282
|
}
|
|
272
283
|
|
|
273
284
|
/**
|
|
@@ -284,142 +295,90 @@ export declare interface UseFileSystemReturn extends FileSystem_2 {
|
|
|
284
295
|
persist: () => Promise<void>;
|
|
285
296
|
/** Restore from storage adapter */
|
|
286
297
|
restore: () => Promise<void>;
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
*/
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
readonly state: ComputedRef<ZipOperationState>;
|
|
322
|
-
/** Whether an operation is in progress */
|
|
323
|
-
readonly isProcessing: Ref<boolean>;
|
|
324
|
-
/** Progress percentage (0-100) */
|
|
325
|
-
readonly progress: Ref<number>;
|
|
326
|
-
/** Last error message */
|
|
327
|
-
readonly error: Ref<string | undefined>;
|
|
328
|
-
/** Create a ZIP archive from files */
|
|
329
|
-
create: (files: readonly ZipInput[], options?: CreateZipOptions) => Promise<Blob>;
|
|
330
|
-
/** Extract all files from a ZIP archive */
|
|
331
|
-
extract: (zipData: Uint8Array | Blob, options?: ExtractZipOptions) => Promise<readonly ZipEntry[]>;
|
|
332
|
-
/** Extract a single file from a ZIP archive */
|
|
333
|
-
extractSingle: (zipData: Uint8Array | Blob, filePath: string) => Promise<Uint8Array | undefined>;
|
|
334
|
-
/** List entries in a ZIP archive without extracting */
|
|
335
|
-
list: (zipData: Uint8Array | Blob) => Promise<readonly ZipEntryMetadata[]>;
|
|
336
|
-
/** Download a ZIP archive */
|
|
337
|
-
download: (files: readonly ZipInput[], fileName: string, options?: CreateZipOptions) => Promise<void>;
|
|
338
|
-
/** Download a blob as a file */
|
|
339
|
-
downloadBlob: (blob: Blob, fileName: string) => void;
|
|
340
|
-
/** Compress data using DEFLATE */
|
|
341
|
-
compress: (data: Uint8Array) => Promise<Uint8Array>;
|
|
342
|
-
/** Decompress DEFLATE data */
|
|
343
|
-
decompress: (data: Uint8Array) => Promise<Uint8Array>;
|
|
344
|
-
/** Compute CRC-32 checksum */
|
|
345
|
-
computeCrc32: (data: Uint8Array) => number;
|
|
346
|
-
/** Reset error state */
|
|
347
|
-
clearError: () => void;
|
|
298
|
+
/** Import a native File object into the virtual filesystem */
|
|
299
|
+
upload: (file: File, targetPath?: string) => Promise<FileSystemResult>;
|
|
300
|
+
/** Import multiple files from a FileList (e.g., from <input type="file">) */
|
|
301
|
+
uploads: (files: FileList, targetDirectory?: string) => Promise<FileSystemResult>;
|
|
302
|
+
/** Export a virtual file as a native Blob */
|
|
303
|
+
toBlob: (path: string) => Blob | undefined;
|
|
304
|
+
/** Export a virtual file as a native File object */
|
|
305
|
+
toFile: (path: string) => File | undefined;
|
|
306
|
+
/** Create a downloadable object URL for a file */
|
|
307
|
+
createObjectURL: (path: string) => string | undefined;
|
|
308
|
+
/** Revoke a previously created object URL */
|
|
309
|
+
revokeObjectURL: (url: string) => void;
|
|
310
|
+
/** Download a virtual file to the user's device */
|
|
311
|
+
download: (path: string, filename?: string) => boolean;
|
|
312
|
+
/** Download multiple files as individual downloads */
|
|
313
|
+
downloads: (paths: readonly string[]) => void;
|
|
314
|
+
/** Create a Web Streams API ReadableStream for a file */
|
|
315
|
+
createReadStream: (path: string, options?: StreamOptions) => ReadableStream<Uint8Array> | undefined;
|
|
316
|
+
/** Create a Web Streams API WritableStream for a file */
|
|
317
|
+
createWriteStream: (path: string, options?: WriteFileOptions & StreamOptions) => WritableStream<Uint8Array>;
|
|
318
|
+
/** Write from any ReadableStream (fetch response, Blob.stream(), etc.) */
|
|
319
|
+
writeFromStream: (path: string, stream: ReadableStream<Uint8Array>, options?: WriteFileOptions) => Promise<FileSystemResult>;
|
|
320
|
+
/** Create a Response object from a file (for Service Worker integration) */
|
|
321
|
+
toResponse: (path: string, init?: ResponseInit) => Response | undefined;
|
|
322
|
+
/** Compute SHA-256 checksum of file content */
|
|
323
|
+
computeChecksum: (path: string) => Promise<string | undefined>;
|
|
324
|
+
/** Get storage usage estimate */
|
|
325
|
+
readonly storageEstimate: ComputedRef<StorageEstimate_2>;
|
|
326
|
+
/** Check if storage is near capacity (above warning threshold) */
|
|
327
|
+
readonly isNearCapacity: ComputedRef<boolean>;
|
|
328
|
+
/** Register callback when storage exceeds warning threshold */
|
|
329
|
+
onStorageWarning: (callback: (estimate: StorageEstimate_2) => void) => () => void;
|
|
330
|
+
/** Begin a transaction for atomic operations */
|
|
331
|
+
beginTransaction: () => Transaction;
|
|
348
332
|
}
|
|
349
333
|
|
|
350
334
|
/**
|
|
351
335
|
* Represents a complete file with content.
|
|
352
336
|
*/
|
|
353
|
-
export declare interface VirtualFile
|
|
354
|
-
readonly
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Options for writing a file.
|
|
359
|
-
*/
|
|
360
|
-
export declare interface WriteFileOptions {
|
|
361
|
-
readonly mimeType?: string;
|
|
362
|
-
readonly overwrite?: boolean;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* Options for ZIP compression.
|
|
367
|
-
*/
|
|
368
|
-
export declare interface ZipCompressionOptions {
|
|
369
|
-
/** Compression level: 'none' stores files, 'fast'/'default' uses deflate */
|
|
370
|
-
readonly level?: 'none' | 'fast' | 'default';
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Represents an entry in a ZIP archive.
|
|
375
|
-
*/
|
|
376
|
-
export declare interface ZipEntry {
|
|
337
|
+
export declare interface VirtualFile {
|
|
338
|
+
readonly name: string;
|
|
377
339
|
readonly path: string;
|
|
378
340
|
readonly content: Uint8Array;
|
|
379
|
-
readonly
|
|
380
|
-
readonly
|
|
381
|
-
readonly
|
|
382
|
-
readonly
|
|
383
|
-
readonly modifiedAt: Date;
|
|
384
|
-
readonly isDirectory: boolean;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* Metadata for a ZIP entry (without content).
|
|
389
|
-
*/
|
|
390
|
-
export declare interface ZipEntryMetadata {
|
|
391
|
-
readonly path: string;
|
|
392
|
-
readonly compressedSize: number;
|
|
393
|
-
readonly uncompressedSize: number;
|
|
394
|
-
readonly compressionMethod: 'store' | 'deflate';
|
|
395
|
-
readonly isDirectory: boolean;
|
|
396
|
-
readonly modifiedAt: Date;
|
|
341
|
+
readonly size: number;
|
|
342
|
+
readonly mimeType: string;
|
|
343
|
+
readonly createdAt: number;
|
|
344
|
+
readonly modifiedAt: number;
|
|
397
345
|
}
|
|
398
346
|
|
|
399
347
|
/**
|
|
400
|
-
*
|
|
348
|
+
* Enhanced watch event with metadata.
|
|
401
349
|
*/
|
|
402
|
-
export declare interface
|
|
350
|
+
export declare interface WatchEvent {
|
|
351
|
+
readonly event: 'create' | 'modify' | 'delete';
|
|
403
352
|
readonly path: string;
|
|
404
|
-
readonly
|
|
353
|
+
readonly type: 'file' | 'directory';
|
|
354
|
+
readonly timestamp: number;
|
|
355
|
+
readonly metadata?: FileMetadata | DirectoryMetadata;
|
|
405
356
|
}
|
|
406
357
|
|
|
407
358
|
/**
|
|
408
|
-
*
|
|
409
|
-
*/
|
|
410
|
-
export declare interface
|
|
411
|
-
|
|
412
|
-
readonly
|
|
413
|
-
|
|
359
|
+
* Options for enhanced file watching.
|
|
360
|
+
*/
|
|
361
|
+
export declare interface WatchOptions {
|
|
362
|
+
/** Filter by path pattern (glob) */
|
|
363
|
+
readonly pattern?: string;
|
|
364
|
+
/** Filter by event types */
|
|
365
|
+
readonly events?: readonly ('create' | 'modify' | 'delete')[];
|
|
366
|
+
/** Filter by entry type */
|
|
367
|
+
readonly type?: 'file' | 'directory' | 'all';
|
|
368
|
+
/** Debounce rapid changes (ms) */
|
|
369
|
+
readonly debounce?: number;
|
|
370
|
+
/** Only watch specific directory (non-recursive by default) */
|
|
371
|
+
readonly path?: string;
|
|
372
|
+
/** Watch recursively when path is specified */
|
|
373
|
+
readonly recursive?: boolean;
|
|
414
374
|
}
|
|
415
375
|
|
|
416
376
|
/**
|
|
417
|
-
*
|
|
377
|
+
* Options for writing a file.
|
|
418
378
|
*/
|
|
419
|
-
export declare interface
|
|
420
|
-
readonly
|
|
421
|
-
readonly
|
|
422
|
-
readonly error?: string;
|
|
379
|
+
export declare interface WriteFileOptions {
|
|
380
|
+
readonly mimeType?: string;
|
|
381
|
+
readonly overwrite?: boolean;
|
|
423
382
|
}
|
|
424
383
|
|
|
425
384
|
export { }
|