rn-file-toolkit 1.0.3 → 1.0.5
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 +77 -30
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,7 +16,10 @@
|
|
|
16
16
|
⭐ **Star this repo if you find it useful to help others discover it!**
|
|
17
17
|
|
|
18
18
|
## 📖 Table of Contents
|
|
19
|
+
|
|
19
20
|
- [Why rn-file-toolkit?](#-why-rn-file-toolkit)
|
|
21
|
+
- [Why not Expo FileSystem?](#-why-not-expo-filesystem)
|
|
22
|
+
- [Documentation Website](#-documentation-website)
|
|
20
23
|
- [Installation](#-installation)
|
|
21
24
|
- [Quick Start: `useDownload`](#-quick-start-usedownload)
|
|
22
25
|
- [Core APIs](#-core-apis)
|
|
@@ -33,9 +36,10 @@
|
|
|
33
36
|
|
|
34
37
|
## 🚀 Why rn-file-toolkit?
|
|
35
38
|
|
|
36
|
-
Most React Native file solutions (`rn-fetch-blob`, `react-native-fs`) are fragmented, lightly maintained, or lack modern features. **rn-file-toolkit** gives you a unified, **TurboModule-
|
|
39
|
+
Most React Native file solutions (`rn-fetch-blob`, `react-native-fs`) are fragmented, lightly maintained, or lack modern features. **rn-file-toolkit** gives you a unified, **TurboModule-compatible** API utilizing OS-native managers (`URLSession` on iOS, `DownloadManager` on Android) for reliable, battery-efficient operations.
|
|
37
40
|
|
|
38
41
|
### ✨ Highlights
|
|
42
|
+
|
|
39
43
|
- 🪝 **Drop-in React Hooks:** Built-in state management (`useDownload`) for progress and controls.
|
|
40
44
|
- 📥 **Background Ready:** Downloads and uploads survive app suspension with automatic re-attachment.
|
|
41
45
|
- 🚦 **Smart Queueing:** Cap concurrency and set priorities without touching native code.
|
|
@@ -46,6 +50,27 @@ Most React Native file solutions (`rn-fetch-blob`, `react-native-fs`) are fragme
|
|
|
46
50
|
|
|
47
51
|
---
|
|
48
52
|
|
|
53
|
+
## 🤔 Why not Expo FileSystem?
|
|
54
|
+
|
|
55
|
+
Many developers looking for an **"expo-file-system alternative"** or a **"better react native download manager"** come here. While Expo FileSystem is a great tool for basic file operations, `rn-file-toolkit` is built specifically to handle complex, real-world file management scenarios:
|
|
56
|
+
|
|
57
|
+
- **Queueing & Concurrency:** Built-in smart queueing allows you to cap concurrent downloads and set priorities without writing complex JavaScript wrappers.
|
|
58
|
+
- **Native Download/Upload Managers:** We hook directly into OS-level managers (`URLSession` on iOS, `DownloadManager` on Android) for maximum reliability and battery efficiency.
|
|
59
|
+
- **Auto-Retries & Resiliency:** Native implementations handle network drops with exponential backoff and HTTP resume automatically.
|
|
60
|
+
- **Multipart Uploads:** Robust, memory-efficient multipart uploads for large media are built right in.
|
|
61
|
+
- **Drop-in React Hooks:** Provides a `useDownload` hook out-of-the-box for instant progress tracking, speed, ETA, and state controls.
|
|
62
|
+
- **Background Persistence:** Downloads and uploads survive app suspension and backgrounding, automatically re-attaching when the app resumes.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## 🌐 Documentation Website
|
|
67
|
+
|
|
68
|
+
Full docs are hosted on GitHub Pages:
|
|
69
|
+
|
|
70
|
+
https://chavan-labs.github.io/rn-file-toolkit/
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
49
74
|
## 📦 Installation
|
|
50
75
|
|
|
51
76
|
```bash
|
|
@@ -59,7 +84,7 @@ yarn add rn-file-toolkit
|
|
|
59
84
|
pnpm add rn-file-toolkit
|
|
60
85
|
```
|
|
61
86
|
|
|
62
|
-
|
|
87
|
+
_(Optional) If you are not using Expo or an auto-linking setup, run `pod install` in your `ios` directory._
|
|
63
88
|
|
|
64
89
|
---
|
|
65
90
|
|
|
@@ -73,22 +98,27 @@ import { View, Text, Button } from 'react-native';
|
|
|
73
98
|
import { useDownload } from 'rn-file-toolkit';
|
|
74
99
|
|
|
75
100
|
export default function DownloadScreen() {
|
|
76
|
-
const { start, pause, resume, cancel, status, progress, result } =
|
|
101
|
+
const { start, pause, resume, cancel, status, progress, result } =
|
|
102
|
+
useDownload();
|
|
77
103
|
|
|
78
104
|
return (
|
|
79
105
|
<View style={{ padding: 20 }}>
|
|
80
|
-
<Button
|
|
81
|
-
title="Start Download"
|
|
82
|
-
onPress={() =>
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
106
|
+
<Button
|
|
107
|
+
title="Start Download"
|
|
108
|
+
onPress={() =>
|
|
109
|
+
start({
|
|
110
|
+
url: 'https://example.com/large-video.mp4',
|
|
111
|
+
destination: 'documents',
|
|
112
|
+
})
|
|
113
|
+
}
|
|
86
114
|
/>
|
|
87
115
|
|
|
88
116
|
{status === 'downloading' && progress && (
|
|
89
117
|
<View style={{ marginTop: 20 }}>
|
|
90
118
|
<Text>Progress: {progress.percent.toFixed(1)}%</Text>
|
|
91
|
-
<Text>
|
|
119
|
+
<Text>
|
|
120
|
+
Speed: {(progress.speedBps / 1024 / 1024).toFixed(2)} MB/s
|
|
121
|
+
</Text>
|
|
92
122
|
<Text>ETA: {progress.etaSeconds.toFixed(0)} seconds</Text>
|
|
93
123
|
<View style={{ flexDirection: 'row', gap: 10, marginTop: 10 }}>
|
|
94
124
|
<Button title="Pause" onPress={pause} />
|
|
@@ -98,8 +128,12 @@ export default function DownloadScreen() {
|
|
|
98
128
|
)}
|
|
99
129
|
|
|
100
130
|
{status === 'paused' && <Button title="Resume" onPress={resume} />}
|
|
101
|
-
{status === 'done' &&
|
|
102
|
-
|
|
131
|
+
{status === 'done' && (
|
|
132
|
+
<Text style={{ color: 'green' }}>✅ Saved: {result?.filePath}</Text>
|
|
133
|
+
)}
|
|
134
|
+
{status === 'error' && (
|
|
135
|
+
<Text style={{ color: 'red' }}>❌ Error: {result?.error}</Text>
|
|
136
|
+
)}
|
|
103
137
|
</View>
|
|
104
138
|
);
|
|
105
139
|
}
|
|
@@ -110,6 +144,7 @@ export default function DownloadScreen() {
|
|
|
110
144
|
## 🛠️ Core APIs
|
|
111
145
|
|
|
112
146
|
### Background Downloads
|
|
147
|
+
|
|
113
148
|
For programmatic, queue-aware background downloads outside of React components.
|
|
114
149
|
|
|
115
150
|
```typescript
|
|
@@ -121,14 +156,15 @@ setQueueOptions({ maxConcurrent: 3 });
|
|
|
121
156
|
const result = await download({
|
|
122
157
|
url: 'https://example.com/file.pdf',
|
|
123
158
|
destination: 'documents', // 'downloads' | 'cache' | 'documents'
|
|
124
|
-
queue: true,
|
|
125
|
-
priority: 'high',
|
|
159
|
+
queue: true, // Join the managed queue
|
|
160
|
+
priority: 'high', // 'high' | 'normal'
|
|
126
161
|
retry: { attempts: 3, delay: 1000 },
|
|
127
162
|
onProgress: (p) => console.log(`${p.percent.toFixed(1)}% downloaded`),
|
|
128
163
|
});
|
|
129
164
|
```
|
|
130
165
|
|
|
131
166
|
### Multipart Uploads
|
|
167
|
+
|
|
132
168
|
Robust, memory-efficient multipart file uploading for large media or documents.
|
|
133
169
|
|
|
134
170
|
```typescript
|
|
@@ -144,6 +180,7 @@ const result = await upload({
|
|
|
144
180
|
```
|
|
145
181
|
|
|
146
182
|
### File System (FS)
|
|
183
|
+
|
|
147
184
|
Perform native filesystem operations securely.
|
|
148
185
|
|
|
149
186
|
```typescript
|
|
@@ -166,6 +203,7 @@ await fs.deleteFile('/path/unwanted.txt');
|
|
|
166
203
|
```
|
|
167
204
|
|
|
168
205
|
### Zip & Unzip Archives
|
|
206
|
+
|
|
169
207
|
Compress and extract archives directly on the device.
|
|
170
208
|
|
|
171
209
|
```typescript
|
|
@@ -179,16 +217,22 @@ await zip('/path/to/user-data-folder', '/path/to/backup.zip');
|
|
|
179
217
|
```
|
|
180
218
|
|
|
181
219
|
### Media & Utilities
|
|
220
|
+
|
|
182
221
|
Helpful tools for sharing, opening, and encoding files.
|
|
183
222
|
|
|
184
223
|
```typescript
|
|
185
|
-
import {
|
|
224
|
+
import {
|
|
225
|
+
saveBase64AsFile,
|
|
226
|
+
urlToBase64,
|
|
227
|
+
shareFile,
|
|
228
|
+
openFile,
|
|
229
|
+
} from 'rn-file-toolkit';
|
|
186
230
|
|
|
187
231
|
// Base64 to File
|
|
188
|
-
await saveBase64AsFile({
|
|
189
|
-
base64Data: 'data:image/png;base64,...',
|
|
232
|
+
await saveBase64AsFile({
|
|
233
|
+
base64Data: 'data:image/png;base64,...',
|
|
190
234
|
destination: 'documents',
|
|
191
|
-
fileName: 'image.png'
|
|
235
|
+
fileName: 'image.png',
|
|
192
236
|
});
|
|
193
237
|
|
|
194
238
|
// URL to Base64 (Great for caching small images)
|
|
@@ -198,28 +242,31 @@ const b64 = await urlToBase64({ url: 'https://example.com/icon.png' });
|
|
|
198
242
|
await shareFile({ filePath: '/path/to/report.pdf' });
|
|
199
243
|
|
|
200
244
|
// Open with default system app
|
|
201
|
-
await openFile({
|
|
245
|
+
await openFile({
|
|
246
|
+
filePath: '/path/to/report.pdf',
|
|
247
|
+
mimeType: 'application/pdf',
|
|
248
|
+
});
|
|
202
249
|
```
|
|
203
250
|
|
|
204
251
|
---
|
|
205
252
|
|
|
206
253
|
## 📚 API Reference
|
|
207
254
|
|
|
208
|
-
| Interface
|
|
209
|
-
|
|
|
210
|
-
| `DownloadOptions`
|
|
211
|
-
| `UploadOptions`
|
|
212
|
-
| `ProgressInfo`
|
|
213
|
-
| `UseDownloadReturn` | `start`, `pause`, `resume`, `cancel`, `status`, `progress` | Hook state and control methods.
|
|
214
|
-
| `FsStat`
|
|
255
|
+
| Interface | Key Properties | Description |
|
|
256
|
+
| :------------------ | :--------------------------------------------------------- | :-------------------------------------- |
|
|
257
|
+
| `DownloadOptions` | `url`, `destination`, `queue`, `retry`, `onProgress` | Configuration for downloading a file. |
|
|
258
|
+
| `UploadOptions` | `url`, `filePath`, `fieldName`, `parameters`, `onProgress` | Configuration for multipart uploads. |
|
|
259
|
+
| `ProgressInfo` | `percent`, `bytesDownloaded`, `speedBps`, `etaSeconds` | Rich real-time progress payload. |
|
|
260
|
+
| `UseDownloadReturn` | `start`, `pause`, `resume`, `cancel`, `status`, `progress` | Hook state and control methods. |
|
|
261
|
+
| `FsStat` | `size`, `modified`, `isDir` | Output of the filesystem `stat` method. |
|
|
215
262
|
|
|
216
|
-
|
|
263
|
+
_For advanced types and detailed parameter documentation, please refer to the source TypeScript definitions._
|
|
217
264
|
|
|
218
265
|
---
|
|
219
266
|
|
|
220
267
|
## 🎪 Expo Support
|
|
221
268
|
|
|
222
|
-
**rn-file-toolkit** works seamlessly with Expo custom development clients (EAS Build / `npx expo run:android` / `npx expo run:ios`). Since it contains native code, it is not compatible with Expo Go.
|
|
269
|
+
**rn-file-toolkit** works seamlessly with Expo custom development clients (EAS Build / `npx expo run:android` / `npx expo run:ios`). Since it contains native code, it is not compatible with Expo Go.
|
|
223
270
|
|
|
224
271
|
An Expo config plugin is included automatically. No extra configuration is needed in your `app.json` unless you want to customize permissions.
|
|
225
272
|
|
|
@@ -227,7 +274,7 @@ An Expo config plugin is included automatically. No extra configuration is neede
|
|
|
227
274
|
|
|
228
275
|
## 🤝 Contributing
|
|
229
276
|
|
|
230
|
-
Contributions are welcome! If you find a bug or want to request a feature, please [open an issue](https://github.com/chavan-labs/rn-file-toolkit/issues).
|
|
277
|
+
Contributions are welcome! If you find a bug or want to request a feature, please [open an issue](https://github.com/chavan-labs/rn-file-toolkit/issues).
|
|
231
278
|
|
|
232
279
|
1. Fork the repository
|
|
233
280
|
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
|
|
@@ -238,5 +285,5 @@ Contributions are welcome! If you find a bug or want to request a feature, pleas
|
|
|
238
285
|
---
|
|
239
286
|
|
|
240
287
|
<div align="center">
|
|
241
|
-
<i>Built with ❤️ for the React Native community by <a href="https://github.com/
|
|
288
|
+
<i>Built with ❤️ for the React Native community by <a href="https://github.com/chavanRk">Rohit Chavan</a></i>
|
|
242
289
|
</div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rn-file-toolkit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "The ultimate native file management toolkit for React Native. Features background downloads, resumable uploads, filesystem operations, queues, zip/unzip, and media utilities with zero third-party dependencies.",
|
|
5
5
|
"main": "./lib/commonjs/index.js",
|
|
6
6
|
"module": "./lib/module/index.js",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"bugs": {
|
|
124
124
|
"url": "https://github.com/chavan-labs/rn-file-toolkit/issues"
|
|
125
125
|
},
|
|
126
|
-
"homepage": "https://
|
|
126
|
+
"homepage": "https://chavan-labs.github.io/rn-file-toolkit/",
|
|
127
127
|
"publishConfig": {
|
|
128
128
|
"registry": "https://registry.npmjs.org/"
|
|
129
129
|
},
|