@onekeyfe/react-native-range-downloader 6.7.0-alpha.466 → 6.8.0-10
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 +131 -39
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,68 +1,160 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
react-native-range-downloader
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# @onekeyfe/react-native-range-downloader
|
|
4
|
+
|
|
5
|
+
**Resumable multi-connection HTTP range downloads for OneKey OTA, APK and asset updates.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@onekeyfe/react-native-range-downloader)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
Fetches one file over parallel HTTP byte-range connections to improve throughput
|
|
16
|
+
on high-latency mobile networks, then assembles and promotes it atomically. Each
|
|
17
|
+
segment is persisted on disk, so a new run resumes from completed bytes instead
|
|
18
|
+
of starting over. The concurrent path is an accelerator: when a server or
|
|
19
|
+
network cannot support ranges, `download()` reports a typed fallback and the
|
|
20
|
+
caller keeps ownership of its single-stream path. iOS transfers through
|
|
21
|
+
background `URLSession`s, Android through a thread pool.
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- **Parallel segments, bounded default** — an 8-segment plan for files at or
|
|
26
|
+
above the 2 MB concurrency threshold.
|
|
27
|
+
- **Resume instead of restart** — completed `.segN` artifacts survive process
|
|
28
|
+
restarts; a re-run fetches only missing or incomplete segments.
|
|
29
|
+
- **Typed outcomes, no prose parsing** — `completed`, `fallbackTransient`,
|
|
30
|
+
`fallbackPermanent` and a `fallbackKind` such as `authExpired`.
|
|
31
|
+
- **Filterable progress events** — one shared registry routes `start`,
|
|
32
|
+
`progress`, `complete`, `error` and `fallback` events by channel and `taskId`.
|
|
33
|
+
- **Explicit cancel and discard** — in-flight work stops before artifacts are
|
|
34
|
+
deleted, so a running task cannot resurrect them.
|
|
35
|
+
- **Integrity and security** — HTTPS on every redirect hop, optional whole-file
|
|
36
|
+
SHA-256 before the atomic rename, and rejection of short or mis-aligned `206`.
|
|
4
37
|
|
|
5
38
|
## Installation
|
|
6
39
|
|
|
7
40
|
```sh
|
|
8
|
-
|
|
41
|
+
yarn add @onekeyfe/react-native-range-downloader react-native-nitro-modules
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Install the app's iOS pods and rebuild the native binary; Android links through
|
|
45
|
+
autolinking. `react-native-nitro-modules` is a required peer dependency, and the
|
|
46
|
+
native code also links `@onekeyfe/react-native-native-logger`. The Android app
|
|
47
|
+
needs the normal `INTERNET` permission; the package declares no permissions.
|
|
48
|
+
|
|
49
|
+
For background transfers to complete after suspension, the app delegate must
|
|
50
|
+
forward background `URLSession` events to the module:
|
|
51
|
+
|
|
52
|
+
```swift
|
|
53
|
+
func application(_ app: UIApplication,
|
|
54
|
+
handleEventsForBackgroundURLSession id: String,
|
|
55
|
+
completionHandler: @escaping () -> Void) {
|
|
56
|
+
NotificationCenter.default.post(
|
|
57
|
+
name: Notification.Name("RangeDownloaderBackgroundEvents"),
|
|
58
|
+
object: nil,
|
|
59
|
+
userInfo: ["identifier": id, "completionHandler": completionHandler]
|
|
60
|
+
)
|
|
61
|
+
}
|
|
9
62
|
```
|
|
10
63
|
|
|
11
|
-
|
|
64
|
+
Android has no background-session concept: a run continues while the process
|
|
65
|
+
lives and resumes from persisted segments on the next launch.
|
|
12
66
|
|
|
13
67
|
## Usage
|
|
14
68
|
|
|
15
69
|
```ts
|
|
16
|
-
import { ReactNativeRangeDownloader } from '@onekeyfe/react-native-range-downloader';
|
|
17
|
-
|
|
18
|
-
// ...
|
|
19
|
-
|
|
20
|
-
const taskId = 'chart-assets';
|
|
21
|
-
const destFilePath = `${ReactNativeRangeDownloader.getDownloadsDir()}/chart-assets.zip`;
|
|
70
|
+
import { ReactNativeRangeDownloader, RangeDownloadChannel } from '@onekeyfe/react-native-range-downloader';
|
|
22
71
|
|
|
72
|
+
const taskId = 'bundle-2026-11';
|
|
73
|
+
const destFilePath = `${ReactNativeRangeDownloader.getDownloadsDir()}/${taskId}.zip`;
|
|
23
74
|
const listenerId = ReactNativeRangeDownloader.addDownloadListener((event) => {
|
|
24
|
-
if (event.channel ===
|
|
75
|
+
if (event.channel === RangeDownloadChannel.Bundle && event.taskId === taskId) {
|
|
25
76
|
console.log(event.type, event.progress, event.message);
|
|
26
77
|
}
|
|
27
78
|
});
|
|
28
79
|
|
|
29
80
|
try {
|
|
30
81
|
const result = await ReactNativeRangeDownloader.download({
|
|
31
|
-
channel:
|
|
82
|
+
channel: RangeDownloadChannel.Bundle,
|
|
32
83
|
taskId,
|
|
33
|
-
url: 'https://example.com/
|
|
84
|
+
url: 'https://example.com/bundle.zip',
|
|
34
85
|
destFilePath,
|
|
35
86
|
});
|
|
36
|
-
console.log(result.outcome, result.
|
|
87
|
+
console.log(result.outcome, result.fallbackKind, result.fallbackReason);
|
|
37
88
|
} finally {
|
|
38
89
|
ReactNativeRangeDownloader.removeDownloadListener(listenerId);
|
|
39
90
|
}
|
|
40
91
|
```
|
|
41
92
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
93
|
+
The caller supplies `destFilePath` and owns directory layout, install flow and
|
|
94
|
+
signature checks; the module owns segment transfer, resume, retry, assembly and
|
|
95
|
+
the checksum it was given.
|
|
96
|
+
|
|
97
|
+
## API
|
|
98
|
+
|
|
99
|
+
| Export | Signature | Platforms | Description |
|
|
100
|
+
| --- | --- | :-: | --- |
|
|
101
|
+
| `download` | `(params: RangeDownloadParams) => Promise<RangeDownloadResult>` | iOS, Android | Runs the concurrent download and resolves once the outcome is decided. |
|
|
102
|
+
| `cancel` | `(channel, taskId, destFilePath) => Promise<void>` | iOS, Android | Cancels the matching run and removes its artifacts. |
|
|
103
|
+
| `discardArtifacts` | `(channel, taskId, destFilePath) => Promise<void>` | iOS, Android | Removes `.segN` / `.partial` / `.progress` artifacts for one task. |
|
|
104
|
+
| `addDownloadListener` | `(callback: (event: RangeDownloadEvent) => void) => number` | iOS, Android | Registers a shared progress listener; returns an id. |
|
|
105
|
+
| `removeDownloadListener` | `(id: number) => void` | iOS, Android | Unregisters a listener. |
|
|
106
|
+
| `getDownloadsDir` | `() => string` | iOS, Android | App-owned writable cache directory for scratch destinations. |
|
|
107
|
+
| `RangeDownloadChannel` | `{ Bundle, Apk, Chart, Firmware }` | iOS, Android | Closed channel set used for event routing and session identity. |
|
|
108
|
+
| Firmware staging | `downloadFirmwareArtifact`, `openFirmwareArtifact`, `readFirmwareArtifact`, `closeFirmwareArtifact`, `discardFirmwareArtifact`, `cancelFirmwareArtifactDownloads`, `materializeFirmwareArchive`, `createFirmwareArtifactLease`, `retainFirmwareArtifact`, `releaseFirmwareArtifactLease`, `sweepFirmwareArtifactOrphans`, `getFirmwareArtifactCapabilities` | iOS, Android | Staged firmware artifact download, bounded reader, archive materialization, lease and orphan sweep. |
|
|
109
|
+
|
|
110
|
+
`RangeDownloadParams` needs `channel`, `taskId`, an HTTPS `url` and an absolute
|
|
111
|
+
`destFilePath`; optional knobs include `expectedSha256`, `segmentCount` (8),
|
|
112
|
+
`minConcurrentBytes` (2 MB), `maxSegmentAttempts` (4), `requestTimeoutSeconds`
|
|
113
|
+
(60), `stallTimeoutSeconds` (30) and `overallDeadlineSeconds` (0 = none). The
|
|
114
|
+
retry, stall and deadline knobs are consumed by the iOS implementation; the
|
|
115
|
+
Android concurrent path keeps its own fixed retry tuning.
|
|
116
|
+
|
|
117
|
+
The normative behavior is the
|
|
118
|
+
[OneKey Concurrent Download Standard](SPEC.md); the package's own native contract
|
|
119
|
+
is [`docs/SPEC.md`](docs/SPEC.md), and the public types are in
|
|
120
|
+
[`src/ReactNativeRangeDownloader.nitro.ts`](src/ReactNativeRangeDownloader.nitro.ts).
|
|
121
|
+
|
|
122
|
+
## Platform support
|
|
123
|
+
|
|
124
|
+
| Capability | iOS | Android | Web |
|
|
125
|
+
| --- | :-: | :-: | :-: |
|
|
126
|
+
| Concurrent range download | ✅ | ✅ | — |
|
|
127
|
+
| Resume from on-disk segments | ✅ | ✅ | — |
|
|
128
|
+
| OS background transfer | ✅ background `URLSession` | — in-process only | — |
|
|
129
|
+
| Progress event stream | ✅ | ✅ | — |
|
|
130
|
+
| Typed fallback classification | ✅ | ✅ | — |
|
|
131
|
+
| Cancel / discard artifacts | ✅ | ✅ | — |
|
|
132
|
+
| Firmware artifact staging | ✅ | ✅ | — |
|
|
133
|
+
|
|
134
|
+
## Caveats
|
|
135
|
+
|
|
136
|
+
> [!IMPORTANT]
|
|
137
|
+
> Treat the concurrent path as an accelerator. Keep a single-stream fallback and
|
|
138
|
+
> branch on `outcome`: `fallbackTransient` keeps its segments and can be retried
|
|
139
|
+
> on the concurrent path; `fallbackPermanent` discards them and must restart
|
|
140
|
+
> through the caller's own downloader.
|
|
141
|
+
|
|
142
|
+
> [!WARNING]
|
|
143
|
+
> All consumers share one listener registry. Filter events by `channel` (and
|
|
144
|
+
> usually `taskId`), and always remove the listener when done.
|
|
145
|
+
|
|
146
|
+
> [!NOTE]
|
|
147
|
+
> `authExpired` and `notFound` are permanent for the URL used. Fetch a fresh
|
|
148
|
+
> signed URL before retrying instead of re-running the same request.
|
|
149
|
+
|
|
150
|
+
## References
|
|
151
|
+
|
|
152
|
+
- [OCDS standard](SPEC.md)
|
|
153
|
+
- [Native contract](docs/SPEC.md)
|
|
154
|
+
- [Example page](../../example/react-native/pages/RangeDownloaderTestPage.tsx)
|
|
155
|
+
- [npm package](https://www.npmjs.com/package/@onekeyfe/react-native-range-downloader)
|
|
156
|
+
- [Changelog](../../CHANGELOG.md)
|
|
61
157
|
|
|
62
158
|
## License
|
|
63
159
|
|
|
64
|
-
MIT
|
|
65
|
-
|
|
66
|
-
---
|
|
67
|
-
|
|
68
|
-
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
|
160
|
+
MIT. See [LICENSE](LICENSE).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-range-downloader",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.8.0-10",
|
|
4
4
|
"description": "react-native-range-downloader",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -89,6 +89,7 @@
|
|
|
89
89
|
"typescript": "^5.9.2"
|
|
90
90
|
},
|
|
91
91
|
"peerDependencies": {
|
|
92
|
+
"@onekeyfe/react-native-native-logger": "*",
|
|
92
93
|
"react": "*",
|
|
93
94
|
"react-native": "*",
|
|
94
95
|
"react-native-nitro-modules": "0.37.0"
|