rn-file-toolkit 1.0.4 → 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 +61 -28
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,8 +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)
|
|
20
21
|
- [Why not Expo FileSystem?](#-why-not-expo-filesystem)
|
|
22
|
+
- [Documentation Website](#-documentation-website)
|
|
21
23
|
- [Installation](#-installation)
|
|
22
24
|
- [Quick Start: `useDownload`](#-quick-start-usedownload)
|
|
23
25
|
- [Core APIs](#-core-apis)
|
|
@@ -37,6 +39,7 @@
|
|
|
37
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.
|
|
38
40
|
|
|
39
41
|
### ✨ Highlights
|
|
42
|
+
|
|
40
43
|
- 🪝 **Drop-in React Hooks:** Built-in state management (`useDownload`) for progress and controls.
|
|
41
44
|
- 📥 **Background Ready:** Downloads and uploads survive app suspension with automatic re-attachment.
|
|
42
45
|
- 🚦 **Smart Queueing:** Cap concurrency and set priorities without touching native code.
|
|
@@ -60,6 +63,14 @@ Many developers looking for an **"expo-file-system alternative"** or a **"better
|
|
|
60
63
|
|
|
61
64
|
---
|
|
62
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
|
+
|
|
63
74
|
## 📦 Installation
|
|
64
75
|
|
|
65
76
|
```bash
|
|
@@ -73,7 +84,7 @@ yarn add rn-file-toolkit
|
|
|
73
84
|
pnpm add rn-file-toolkit
|
|
74
85
|
```
|
|
75
86
|
|
|
76
|
-
|
|
87
|
+
_(Optional) If you are not using Expo or an auto-linking setup, run `pod install` in your `ios` directory._
|
|
77
88
|
|
|
78
89
|
---
|
|
79
90
|
|
|
@@ -87,22 +98,27 @@ import { View, Text, Button } from 'react-native';
|
|
|
87
98
|
import { useDownload } from 'rn-file-toolkit';
|
|
88
99
|
|
|
89
100
|
export default function DownloadScreen() {
|
|
90
|
-
const { start, pause, resume, cancel, status, progress, result } =
|
|
101
|
+
const { start, pause, resume, cancel, status, progress, result } =
|
|
102
|
+
useDownload();
|
|
91
103
|
|
|
92
104
|
return (
|
|
93
105
|
<View style={{ padding: 20 }}>
|
|
94
|
-
<Button
|
|
95
|
-
title="Start Download"
|
|
96
|
-
onPress={() =>
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
106
|
+
<Button
|
|
107
|
+
title="Start Download"
|
|
108
|
+
onPress={() =>
|
|
109
|
+
start({
|
|
110
|
+
url: 'https://example.com/large-video.mp4',
|
|
111
|
+
destination: 'documents',
|
|
112
|
+
})
|
|
113
|
+
}
|
|
100
114
|
/>
|
|
101
115
|
|
|
102
116
|
{status === 'downloading' && progress && (
|
|
103
117
|
<View style={{ marginTop: 20 }}>
|
|
104
118
|
<Text>Progress: {progress.percent.toFixed(1)}%</Text>
|
|
105
|
-
<Text>
|
|
119
|
+
<Text>
|
|
120
|
+
Speed: {(progress.speedBps / 1024 / 1024).toFixed(2)} MB/s
|
|
121
|
+
</Text>
|
|
106
122
|
<Text>ETA: {progress.etaSeconds.toFixed(0)} seconds</Text>
|
|
107
123
|
<View style={{ flexDirection: 'row', gap: 10, marginTop: 10 }}>
|
|
108
124
|
<Button title="Pause" onPress={pause} />
|
|
@@ -112,8 +128,12 @@ export default function DownloadScreen() {
|
|
|
112
128
|
)}
|
|
113
129
|
|
|
114
130
|
{status === 'paused' && <Button title="Resume" onPress={resume} />}
|
|
115
|
-
{status === 'done' &&
|
|
116
|
-
|
|
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
|
+
)}
|
|
117
137
|
</View>
|
|
118
138
|
);
|
|
119
139
|
}
|
|
@@ -124,6 +144,7 @@ export default function DownloadScreen() {
|
|
|
124
144
|
## 🛠️ Core APIs
|
|
125
145
|
|
|
126
146
|
### Background Downloads
|
|
147
|
+
|
|
127
148
|
For programmatic, queue-aware background downloads outside of React components.
|
|
128
149
|
|
|
129
150
|
```typescript
|
|
@@ -135,14 +156,15 @@ setQueueOptions({ maxConcurrent: 3 });
|
|
|
135
156
|
const result = await download({
|
|
136
157
|
url: 'https://example.com/file.pdf',
|
|
137
158
|
destination: 'documents', // 'downloads' | 'cache' | 'documents'
|
|
138
|
-
queue: true,
|
|
139
|
-
priority: 'high',
|
|
159
|
+
queue: true, // Join the managed queue
|
|
160
|
+
priority: 'high', // 'high' | 'normal'
|
|
140
161
|
retry: { attempts: 3, delay: 1000 },
|
|
141
162
|
onProgress: (p) => console.log(`${p.percent.toFixed(1)}% downloaded`),
|
|
142
163
|
});
|
|
143
164
|
```
|
|
144
165
|
|
|
145
166
|
### Multipart Uploads
|
|
167
|
+
|
|
146
168
|
Robust, memory-efficient multipart file uploading for large media or documents.
|
|
147
169
|
|
|
148
170
|
```typescript
|
|
@@ -158,6 +180,7 @@ const result = await upload({
|
|
|
158
180
|
```
|
|
159
181
|
|
|
160
182
|
### File System (FS)
|
|
183
|
+
|
|
161
184
|
Perform native filesystem operations securely.
|
|
162
185
|
|
|
163
186
|
```typescript
|
|
@@ -180,6 +203,7 @@ await fs.deleteFile('/path/unwanted.txt');
|
|
|
180
203
|
```
|
|
181
204
|
|
|
182
205
|
### Zip & Unzip Archives
|
|
206
|
+
|
|
183
207
|
Compress and extract archives directly on the device.
|
|
184
208
|
|
|
185
209
|
```typescript
|
|
@@ -193,16 +217,22 @@ await zip('/path/to/user-data-folder', '/path/to/backup.zip');
|
|
|
193
217
|
```
|
|
194
218
|
|
|
195
219
|
### Media & Utilities
|
|
220
|
+
|
|
196
221
|
Helpful tools for sharing, opening, and encoding files.
|
|
197
222
|
|
|
198
223
|
```typescript
|
|
199
|
-
import {
|
|
224
|
+
import {
|
|
225
|
+
saveBase64AsFile,
|
|
226
|
+
urlToBase64,
|
|
227
|
+
shareFile,
|
|
228
|
+
openFile,
|
|
229
|
+
} from 'rn-file-toolkit';
|
|
200
230
|
|
|
201
231
|
// Base64 to File
|
|
202
|
-
await saveBase64AsFile({
|
|
203
|
-
base64Data: 'data:image/png;base64,...',
|
|
232
|
+
await saveBase64AsFile({
|
|
233
|
+
base64Data: 'data:image/png;base64,...',
|
|
204
234
|
destination: 'documents',
|
|
205
|
-
fileName: 'image.png'
|
|
235
|
+
fileName: 'image.png',
|
|
206
236
|
});
|
|
207
237
|
|
|
208
238
|
// URL to Base64 (Great for caching small images)
|
|
@@ -212,28 +242,31 @@ const b64 = await urlToBase64({ url: 'https://example.com/icon.png' });
|
|
|
212
242
|
await shareFile({ filePath: '/path/to/report.pdf' });
|
|
213
243
|
|
|
214
244
|
// Open with default system app
|
|
215
|
-
await openFile({
|
|
245
|
+
await openFile({
|
|
246
|
+
filePath: '/path/to/report.pdf',
|
|
247
|
+
mimeType: 'application/pdf',
|
|
248
|
+
});
|
|
216
249
|
```
|
|
217
250
|
|
|
218
251
|
---
|
|
219
252
|
|
|
220
253
|
## 📚 API Reference
|
|
221
254
|
|
|
222
|
-
| Interface
|
|
223
|
-
|
|
|
224
|
-
| `DownloadOptions`
|
|
225
|
-
| `UploadOptions`
|
|
226
|
-
| `ProgressInfo`
|
|
227
|
-
| `UseDownloadReturn` | `start`, `pause`, `resume`, `cancel`, `status`, `progress` | Hook state and control methods.
|
|
228
|
-
| `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. |
|
|
229
262
|
|
|
230
|
-
|
|
263
|
+
_For advanced types and detailed parameter documentation, please refer to the source TypeScript definitions._
|
|
231
264
|
|
|
232
265
|
---
|
|
233
266
|
|
|
234
267
|
## 🎪 Expo Support
|
|
235
268
|
|
|
236
|
-
**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.
|
|
237
270
|
|
|
238
271
|
An Expo config plugin is included automatically. No extra configuration is needed in your `app.json` unless you want to customize permissions.
|
|
239
272
|
|
|
@@ -241,7 +274,7 @@ An Expo config plugin is included automatically. No extra configuration is neede
|
|
|
241
274
|
|
|
242
275
|
## 🤝 Contributing
|
|
243
276
|
|
|
244
|
-
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).
|
|
245
278
|
|
|
246
279
|
1. Fork the repository
|
|
247
280
|
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
|
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
|
},
|