@onekeyfe/react-native-range-downloader 6.7.0-alpha.475 → 6.8.0-3

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.
Files changed (2) hide show
  1. package/README.md +131 -39
  2. package/package.json +2 -1
package/README.md CHANGED
@@ -1,68 +1,160 @@
1
- # react-native-range-downloader
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
+ [![npm](https://img.shields.io/npm/v/%40onekeyfe%2Freact-native-range-downloader?label=npm&color=4D6BFE)](https://www.npmjs.com/package/@onekeyfe/react-native-range-downloader)
8
+ [![license](https://img.shields.io/npm/l/%40onekeyfe%2Freact-native-range-downloader?label=license&color=4D6BFE)](LICENSE)
9
+ ![iOS](https://img.shields.io/badge/iOS-000000?logo=apple&logoColor=white)
10
+ ![Android](https://img.shields.io/badge/Android-3DDC84?logo=android&logoColor=white)
11
+ ![Nitro Modules](https://img.shields.io/badge/Nitro_Modules-4D6BFE)
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
- npm install @onekeyfe/react-native-range-downloader react-native-nitro-modules
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
- > `react-native-nitro-modules` is required as this library relies on [Nitro Modules](https://nitro.margelo.com/).
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 === 'chart' && event.taskId === taskId) {
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: 'chart',
82
+ channel: RangeDownloadChannel.Bundle,
32
83
  taskId,
33
- url: 'https://example.com/chart-assets.zip',
84
+ url: 'https://example.com/bundle.zip',
34
85
  destFilePath,
35
86
  });
36
- console.log(result.outcome, result.filePath, result.fallbackReason);
87
+ console.log(result.outcome, result.fallbackKind, result.fallbackReason);
37
88
  } finally {
38
89
  ReactNativeRangeDownloader.removeDownloadListener(listenerId);
39
90
  }
40
91
  ```
41
92
 
42
- ## Specification
43
-
44
- The behavior of the concurrent downloader is governed by a normative,
45
- platform-agnostic standard that **all** implementations (iOS, Android, Desktop,
46
- and any future platform) MUST conform to:
47
-
48
- **→ [OneKey Concurrent Download Standard (OCDS)](https://github.com/OneKeyHQ/app-modules/blob/main/native-modules/react-native-range-downloader/SPEC.md)**
49
-
50
- Any change to download behavior on any platform must be checked against OCDS.
51
- When an implementation and the standard disagree, the implementation is wrong.
52
-
53
- How each platform (Node / Android / iOS) is verified against OCDS — and the
54
- runnable verification code to re-run after any downloader change — lives in
55
- **→ [`conformance/`](https://github.com/OneKeyHQ/app-modules/blob/main/native-modules/react-native-range-downloader/conformance/README.md)**.
56
-
57
- ## Contributing
58
-
59
- Follow the repository's
60
- [native development workflow](https://github.com/OneKeyHQ/app-modules/blob/main/docs/NATIVE_MODULE_DEVELOPMENT.md).
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.7.0-alpha.475",
3
+ "version": "6.8.0-3",
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"