@molecule/app-filesystem 1.0.0 → 1.0.2
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 +691 -0
- package/package.json +8 -7
package/README.md
ADDED
|
@@ -0,0 +1,691 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
3
|
+
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
|
+
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
|
+
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
+
Generated: 2026-08-04T01:50:44.576Z
|
|
7
|
+
-->
|
|
8
|
+
|
|
9
|
+
# @molecule/app-filesystem
|
|
10
|
+
|
|
11
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
12
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
13
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
14
|
+
|
|
15
|
+
Device filesystem access interface for molecule.dev.
|
|
16
|
+
|
|
17
|
+
Framework-agnostic core for app-scoped file storage through a swappable
|
|
18
|
+
`FilesystemProvider`: read/write/append (text or Blob), directories
|
|
19
|
+
(mkdir/rmdir/readdir), stat/exists, copy/move, URIs for native viewers,
|
|
20
|
+
and free-space checks — all addressed relative to well-known base
|
|
21
|
+
directories (`'documents' | 'data' | 'cache' | 'external' | 'library' |
|
|
22
|
+
'temp'`). Pure path/format helpers (`joinPath`, `getExtension`,
|
|
23
|
+
`getBasename`, `getDirname`, `getMimeType`, `formatFileSize`) work
|
|
24
|
+
without a provider.
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { exists, hasProvider, joinPath, readFile, writeFile } from '@molecule/app-filesystem'
|
|
30
|
+
|
|
31
|
+
async function saveDraft(text: string): Promise<void> {
|
|
32
|
+
if (!hasProvider()) return // no provider wired — use app-storage instead
|
|
33
|
+
const path = joinPath('drafts', 'note.txt')
|
|
34
|
+
await writeFile(path, text, { directory: 'data', recursive: true })
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function loadDraft(): Promise<string | null> {
|
|
38
|
+
const path = joinPath('drafts', 'note.txt')
|
|
39
|
+
if (!(await exists(path, { directory: 'data' }))) return null
|
|
40
|
+
return readFile(path, { directory: 'data' })
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Type
|
|
45
|
+
|
|
46
|
+
`native`
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install @molecule/app-filesystem @molecule/app-bond @molecule/app-i18n
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## API
|
|
55
|
+
|
|
56
|
+
### Interfaces
|
|
57
|
+
|
|
58
|
+
#### `CopyOptions`
|
|
59
|
+
|
|
60
|
+
Copy/move options
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
interface CopyOptions {
|
|
64
|
+
/** Source directory */
|
|
65
|
+
fromDirectory?: Directory
|
|
66
|
+
/** Destination directory */
|
|
67
|
+
toDirectory?: Directory
|
|
68
|
+
/** Overwrite existing file */
|
|
69
|
+
overwrite?: boolean
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### `DeleteOptions`
|
|
74
|
+
|
|
75
|
+
Options for deleting a file or directory (directory type, recursive deletion).
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
interface DeleteOptions {
|
|
79
|
+
/** Directory type */
|
|
80
|
+
directory?: Directory
|
|
81
|
+
/** Delete directory contents recursively */
|
|
82
|
+
recursive?: boolean
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
#### `FileInfo`
|
|
87
|
+
|
|
88
|
+
Metadata about a file or directory (name, path, size, timestamps, type).
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
interface FileInfo {
|
|
92
|
+
/** File name */
|
|
93
|
+
name: string
|
|
94
|
+
/** Full path */
|
|
95
|
+
path: string
|
|
96
|
+
/** File URI */
|
|
97
|
+
uri: string
|
|
98
|
+
/** File size in bytes */
|
|
99
|
+
size: number
|
|
100
|
+
/** Creation time (ISO string) */
|
|
101
|
+
createdAt?: string
|
|
102
|
+
/** Modification time (ISO string) */
|
|
103
|
+
modifiedAt?: string
|
|
104
|
+
/** Whether this is a directory */
|
|
105
|
+
isDirectory: boolean
|
|
106
|
+
/** Whether this is a file */
|
|
107
|
+
isFile: boolean
|
|
108
|
+
/** MIME type (if available) */
|
|
109
|
+
mimeType?: string
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### `FilesystemCapabilities`
|
|
114
|
+
|
|
115
|
+
Filesystem capabilities
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
interface FilesystemCapabilities {
|
|
119
|
+
/** Whether filesystem access is supported */
|
|
120
|
+
supported: boolean
|
|
121
|
+
/** Available directories */
|
|
122
|
+
directories: Directory[]
|
|
123
|
+
/** Whether external storage is available */
|
|
124
|
+
hasExternalStorage: boolean
|
|
125
|
+
/** Whether file picking is supported */
|
|
126
|
+
hasPicker: boolean
|
|
127
|
+
/** Maximum file size (if limited) */
|
|
128
|
+
maxFileSize?: number
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
#### `FilesystemProvider`
|
|
133
|
+
|
|
134
|
+
Filesystem provider interface
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
interface FilesystemProvider {
|
|
138
|
+
/**
|
|
139
|
+
* Read a file as text
|
|
140
|
+
* @param path - File path
|
|
141
|
+
* @param options - Read options
|
|
142
|
+
*/
|
|
143
|
+
readFile(path: string, options?: ReadOptions): Promise<string>
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Read a file as binary data
|
|
147
|
+
* @param path - File path
|
|
148
|
+
* @param options - Read options
|
|
149
|
+
*/
|
|
150
|
+
readFileAsBlob(path: string, options?: Omit<ReadOptions, 'encoding'>): Promise<Blob>
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Write text to a file
|
|
154
|
+
* @param path - File path
|
|
155
|
+
* @param data - Content to write
|
|
156
|
+
* @param options - Write options
|
|
157
|
+
*/
|
|
158
|
+
writeFile(path: string, data: string, options?: WriteOptions): Promise<void>
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Write binary data to a file
|
|
162
|
+
* @param path - File path
|
|
163
|
+
* @param data - Binary data to write
|
|
164
|
+
* @param options - Write options
|
|
165
|
+
*/
|
|
166
|
+
writeFileFromBlob(
|
|
167
|
+
path: string,
|
|
168
|
+
data: Blob,
|
|
169
|
+
options?: Omit<WriteOptions, 'encoding'>,
|
|
170
|
+
): Promise<void>
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Append text to a file
|
|
174
|
+
* @param path - File path
|
|
175
|
+
* @param data - Content to append
|
|
176
|
+
* @param options - Write options
|
|
177
|
+
*/
|
|
178
|
+
appendFile(path: string, data: string, options?: WriteOptions): Promise<void>
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Delete a file
|
|
182
|
+
* @param path - File path
|
|
183
|
+
* @param options - Delete options
|
|
184
|
+
*/
|
|
185
|
+
deleteFile(path: string, options?: DeleteOptions): Promise<void>
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Create a directory
|
|
189
|
+
* @param path - Directory path
|
|
190
|
+
* @param options - Options
|
|
191
|
+
*/
|
|
192
|
+
mkdir(path: string, options?: WriteOptions): Promise<void>
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Remove a directory
|
|
196
|
+
* @param path - Directory path
|
|
197
|
+
* @param options - Delete options
|
|
198
|
+
*/
|
|
199
|
+
rmdir(path: string, options?: DeleteOptions): Promise<void>
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* List directory contents
|
|
203
|
+
* @param path - Directory path
|
|
204
|
+
* @param options - List options
|
|
205
|
+
*/
|
|
206
|
+
readdir(path: string, options?: ListOptions): Promise<FileInfo[]>
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Get file/directory info
|
|
210
|
+
* @param path - Path
|
|
211
|
+
* @param options - Stat options
|
|
212
|
+
*/
|
|
213
|
+
stat(path: string, options?: StatOptions): Promise<FileInfo>
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Check if file/directory exists
|
|
217
|
+
* @param path - Path
|
|
218
|
+
* @param options - Options
|
|
219
|
+
*/
|
|
220
|
+
exists(path: string, options?: StatOptions): Promise<boolean>
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Copy a file
|
|
224
|
+
* @param from - Source path
|
|
225
|
+
* @param to - Destination path
|
|
226
|
+
* @param options - Copy options
|
|
227
|
+
*/
|
|
228
|
+
copy(from: string, to: string, options?: CopyOptions): Promise<void>
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Move/rename a file
|
|
232
|
+
* @param from - Source path
|
|
233
|
+
* @param to - Destination path
|
|
234
|
+
* @param options - Copy options
|
|
235
|
+
*/
|
|
236
|
+
move(from: string, to: string, options?: CopyOptions): Promise<void>
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Get the platform URI for a file path.
|
|
240
|
+
* @param path - The file path to resolve.
|
|
241
|
+
* @param options - Options including directory type.
|
|
242
|
+
* @returns The file's platform-specific URI string.
|
|
243
|
+
*/
|
|
244
|
+
getUri(path: string, options?: StatOptions): Promise<string>
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Get available storage space in bytes.
|
|
248
|
+
* @param directory - The directory type to check (defaults to app data).
|
|
249
|
+
* @returns The available space in bytes.
|
|
250
|
+
*/
|
|
251
|
+
getAvailableSpace(directory?: Directory): Promise<number>
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Get the platform's filesystem capabilities.
|
|
255
|
+
* @returns The capabilities indicating available directories, picker support, and size limits.
|
|
256
|
+
*/
|
|
257
|
+
getCapabilities(): Promise<FilesystemCapabilities>
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
#### `ListOptions`
|
|
262
|
+
|
|
263
|
+
Options for listing directory contents (directory type, hidden files).
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
interface ListOptions {
|
|
267
|
+
/** Directory type */
|
|
268
|
+
directory?: Directory
|
|
269
|
+
/** Whether to include hidden files */
|
|
270
|
+
includeHidden?: boolean
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
#### `ReadOptions`
|
|
275
|
+
|
|
276
|
+
Options for reading a file (target directory and text encoding).
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
interface ReadOptions {
|
|
280
|
+
/** Directory to read from */
|
|
281
|
+
directory?: Directory
|
|
282
|
+
/** File encoding */
|
|
283
|
+
encoding?: Encoding
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
#### `StatOptions`
|
|
288
|
+
|
|
289
|
+
Options for getting file/directory metadata (target directory type).
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
interface StatOptions {
|
|
293
|
+
/** Directory type */
|
|
294
|
+
directory?: Directory
|
|
295
|
+
}
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
#### `WriteOptions`
|
|
299
|
+
|
|
300
|
+
Options for writing a file (directory, encoding, recursive creation, append mode).
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
interface WriteOptions {
|
|
304
|
+
/** Directory to write to */
|
|
305
|
+
directory?: Directory
|
|
306
|
+
/** File encoding */
|
|
307
|
+
encoding?: Encoding
|
|
308
|
+
/** Whether to create parent directories */
|
|
309
|
+
recursive?: boolean
|
|
310
|
+
/** Whether to append to existing file */
|
|
311
|
+
append?: boolean
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Types
|
|
316
|
+
|
|
317
|
+
#### `Directory`
|
|
318
|
+
|
|
319
|
+
File system directory type
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
type Directory =
|
|
323
|
+
| 'documents' // User documents
|
|
324
|
+
| 'data' // App-specific data
|
|
325
|
+
| 'cache' // Temporary cache
|
|
326
|
+
| 'external' // External storage (Android)
|
|
327
|
+
| 'library' // Library (iOS)
|
|
328
|
+
| 'temp'
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
#### `Encoding`
|
|
332
|
+
|
|
333
|
+
Text encoding for file read/write operations.
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
type Encoding = 'utf8' | 'ascii' | 'base64'
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### Functions
|
|
340
|
+
|
|
341
|
+
#### `appendFile(path, data, options)`
|
|
342
|
+
|
|
343
|
+
Append text content to a file.
|
|
344
|
+
|
|
345
|
+
```typescript
|
|
346
|
+
function appendFile(path: string, data: string, options?: WriteOptions): Promise<void>
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
- `path` — The file path to append to.
|
|
350
|
+
- `data` — The text content to append.
|
|
351
|
+
- `options` — Write options (directory, encoding).
|
|
352
|
+
|
|
353
|
+
**Returns:** A promise that resolves when the data is appended.
|
|
354
|
+
|
|
355
|
+
#### `copy(from, to, options)`
|
|
356
|
+
|
|
357
|
+
Copy a file to a new location.
|
|
358
|
+
|
|
359
|
+
```typescript
|
|
360
|
+
function copy(from: string, to: string, options?: CopyOptions): Promise<void>
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
- `from` — The source file path.
|
|
364
|
+
- `to` — The destination file path.
|
|
365
|
+
- `options` — Copy options (source/dest directories, overwrite).
|
|
366
|
+
|
|
367
|
+
**Returns:** A promise that resolves when the file is copied.
|
|
368
|
+
|
|
369
|
+
#### `deleteFile(path, options)`
|
|
370
|
+
|
|
371
|
+
Delete a file.
|
|
372
|
+
|
|
373
|
+
```typescript
|
|
374
|
+
function deleteFile(path: string, options?: DeleteOptions): Promise<void>
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
- `path` — The file path to delete.
|
|
378
|
+
- `options` — Delete options (directory, recursive).
|
|
379
|
+
|
|
380
|
+
**Returns:** A promise that resolves when the file is deleted.
|
|
381
|
+
|
|
382
|
+
#### `exists(path, options)`
|
|
383
|
+
|
|
384
|
+
Check if a file or directory exists.
|
|
385
|
+
|
|
386
|
+
```typescript
|
|
387
|
+
function exists(path: string, options?: StatOptions): Promise<boolean>
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
- `path` — The path to check.
|
|
391
|
+
- `options` — Stat options (directory).
|
|
392
|
+
|
|
393
|
+
**Returns:** Whether the path exists.
|
|
394
|
+
|
|
395
|
+
#### `formatFileSize(bytes)`
|
|
396
|
+
|
|
397
|
+
Format a byte count as a human-readable file size string (e.g., '1.5 MB').
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
function formatFileSize(bytes: number): string
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
- `bytes` — The size in bytes.
|
|
404
|
+
|
|
405
|
+
**Returns:** A formatted string with the appropriate unit (B, KB, MB, GB, TB).
|
|
406
|
+
|
|
407
|
+
#### `getAvailableSpace(directory)`
|
|
408
|
+
|
|
409
|
+
Get available storage space in bytes for a directory.
|
|
410
|
+
|
|
411
|
+
```typescript
|
|
412
|
+
function getAvailableSpace(directory?: Directory): Promise<number>
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
- `directory` — The directory type to check (defaults to app data).
|
|
416
|
+
|
|
417
|
+
**Returns:** The available space in bytes.
|
|
418
|
+
|
|
419
|
+
#### `getBasename(path)`
|
|
420
|
+
|
|
421
|
+
Get the filename without its extension from a path.
|
|
422
|
+
|
|
423
|
+
```typescript
|
|
424
|
+
function getBasename(path: string): string
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
- `path` — The file path.
|
|
428
|
+
|
|
429
|
+
**Returns:** The base filename without extension (e.g., 'readme' from '/docs/readme.md').
|
|
430
|
+
|
|
431
|
+
#### `getCapabilities()`
|
|
432
|
+
|
|
433
|
+
Get the platform's filesystem capabilities.
|
|
434
|
+
|
|
435
|
+
```typescript
|
|
436
|
+
function getCapabilities(): Promise<FilesystemCapabilities>
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
**Returns:** The capabilities indicating available directories, picker support, and size limits.
|
|
440
|
+
|
|
441
|
+
#### `getDirname(path)`
|
|
442
|
+
|
|
443
|
+
Get the directory portion of a file path.
|
|
444
|
+
|
|
445
|
+
```typescript
|
|
446
|
+
function getDirname(path: string): string
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
- `path` — The file path.
|
|
450
|
+
|
|
451
|
+
**Returns:** The parent directory path (e.g., '/docs' from '/docs/readme.md').
|
|
452
|
+
|
|
453
|
+
#### `getExtension(path)`
|
|
454
|
+
|
|
455
|
+
Extract the file extension from a path, without the leading dot.
|
|
456
|
+
|
|
457
|
+
```typescript
|
|
458
|
+
function getExtension(path: string): string
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
- `path` — The file path or filename.
|
|
462
|
+
|
|
463
|
+
**Returns:** The lowercase extension (e.g., 'txt'), or empty string if none.
|
|
464
|
+
|
|
465
|
+
#### `getMimeType(path)`
|
|
466
|
+
|
|
467
|
+
Infer a MIME type from a file extension. Supports common image, document,
|
|
468
|
+
text, media, and archive formats. Falls back to 'application/octet-stream'.
|
|
469
|
+
|
|
470
|
+
```typescript
|
|
471
|
+
function getMimeType(path: string): string
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
- `path` — The file path or extension to look up.
|
|
475
|
+
|
|
476
|
+
**Returns:** The inferred MIME type string.
|
|
477
|
+
|
|
478
|
+
#### `getProvider()`
|
|
479
|
+
|
|
480
|
+
Get the current filesystem provider.
|
|
481
|
+
|
|
482
|
+
```typescript
|
|
483
|
+
function getProvider(): FilesystemProvider
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
**Returns:** The active FilesystemProvider instance.
|
|
487
|
+
|
|
488
|
+
#### `getUri(path, options)`
|
|
489
|
+
|
|
490
|
+
Get the platform-specific URI for a file path.
|
|
491
|
+
|
|
492
|
+
```typescript
|
|
493
|
+
function getUri(path: string, options?: StatOptions): Promise<string>
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
- `path` — The file path to resolve.
|
|
497
|
+
- `options` — Stat options (directory).
|
|
498
|
+
|
|
499
|
+
**Returns:** The file's platform URI string.
|
|
500
|
+
|
|
501
|
+
#### `hasProvider()`
|
|
502
|
+
|
|
503
|
+
Check if a filesystem provider has been registered.
|
|
504
|
+
|
|
505
|
+
```typescript
|
|
506
|
+
function hasProvider(): boolean
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
**Returns:** Whether a FilesystemProvider has been bonded.
|
|
510
|
+
|
|
511
|
+
#### `joinPath(segments)`
|
|
512
|
+
|
|
513
|
+
Join multiple path segments into a single normalized path.
|
|
514
|
+
Collapses duplicate slashes and removes trailing slashes.
|
|
515
|
+
|
|
516
|
+
```typescript
|
|
517
|
+
function joinPath(segments?: string[]): string
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
- `segments` — The path segments to join.
|
|
521
|
+
|
|
522
|
+
**Returns:** The joined and normalized path.
|
|
523
|
+
|
|
524
|
+
#### `mkdir(path, options)`
|
|
525
|
+
|
|
526
|
+
Create a directory.
|
|
527
|
+
|
|
528
|
+
```typescript
|
|
529
|
+
function mkdir(path: string, options?: WriteOptions): Promise<void>
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
- `path` — The directory path to create.
|
|
533
|
+
- `options` — Write options (directory, recursive for parent directories).
|
|
534
|
+
|
|
535
|
+
**Returns:** A promise that resolves when the directory is created.
|
|
536
|
+
|
|
537
|
+
#### `move(from, to, options)`
|
|
538
|
+
|
|
539
|
+
Move or rename a file.
|
|
540
|
+
|
|
541
|
+
```typescript
|
|
542
|
+
function move(from: string, to: string, options?: CopyOptions): Promise<void>
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
- `from` — The source file path.
|
|
546
|
+
- `to` — The destination file path.
|
|
547
|
+
- `options` — Move options (source/dest directories, overwrite).
|
|
548
|
+
|
|
549
|
+
**Returns:** A promise that resolves when the file is moved.
|
|
550
|
+
|
|
551
|
+
#### `readdir(path, options)`
|
|
552
|
+
|
|
553
|
+
List directory contents.
|
|
554
|
+
|
|
555
|
+
```typescript
|
|
556
|
+
function readdir(path: string, options?: ListOptions): Promise<FileInfo[]>
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
- `path` — The directory path to list.
|
|
560
|
+
- `options` — List options (directory, include hidden files).
|
|
561
|
+
|
|
562
|
+
**Returns:** An array of FileInfo objects for each entry.
|
|
563
|
+
|
|
564
|
+
#### `readFile(path, options)`
|
|
565
|
+
|
|
566
|
+
Read a file as text.
|
|
567
|
+
|
|
568
|
+
```typescript
|
|
569
|
+
function readFile(path: string, options?: ReadOptions): Promise<string>
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
- `path` — The file path to read.
|
|
573
|
+
- `options` — Read options (directory, encoding).
|
|
574
|
+
|
|
575
|
+
**Returns:** The file contents as a string.
|
|
576
|
+
|
|
577
|
+
#### `readFileAsBlob(path, options)`
|
|
578
|
+
|
|
579
|
+
Read a file as binary data.
|
|
580
|
+
|
|
581
|
+
```typescript
|
|
582
|
+
function readFileAsBlob(path: string, options?: Omit<ReadOptions, 'encoding'>): Promise<Blob>
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
- `path` — The file path to read.
|
|
586
|
+
- `options` — Read options (directory).
|
|
587
|
+
|
|
588
|
+
**Returns:** The file contents as a Blob.
|
|
589
|
+
|
|
590
|
+
#### `rmdir(path, options)`
|
|
591
|
+
|
|
592
|
+
Remove a directory.
|
|
593
|
+
|
|
594
|
+
```typescript
|
|
595
|
+
function rmdir(path: string, options?: DeleteOptions): Promise<void>
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
- `path` — The directory path to remove.
|
|
599
|
+
- `options` — Delete options (directory, recursive for contents).
|
|
600
|
+
|
|
601
|
+
**Returns:** A promise that resolves when the directory is removed.
|
|
602
|
+
|
|
603
|
+
#### `setProvider(provider)`
|
|
604
|
+
|
|
605
|
+
Set the filesystem provider.
|
|
606
|
+
|
|
607
|
+
```typescript
|
|
608
|
+
function setProvider(provider: FilesystemProvider): void
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
- `provider` — FilesystemProvider implementation to register.
|
|
612
|
+
|
|
613
|
+
#### `stat(path, options)`
|
|
614
|
+
|
|
615
|
+
Get file or directory metadata.
|
|
616
|
+
|
|
617
|
+
```typescript
|
|
618
|
+
function stat(path: string, options?: StatOptions): Promise<FileInfo>
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
- `path` — The path to stat.
|
|
622
|
+
- `options` — Stat options (directory).
|
|
623
|
+
|
|
624
|
+
**Returns:** The FileInfo with size, dates, and type information.
|
|
625
|
+
|
|
626
|
+
#### `writeFile(path, data, options)`
|
|
627
|
+
|
|
628
|
+
Write text content to a file.
|
|
629
|
+
|
|
630
|
+
```typescript
|
|
631
|
+
function writeFile(path: string, data: string, options?: WriteOptions): Promise<void>
|
|
632
|
+
```
|
|
633
|
+
|
|
634
|
+
- `path` — The file path to write to.
|
|
635
|
+
- `data` — The text content to write.
|
|
636
|
+
- `options` — Write options (directory, encoding, recursive, append).
|
|
637
|
+
|
|
638
|
+
**Returns:** A promise that resolves when the file is written.
|
|
639
|
+
|
|
640
|
+
#### `writeFileFromBlob(path, data, options)`
|
|
641
|
+
|
|
642
|
+
Write binary data to a file.
|
|
643
|
+
|
|
644
|
+
```typescript
|
|
645
|
+
function writeFileFromBlob(
|
|
646
|
+
path: string,
|
|
647
|
+
data: Blob,
|
|
648
|
+
options?: Omit<WriteOptions, 'encoding'>,
|
|
649
|
+
): Promise<void>
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
- `path` — The file path to write to.
|
|
653
|
+
- `data` — The binary data to write as a Blob.
|
|
654
|
+
- `options` — Write options (directory, recursive).
|
|
655
|
+
|
|
656
|
+
**Returns:** A promise that resolves when the file is written.
|
|
657
|
+
|
|
658
|
+
## Injection Notes
|
|
659
|
+
|
|
660
|
+
### Requirements
|
|
661
|
+
|
|
662
|
+
Peer dependencies:
|
|
663
|
+
|
|
664
|
+
- `@molecule/app-bond` ^1.0.1
|
|
665
|
+
- `@molecule/app-i18n` ^1.0.1
|
|
666
|
+
|
|
667
|
+
### Runtime Dependencies
|
|
668
|
+
|
|
669
|
+
- `@molecule/app-bond`
|
|
670
|
+
- `@molecule/app-i18n`
|
|
671
|
+
|
|
672
|
+
- **Every file operation THROWS until `setProvider()` is called** — there
|
|
673
|
+
is no web fallback and **no prebuilt provider package ships with
|
|
674
|
+
molecule**; supply a `FilesystemProvider` from your native runtime.
|
|
675
|
+
- **This is NOT general key-value persistence.** For settings/state on any
|
|
676
|
+
platform use `@molecule/app-storage`; reach for app-filesystem only when
|
|
677
|
+
you genuinely need files (large blobs, exports, media handed to other
|
|
678
|
+
apps via `getUri`).
|
|
679
|
+
- On web there is no path-addressed filesystem; a provider could be built
|
|
680
|
+
on OPFS (origin-private, invisible to the user's file manager), but
|
|
681
|
+
`'external'`/`'library'` semantics and `getUri` for OS viewers do not
|
|
682
|
+
translate — feature-gate on `getCapabilities()`.
|
|
683
|
+
- Paths are RELATIVE to the `directory` base option (default varies by
|
|
684
|
+
provider — pass it explicitly). Use `joinPath`, never string-concat
|
|
685
|
+
with `/`.
|
|
686
|
+
- Write ops fail on missing parent directories unless
|
|
687
|
+
`{ recursive: true }`.
|
|
688
|
+
|
|
689
|
+
## Translations
|
|
690
|
+
|
|
691
|
+
Translation strings are provided by `@molecule/app-locales-filesystem`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-filesystem",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Device filesystem access interface for molecule.dev",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
|
-
"dist"
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
21
22
|
],
|
|
22
23
|
"keywords": [
|
|
23
24
|
"molecule",
|
|
@@ -28,21 +29,21 @@
|
|
|
28
29
|
],
|
|
29
30
|
"license": "Apache-2.0",
|
|
30
31
|
"peerDependencies": {
|
|
31
|
-
"@molecule/app-bond": "^1.0.
|
|
32
|
-
"@molecule/app-i18n": "^1.0.
|
|
32
|
+
"@molecule/app-bond": "^1.0.1",
|
|
33
|
+
"@molecule/app-i18n": "^1.0.1"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
|
-
"@molecule/app-bond": "1.0.
|
|
36
|
+
"@molecule/app-bond": "1.0.2",
|
|
36
37
|
"@types/node": "26.1.2",
|
|
37
38
|
"typescript": "6.0.3",
|
|
38
|
-
"vitest": "4.1.
|
|
39
|
+
"vitest": "4.1.11"
|
|
39
40
|
},
|
|
40
41
|
"repository": {
|
|
41
42
|
"type": "git",
|
|
42
43
|
"url": "https://github.com/molecule-dev/molecule.git",
|
|
43
44
|
"directory": "packages/app/native/filesystem"
|
|
44
45
|
},
|
|
45
|
-
"homepage": "https://
|
|
46
|
+
"homepage": "https://www.molecule.dev/packages/app-filesystem",
|
|
46
47
|
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
47
48
|
"publishConfig": {
|
|
48
49
|
"access": "public"
|