rn-file-toolkit 1.0.7 → 1.0.9
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/FileToolkit.podspec +1 -0
- package/README.md +365 -24
- package/android/src/main/java/com/filetoolkit/FileToolkitModule.kt +273 -0
- package/ios/FileToolkit.mm +220 -0
- package/lib/commonjs/NativeFileToolkit.js.map +1 -1
- package/lib/commonjs/index.js +137 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/NativeFileToolkit.js.map +1 -1
- package/lib/module/index.js +129 -3
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/commonjs/src/NativeFileToolkit.d.ts +6 -0
- package/lib/typescript/commonjs/src/NativeFileToolkit.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +67 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/NativeFileToolkit.d.ts +6 -0
- package/lib/typescript/module/src/NativeFileToolkit.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +67 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/NativeFileToolkit.ts +6 -0
- package/src/index.tsx +183 -2
package/FileToolkit.podspec
CHANGED
package/README.md
CHANGED
|
@@ -25,10 +25,20 @@
|
|
|
25
25
|
- [Quick Start: `useDownload`](#-quick-start-usedownload)
|
|
26
26
|
- [Core APIs](#-core-apis)
|
|
27
27
|
- [Background Downloads](#background-downloads)
|
|
28
|
+
- [Download Controls](#download-controls)
|
|
28
29
|
- [Multipart Uploads](#multipart-uploads)
|
|
30
|
+
- [Queue Management](#queue-management)
|
|
29
31
|
- [File System (FS)](#file-system-fs)
|
|
30
32
|
- [Zip & Unzip Archives](#zip--unzip-archives)
|
|
33
|
+
- [Cache Management](#cache-management)
|
|
31
34
|
- [Media & Utilities](#media--utilities)
|
|
35
|
+
- [Disk Space](#disk-space)
|
|
36
|
+
- [File Appending](#file-appending)
|
|
37
|
+
- [File Hashing](#file-hashing)
|
|
38
|
+
- [Session Management](#session-management)
|
|
39
|
+
- [Cookie Management](#cookie-management)
|
|
40
|
+
- [MediaStore / Photos Library](#mediastore--photos-library)
|
|
41
|
+
- [Event Listeners](#event-listeners)
|
|
32
42
|
- [API Reference](#-api-reference)
|
|
33
43
|
- [Expo Support](#-expo-support)
|
|
34
44
|
- [Contributing](#-contributing)
|
|
@@ -46,7 +56,10 @@ Most React Native file solutions (`rn-fetch-blob`, `react-native-fs`) are fragme
|
|
|
46
56
|
- 🚦 **Smart Queueing:** Cap concurrency and set priorities without touching native code.
|
|
47
57
|
- 🛡️ **Resilient:** Auto-retries on network errors with exponential backoff and HTTP resume.
|
|
48
58
|
- 🗜️ **Zero-Dependency Zip:** Uses native `java.util.zip` and iOS `zlib`.
|
|
49
|
-
- 🗄️ **Rich File System API:** Comprehensive FS methods (`readFile`, `writeFile`, `copyFile`, `mkdir`, `stat`, etc.).
|
|
59
|
+
- 🗄️ **Rich File System API:** Comprehensive FS methods (`readFile`, `writeFile`, `appendFile`, `copyFile`, `mkdir`, `stat`, `hash`, `df`, etc.).
|
|
60
|
+
- 🍪 **Cookie Management:** Read and clear HTTP cookies from the platform's shared cookie store.
|
|
61
|
+
- 📸 **MediaStore / Photos Library:** Save files directly to the device's shared media store.
|
|
62
|
+
- 📦 **Session Management:** Group files into named sessions for batch cleanup.
|
|
50
63
|
- 🛠️ **Expo Compatible:** Seamless integration with Expo custom dev clients.
|
|
51
64
|
|
|
52
65
|
---
|
|
@@ -159,19 +172,54 @@ export default function DownloadScreen() {
|
|
|
159
172
|
For programmatic, queue-aware background downloads outside of React components.
|
|
160
173
|
|
|
161
174
|
```typescript
|
|
162
|
-
import { download
|
|
163
|
-
|
|
164
|
-
// Optimize global concurrency
|
|
165
|
-
setQueueOptions({ maxConcurrent: 3 });
|
|
175
|
+
import { download } from 'rn-file-toolkit';
|
|
166
176
|
|
|
167
177
|
const result = await download({
|
|
168
178
|
url: 'https://example.com/file.pdf',
|
|
179
|
+
fileName: 'report.pdf', // Optional custom filename
|
|
169
180
|
destination: 'documents', // 'downloads' | 'cache' | 'documents'
|
|
181
|
+
background: true, // Survive app suspension
|
|
182
|
+
headers: { Authorization: 'Bearer token' },
|
|
170
183
|
queue: true, // Join the managed queue
|
|
171
184
|
priority: 'high', // 'high' | 'normal'
|
|
172
|
-
|
|
185
|
+
downloadId: 'my-unique-id', // Optional custom ID for tracking
|
|
186
|
+
notificationTitle: 'Downloading report…', // Android notification
|
|
187
|
+
notificationDescription: 'Please wait',
|
|
188
|
+
checksum: { hash: 'abc123...', algorithm: 'sha256' }, // Verify integrity
|
|
189
|
+
retry: {
|
|
190
|
+
attempts: 3,
|
|
191
|
+
delay: 1000,
|
|
192
|
+
onRetry: (attempt, error) => console.warn(`Retry #${attempt}: ${error}`),
|
|
193
|
+
},
|
|
173
194
|
onProgress: (p) => console.log(`${p.percent.toFixed(1)}% downloaded`),
|
|
174
195
|
});
|
|
196
|
+
|
|
197
|
+
console.log(result.filePath); // Path to the downloaded file
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Download Controls
|
|
201
|
+
|
|
202
|
+
Pause, resume, or cancel any active download by its ID—works both inside and outside React components.
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import {
|
|
206
|
+
download,
|
|
207
|
+
pauseDownload,
|
|
208
|
+
resumeDownload,
|
|
209
|
+
cancelDownload,
|
|
210
|
+
} from 'rn-file-toolkit';
|
|
211
|
+
|
|
212
|
+
// Start a download with a known ID
|
|
213
|
+
const result = download({
|
|
214
|
+
url: 'https://example.com/large-video.mp4',
|
|
215
|
+
downloadId: 'video-1',
|
|
216
|
+
destination: 'documents',
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// Later… pause, resume, or cancel by ID
|
|
220
|
+
await pauseDownload('video-1');
|
|
221
|
+
await resumeDownload('video-1');
|
|
222
|
+
await cancelDownload('video-1');
|
|
175
223
|
```
|
|
176
224
|
|
|
177
225
|
### Multipart Uploads
|
|
@@ -185,21 +233,52 @@ const result = await upload({
|
|
|
185
233
|
url: 'https://api.example.com/v1/upload',
|
|
186
234
|
filePath: '/path/to/local/image.jpg',
|
|
187
235
|
fieldName: 'file',
|
|
236
|
+
headers: { Authorization: 'Bearer token' },
|
|
188
237
|
parameters: { userId: '123', folder: 'avatars' },
|
|
238
|
+
uploadId: 'upload-1', // Optional custom ID for tracking
|
|
189
239
|
onProgress: (percent) => console.log(`Uploading: ${percent}%`),
|
|
190
240
|
});
|
|
241
|
+
|
|
242
|
+
console.log(result.status); // HTTP status code
|
|
243
|
+
console.log(result.data); // Server response body
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Queue Management
|
|
247
|
+
|
|
248
|
+
Control download concurrency globally and inspect the queue state.
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
import { setQueueOptions, getQueueStatus } from 'rn-file-toolkit';
|
|
252
|
+
|
|
253
|
+
// Set the maximum number of simultaneous downloads
|
|
254
|
+
setQueueOptions({ maxConcurrent: 3 });
|
|
255
|
+
|
|
256
|
+
// Inspect the queue at any time
|
|
257
|
+
const status = getQueueStatus();
|
|
258
|
+
console.log(status.active); // Currently downloading
|
|
259
|
+
console.log(status.pending); // Waiting in queue
|
|
260
|
+
console.log(status.maxConcurrent); // Concurrency cap
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
You can also retrieve all downloads currently running in the background (useful after app re-launch):
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
import { getBackgroundDownloads } from 'rn-file-toolkit';
|
|
267
|
+
|
|
268
|
+
const active = await getBackgroundDownloads();
|
|
269
|
+
console.log(active); // Array of background download descriptors
|
|
191
270
|
```
|
|
192
271
|
|
|
193
272
|
### File System (FS)
|
|
194
273
|
|
|
195
|
-
Perform native filesystem operations securely.
|
|
274
|
+
Perform native filesystem operations securely. All methods are available both as the namespaced `fs` object and as standalone named exports.
|
|
196
275
|
|
|
197
276
|
```typescript
|
|
198
277
|
import { fs } from 'rn-file-toolkit';
|
|
199
278
|
|
|
200
279
|
// Check & Inspect
|
|
201
280
|
const exists = await fs.exists('/path/to/data.json');
|
|
202
|
-
const stats = await fs.stat('/path/to/data.json'); // { size, modified, isDir }
|
|
281
|
+
const stats = await fs.stat('/path/to/data.json'); // { path, name, size, modified, isDir }
|
|
203
282
|
|
|
204
283
|
// Read & Write
|
|
205
284
|
await fs.writeFile('/path/to/data.txt', 'Hello World', 'utf8'); // Also supports 'base64'
|
|
@@ -213,18 +292,42 @@ await fs.moveFile('/path/old.txt', '/path/new.txt');
|
|
|
213
292
|
await fs.deleteFile('/path/unwanted.txt');
|
|
214
293
|
```
|
|
215
294
|
|
|
295
|
+
> **Tip:** You can also import each FS method individually:
|
|
296
|
+
> ```typescript
|
|
297
|
+
> import { exists, stat, readFile, writeFile, copyFile, moveFile, deleteFile, mkdir, ls } from 'rn-file-toolkit';
|
|
298
|
+
> ```
|
|
299
|
+
|
|
216
300
|
### Zip & Unzip Archives
|
|
217
301
|
|
|
218
|
-
Compress and extract archives directly on the device.
|
|
302
|
+
Compress and extract archives directly on the device using native `java.util.zip` (Android) and `zlib` (iOS).
|
|
219
303
|
|
|
220
304
|
```typescript
|
|
221
305
|
import { unzip, zip } from 'rn-file-toolkit';
|
|
222
306
|
|
|
223
307
|
// Extract a downloaded zip
|
|
224
|
-
await unzip('/path/to/bundle.zip', '/path/to/extract-folder');
|
|
308
|
+
const unzipResult = await unzip('/path/to/bundle.zip', '/path/to/extract-folder');
|
|
309
|
+
console.log(unzipResult.files); // List of extracted file paths
|
|
225
310
|
|
|
226
311
|
// Compress user data before uploading
|
|
227
|
-
await zip('/path/to/user-data-folder', '/path/to/backup.zip');
|
|
312
|
+
const zipResult = await zip('/path/to/user-data-folder', '/path/to/backup.zip');
|
|
313
|
+
console.log(zipResult.zipPath); // Path to the created archive
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Cache Management
|
|
317
|
+
|
|
318
|
+
Inspect and clear files stored in the cache directory.
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
import { getCachedFiles, clearCache } from 'rn-file-toolkit';
|
|
322
|
+
|
|
323
|
+
// List all cached files with metadata
|
|
324
|
+
const cache = await getCachedFiles();
|
|
325
|
+
cache.files?.forEach((f) => {
|
|
326
|
+
console.log(f.fileName, f.filePath, f.size, f.modifiedAt);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
// Wipe the entire cache directory
|
|
330
|
+
await clearCache();
|
|
228
331
|
```
|
|
229
332
|
|
|
230
333
|
### Media & Utilities
|
|
@@ -239,18 +342,27 @@ import {
|
|
|
239
342
|
openFile,
|
|
240
343
|
} from 'rn-file-toolkit';
|
|
241
344
|
|
|
242
|
-
// Base64 to File
|
|
345
|
+
// Base64 to File (accepts raw base64 or data URIs)
|
|
243
346
|
await saveBase64AsFile({
|
|
244
347
|
base64Data: 'data:image/png;base64,...',
|
|
245
348
|
destination: 'documents',
|
|
246
349
|
fileName: 'image.png',
|
|
247
350
|
});
|
|
248
351
|
|
|
249
|
-
// URL to Base64 (
|
|
250
|
-
const b64 = await urlToBase64({
|
|
352
|
+
// URL to Base64 (great for caching small images)
|
|
353
|
+
const b64 = await urlToBase64({
|
|
354
|
+
url: 'https://example.com/icon.png',
|
|
355
|
+
headers: { Authorization: 'Bearer token' }, // Optional
|
|
356
|
+
});
|
|
357
|
+
console.log(b64.mimeType); // e.g. 'image/png'
|
|
358
|
+
console.log(b64.dataUri); // Ready-to-use data URI string
|
|
251
359
|
|
|
252
360
|
// Native Share Sheet
|
|
253
|
-
await shareFile({
|
|
361
|
+
await shareFile({
|
|
362
|
+
filePath: '/path/to/report.pdf',
|
|
363
|
+
title: 'Share report', // Optional
|
|
364
|
+
subject: 'Monthly report', // Optional (email subject)
|
|
365
|
+
});
|
|
254
366
|
|
|
255
367
|
// Open with default system app
|
|
256
368
|
await openFile({
|
|
@@ -259,19 +371,248 @@ await openFile({
|
|
|
259
371
|
});
|
|
260
372
|
```
|
|
261
373
|
|
|
374
|
+
### Event Listeners
|
|
375
|
+
|
|
376
|
+
Subscribe to global download and upload lifecycle events. Each listener returns an unsubscribe function.
|
|
377
|
+
|
|
378
|
+
```typescript
|
|
379
|
+
import {
|
|
380
|
+
onDownloadComplete,
|
|
381
|
+
onDownloadError,
|
|
382
|
+
onDownloadRetry,
|
|
383
|
+
onUploadProgress,
|
|
384
|
+
} from 'rn-file-toolkit';
|
|
385
|
+
|
|
386
|
+
// Fires when any download finishes successfully
|
|
387
|
+
const unsub1 = onDownloadComplete((event) => {
|
|
388
|
+
console.log('Download done:', event);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
// Fires when any download fails
|
|
392
|
+
const unsub2 = onDownloadError((event) => {
|
|
393
|
+
console.error('Download failed:', event);
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
// Fires on each retry attempt (when retry is configured)
|
|
397
|
+
const unsub3 = onDownloadRetry((event) => {
|
|
398
|
+
console.warn(`Retry #${event.attempt}:`, event.error);
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
// Fires on upload progress updates
|
|
402
|
+
const unsub4 = onUploadProgress((event) => {
|
|
403
|
+
console.log(`Upload ${event.uploadId}: ${event.progress}%`);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
// Clean up when done
|
|
407
|
+
unsub1();
|
|
408
|
+
unsub2();
|
|
409
|
+
unsub3();
|
|
410
|
+
unsub4();
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
### Disk Space
|
|
414
|
+
|
|
415
|
+
Check available and total device storage.
|
|
416
|
+
|
|
417
|
+
```typescript
|
|
418
|
+
import { df } from 'rn-file-toolkit';
|
|
419
|
+
// or: import { fs } from 'rn-file-toolkit'; const result = await fs.df();
|
|
420
|
+
|
|
421
|
+
const space = await df();
|
|
422
|
+
if (space.success) {
|
|
423
|
+
console.log(`Free: ${(space.freeBytes! / 1024 / 1024 / 1024).toFixed(2)} GB`);
|
|
424
|
+
console.log(`Total: ${(space.totalBytes! / 1024 / 1024 / 1024).toFixed(2)} GB`);
|
|
425
|
+
}
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
### File Appending
|
|
429
|
+
|
|
430
|
+
Append data to the end of a file without overwriting existing content.
|
|
431
|
+
|
|
432
|
+
```typescript
|
|
433
|
+
import { appendFile } from 'rn-file-toolkit';
|
|
434
|
+
|
|
435
|
+
// Append a log line
|
|
436
|
+
await appendFile('/path/to/log.txt', 'New log entry\n');
|
|
437
|
+
|
|
438
|
+
// Append base64 data
|
|
439
|
+
await appendFile('/path/to/data.bin', base64String, 'base64');
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
### File Hashing
|
|
443
|
+
|
|
444
|
+
Compute the MD5, SHA-1, or SHA-256 hash of any file on disk.
|
|
445
|
+
|
|
446
|
+
```typescript
|
|
447
|
+
import { hash } from 'rn-file-toolkit';
|
|
448
|
+
|
|
449
|
+
const result = await hash('/path/to/file.zip', 'sha256');
|
|
450
|
+
if (result.success) {
|
|
451
|
+
console.log('SHA-256:', result.hash);
|
|
452
|
+
}
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
### Session Management
|
|
456
|
+
|
|
457
|
+
Group downloaded files into sessions for batch cleanup. Useful for temporary file workflows.
|
|
458
|
+
|
|
459
|
+
```typescript
|
|
460
|
+
import { session, download } from 'rn-file-toolkit';
|
|
461
|
+
|
|
462
|
+
// Download files and track them in a session
|
|
463
|
+
const result = await download({ url: 'https://example.com/tmp1.pdf', destination: 'cache' });
|
|
464
|
+
if (result.filePath) session.add('my-workflow', result.filePath);
|
|
465
|
+
|
|
466
|
+
const result2 = await download({ url: 'https://example.com/tmp2.pdf', destination: 'cache' });
|
|
467
|
+
if (result2.filePath) session.add('my-workflow', result2.filePath);
|
|
468
|
+
|
|
469
|
+
// List session files
|
|
470
|
+
console.log(session.get('my-workflow')); // ['/path/to/tmp1.pdf', '/path/to/tmp2.pdf']
|
|
471
|
+
|
|
472
|
+
// Clean up everything when done
|
|
473
|
+
await session.clear('my-workflow');
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
> **Note:** Session data lives in memory and does not persist across app restarts.
|
|
477
|
+
|
|
478
|
+
### Cookie Management
|
|
479
|
+
|
|
480
|
+
Read and clear HTTP cookies from the platform's shared cookie store.
|
|
481
|
+
|
|
482
|
+
```typescript
|
|
483
|
+
import { getCookies, clearCookies } from 'rn-file-toolkit';
|
|
484
|
+
// or: import { cookies } from 'rn-file-toolkit';
|
|
485
|
+
|
|
486
|
+
// Get cookies for a domain
|
|
487
|
+
const result = await getCookies('example.com');
|
|
488
|
+
result.cookies?.forEach((c) => {
|
|
489
|
+
console.log(`${c.name}=${c.value} (domain: ${c.domain})`);
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
// Clear cookies for a specific domain
|
|
493
|
+
await clearCookies('example.com');
|
|
494
|
+
|
|
495
|
+
// Clear ALL cookies
|
|
496
|
+
await clearCookies();
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
### MediaStore / Photos Library
|
|
500
|
+
|
|
501
|
+
Save files to the device's shared media store (Android MediaStore / iOS Photos Library).
|
|
502
|
+
|
|
503
|
+
```typescript
|
|
504
|
+
import { saveToMediaStore } from 'rn-file-toolkit';
|
|
505
|
+
|
|
506
|
+
// Save an image to the Photos library / gallery
|
|
507
|
+
const result = await saveToMediaStore({
|
|
508
|
+
filePath: '/path/to/photo.jpg',
|
|
509
|
+
mediaType: 'image',
|
|
510
|
+
album: 'MyApp', // Optional album/subfolder
|
|
511
|
+
});
|
|
512
|
+
console.log(result.uri); // content://... (Android) or file path (iOS)
|
|
513
|
+
|
|
514
|
+
// Save a video
|
|
515
|
+
await saveToMediaStore({
|
|
516
|
+
filePath: '/path/to/video.mp4',
|
|
517
|
+
mediaType: 'video',
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
// Save to the Downloads folder
|
|
521
|
+
await saveToMediaStore({
|
|
522
|
+
filePath: '/path/to/report.pdf',
|
|
523
|
+
mediaType: 'download',
|
|
524
|
+
});
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
> **Permissions:** iOS requires `NSPhotoLibraryAddUsageDescription` in your `Info.plist` for image/video saves. Android may require `WRITE_EXTERNAL_STORAGE` on API < 29.
|
|
528
|
+
|
|
262
529
|
---
|
|
263
530
|
|
|
264
531
|
## 📚 API Reference
|
|
265
532
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
|
269
|
-
|
|
|
270
|
-
| `
|
|
271
|
-
| `
|
|
272
|
-
| `
|
|
273
|
-
|
|
274
|
-
|
|
533
|
+
### Types & Interfaces
|
|
534
|
+
|
|
535
|
+
| Interface | Key Properties | Description |
|
|
536
|
+
| :--- | :--- | :--- |
|
|
537
|
+
| `DownloadOptions` | `url`, `fileName`, `destination`, `background`, `headers`, `queue`, `priority`, `downloadId`, `checksum`, `retry`, `onProgress`, `notificationTitle`, `notificationDescription` | Full configuration for downloading a file. |
|
|
538
|
+
| `UploadOptions` | `url`, `filePath`, `fieldName`, `headers`, `parameters`, `uploadId`, `onProgress` | Configuration for multipart uploads. |
|
|
539
|
+
| `ProgressInfo` | `percent`, `bytesDownloaded`, `totalBytes`, `speedBps`, `etaSeconds` | Rich real-time download progress payload. |
|
|
540
|
+
| `DownloadResult` | `success`, `filePath`, `downloadId`, `error` | Result returned after a download completes. |
|
|
541
|
+
| `UploadResult` | `success`, `status`, `data`, `uploadId`, `error` | Result returned after an upload completes. |
|
|
542
|
+
| `ActionResult` | `success`, `error` | Generic result for actions like pause/resume/cancel. |
|
|
543
|
+
| `UseDownloadReturn` | `start`, `pause`, `resume`, `cancel`, `status`, `progress`, `result`, `downloadId` | Hook state and control methods. |
|
|
544
|
+
| `FsApi` | `exists`, `stat`, `readFile`, `writeFile`, `appendFile`, `copyFile`, `moveFile`, `deleteFile`, `mkdir`, `ls`, `df`, `hash` | Namespaced filesystem API. |
|
|
545
|
+
| `FsStat` | `path`, `name`, `size`, `modified`, `isDir` | Output of the filesystem `stat` method. |
|
|
546
|
+
| `FsEncoding` | `'utf8'` \| `'base64'` | Encoding used for read/write operations. |
|
|
547
|
+
| `QueueOptions` | `maxConcurrent` | Configuration for the download queue. |
|
|
548
|
+
| `QueueStatus` | `active`, `pending`, `maxConcurrent` | Snapshot of the current queue state. |
|
|
549
|
+
| `CachedFile` | `fileName`, `filePath`, `size`, `modifiedAt` | Metadata for a single cached file. |
|
|
550
|
+
| `CacheResult` | `success`, `files`, `error` | Result of `getCachedFiles()`. |
|
|
551
|
+
| `SaveBase64Options` | `base64Data`, `fileName`, `destination` | Options for saving a base64 string to a file. |
|
|
552
|
+
| `SaveBase64Result` | `success`, `filePath`, `error` | Result of `saveBase64AsFile()`. |
|
|
553
|
+
| `UrlToBase64Options` | `url`, `headers` | Options for converting a URL to base64. |
|
|
554
|
+
| `UrlToBase64Result` | `success`, `base64`, `mimeType`, `dataUri`, `error` | Result of `urlToBase64()`. |
|
|
555
|
+
| `ShareFileOptions` | `filePath`, `title`, `subject` | Options for the native share sheet. |
|
|
556
|
+
| `OpenFileOptions` | `filePath`, `mimeType` | Options for opening a file with the system default app. |
|
|
557
|
+
| `UnzipResult` | `success`, `destDir`, `files`, `error` | Result of `unzip()`. |
|
|
558
|
+
| `ZipResult` | `success`, `zipPath`, `error` | Result of `zip()`. |
|
|
559
|
+
|
|
560
|
+
### Exported Functions
|
|
561
|
+
|
|
562
|
+
| Function | Signature | Description |
|
|
563
|
+
| :--- | :--- | :--- |
|
|
564
|
+
| `download` | `(options: DownloadOptions) => Promise<DownloadResult>` | Download a file (supports queue, background, retries). |
|
|
565
|
+
| `upload` | `(options: UploadOptions) => Promise<UploadResult>` | Multipart upload a file. |
|
|
566
|
+
| `pauseDownload` | `(id: string) => Promise<ActionResult>` | Pause an active download by ID. |
|
|
567
|
+
| `resumeDownload` | `(id: string) => Promise<ActionResult>` | Resume a paused download by ID. |
|
|
568
|
+
| `cancelDownload` | `(id: string) => Promise<ActionResult>` | Cancel a download by ID. |
|
|
569
|
+
| `setQueueOptions` | `(options: QueueOptions) => void` | Set global queue concurrency. |
|
|
570
|
+
| `getQueueStatus` | `() => QueueStatus` | Get current queue state (active/pending counts). |
|
|
571
|
+
| `getBackgroundDownloads` | `() => Promise<any>` | Retrieve active background download descriptors. |
|
|
572
|
+
| `getCachedFiles` | `() => Promise<CacheResult>` | List all files in the cache directory. |
|
|
573
|
+
| `clearCache` | `() => Promise<ActionResult>` | Delete all cached files. |
|
|
574
|
+
| `deleteFile` | `(path: string) => Promise<ActionResult>` | Delete a single file by path. |
|
|
575
|
+
| `exists` | `(path: string) => Promise<boolean>` | Check if a file or directory exists. |
|
|
576
|
+
| `stat` | `(path: string) => Promise<FsStat>` | Get metadata for a file or directory. |
|
|
577
|
+
| `readFile` | `(path: string, encoding?: FsEncoding) => Promise<string>` | Read file contents as a string. |
|
|
578
|
+
| `writeFile` | `(path: string, data: string, encoding?: FsEncoding) => Promise<void>` | Write a string to a file. |
|
|
579
|
+
| `copyFile` | `(from: string, to: string) => Promise<void>` | Copy a file. |
|
|
580
|
+
| `moveFile` | `(from: string, to: string) => Promise<void>` | Move or rename a file. |
|
|
581
|
+
| `mkdir` | `(path: string) => Promise<void>` | Create a directory (recursive). |
|
|
582
|
+
| `ls` | `(path: string) => Promise<string[]>` | List directory contents. |
|
|
583
|
+
| `unzip` | `(src: string, dest: string) => Promise<UnzipResult>` | Extract a zip archive. |
|
|
584
|
+
| `zip` | `(src: string, dest: string) => Promise<ZipResult>` | Compress a folder into a zip archive. |
|
|
585
|
+
| `saveBase64AsFile` | `(options: SaveBase64Options) => Promise<SaveBase64Result>` | Save a base64 string as a file. |
|
|
586
|
+
| `urlToBase64` | `(options: UrlToBase64Options) => Promise<UrlToBase64Result>` | Fetch a URL and return its content as base64. |
|
|
587
|
+
| `shareFile` | `(options: ShareFileOptions) => Promise<ShareFileResult>` | Open the native share sheet for a file. |
|
|
588
|
+
| `openFile` | `(options: OpenFileOptions) => Promise<OpenFileResult>` | Open a file with the system default app. |
|
|
589
|
+
| `onDownloadComplete` | `(cb) => () => void` | Subscribe to download completion events. |
|
|
590
|
+
| `onDownloadError` | `(cb) => () => void` | Subscribe to download error events. |
|
|
591
|
+
| `onDownloadRetry` | `(cb) => () => void` | Subscribe to download retry events. |
|
|
592
|
+
| `onUploadProgress` | `(cb) => () => void` | Subscribe to upload progress events. |
|
|
593
|
+
| `useDownload` | `() => UseDownloadReturn` | React hook for managing a download with state. |
|
|
594
|
+
| `df` | `() => Promise<DiskSpaceResult>` | Get free and total device disk space. |
|
|
595
|
+
| `appendFile` | `(path: string, data: string, encoding?: FsEncoding) => Promise<void>` | Append data to a file. |
|
|
596
|
+
| `hash` | `(path: string, algorithm?: HashAlgorithm) => Promise<HashResult>` | Compute a file's hash digest. |
|
|
597
|
+
| `getCookies` | `(domain: string) => Promise<CookiesResult>` | Get cookies for a domain. |
|
|
598
|
+
| `clearCookies` | `(domain?: string) => Promise<ActionResult>` | Clear cookies (domain or all). |
|
|
599
|
+
| `saveToMediaStore` | `(options: MediaStoreOptions) => Promise<MediaStoreResult>` | Save file to shared media store. |
|
|
600
|
+
| `fs` | `FsApi` | Namespaced object grouping all filesystem methods (includes `df`, `appendFile`, `hash`). |
|
|
601
|
+
| `cookies` | `{ get, clear }` | Namespaced cookie management. |
|
|
602
|
+
| `session` | `SessionApi` | Namespaced session management. |
|
|
603
|
+
|
|
604
|
+
### New Types & Interfaces
|
|
605
|
+
|
|
606
|
+
| Interface | Key Properties | Description |
|
|
607
|
+
| :--- | :--- | :--- |
|
|
608
|
+
| `DiskSpaceResult` | `success`, `freeBytes`, `totalBytes`, `error` | Result of `df()`. |
|
|
609
|
+
| `HashAlgorithm` | `'md5'` \| `'sha1'` \| `'sha256'` | Algorithm for file hashing. |
|
|
610
|
+
| `HashResult` | `success`, `hash`, `error` | Result of `hash()`. |
|
|
611
|
+
| `Cookie` | `name`, `value`, `domain`, `path`, `expiresDate`, `isSecure`, `isHTTPOnly` | A single cookie entry. |
|
|
612
|
+
| `CookiesResult` | `success`, `cookies`, `error` | Result of `getCookies()`. |
|
|
613
|
+
| `MediaStoreOptions` | `filePath`, `mediaType`, `album` | Options for saving to the media store. |
|
|
614
|
+
| `MediaStoreResult` | `success`, `uri`, `error` | Result of `saveToMediaStore()`. |
|
|
615
|
+
| `SessionApi` | `add`, `get`, `clear`, `clearAll` | Session management methods. |
|
|
275
616
|
|
|
276
617
|
---
|
|
277
618
|
|