@hxa-rn/rn-fetch-blob 0.12.0
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/LICENSE +21 -0
- package/README.md +290 -0
- package/harmony/fetch_blob/LICENSE +21 -0
- package/harmony/fetch_blob/NOTICE +33 -0
- package/harmony/fetch_blob/OAT.xml +38 -0
- package/harmony/fetch_blob/build-profile.json5 +16 -0
- package/harmony/fetch_blob/hvigorfile.ts +2 -0
- package/harmony/fetch_blob/index.ets +1 -0
- package/harmony/fetch_blob/oh-package.json5 +14 -0
- package/harmony/fetch_blob/src/main/cpp/CMakeLists.txt +15 -0
- package/harmony/fetch_blob/src/main/cpp/FetchBlobPackage.h +13 -0
- package/harmony/fetch_blob/src/main/cpp/generated/RNOH/generated/BaseFetchBlobPackage.h +72 -0
- package/harmony/fetch_blob/src/main/cpp/generated/RNOH/generated/turbo_modules/RNFetchBlob.cpp +55 -0
- package/harmony/fetch_blob/src/main/cpp/generated/RNOH/generated/turbo_modules/RNFetchBlob.h +16 -0
- package/harmony/fetch_blob/src/main/ets/FetchBlobTurboModulesFactory.ets +18 -0
- package/harmony/fetch_blob/src/main/ets/Logger.ts +40 -0
- package/harmony/fetch_blob/src/main/ets/RNFetchBlobConfig.ts +45 -0
- package/harmony/fetch_blob/src/main/ets/RNFetchBlobFS.ts +673 -0
- package/harmony/fetch_blob/src/main/ets/RNFetchBlobImpl.ts +246 -0
- package/harmony/fetch_blob/src/main/ets/RNFetchBlobReq.ts +530 -0
- package/harmony/fetch_blob/src/main/ets/RNFetchBlobStream.ts +169 -0
- package/harmony/fetch_blob/src/main/ets/RNFetchBlobTurboModule.ts +192 -0
- package/harmony/fetch_blob/src/main/ets/generated/index.ets +5 -0
- package/harmony/fetch_blob/src/main/ets/generated/ts.ts +5 -0
- package/harmony/fetch_blob/src/main/ets/generated/turboModules/RNFetchBlob.ts +92 -0
- package/harmony/fetch_blob/src/main/ets/generated/turboModules/ts.ts +5 -0
- package/harmony/fetch_blob/src/main/module.json5 +22 -0
- package/harmony/fetch_blob/src/main/resources/base/element/string.json +8 -0
- package/harmony/fetch_blob/src/main/resources/en_US/element/string.json +8 -0
- package/harmony/fetch_blob/src/main/resources/zh_CN/element/string.json +8 -0
- package/harmony/fetch_blob.har +0 -0
- package/package.json +59 -0
- package/src/android.js +62 -0
- package/src/class/RNFetchBlobFile.js +17 -0
- package/src/class/RNFetchBlobReadStream.js +82 -0
- package/src/class/RNFetchBlobSession.js +74 -0
- package/src/class/RNFetchBlobWriteStream.js +57 -0
- package/src/class/StatefulPromise.js +7 -0
- package/src/fs.js +432 -0
- package/src/index.d.ts +690 -0
- package/src/index.js +577 -0
- package/src/ios.js +54 -0
- package/src/json-stream.js +45 -0
- package/src/lib/oboe-browser.min.js +1 -0
- package/src/polyfill/Blob.js +362 -0
- package/src/polyfill/Event.js +11 -0
- package/src/polyfill/EventTarget.js +79 -0
- package/src/polyfill/Fetch.js +213 -0
- package/src/polyfill/File.js +27 -0
- package/src/polyfill/FileReader.js +90 -0
- package/src/polyfill/ProgressEvent.js +32 -0
- package/src/polyfill/XMLHttpRequest.js +446 -0
- package/src/polyfill/XMLHttpRequestEventTarget.js +118 -0
- package/src/polyfill/index.js +11 -0
- package/src/specs/v1/NativeRNFetchBlob.ts +85 -0
- package/src/types.js +64 -0
- package/src/utils/log.js +40 -0
- package/src/utils/unicode.js +7 -0
- package/src/utils/uri.js +28 -0
- package/src/utils/uuid.js +4 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2026. All rights reserved.
|
|
3
|
+
* HarmonyOS adaptation of rn-fetch-blob (RNFetchBlob TurboModule).
|
|
4
|
+
*
|
|
5
|
+
* Orchestration layer: owns the task map (taskId -> Req) and delegates to the
|
|
6
|
+
* FS / Stream / Req modules. Android/iOS-only APIs are mapped to the closest
|
|
7
|
+
* HarmonyOS capability or rejected with 'not supported'.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import common from '@ohos.app.ability.common';
|
|
11
|
+
import { BusinessError } from '@ohos.base';
|
|
12
|
+
import { picker } from '@kit.CoreFileKit';
|
|
13
|
+
import { UITurboModuleContext } from '@rnoh/react-native-openharmony/ts';
|
|
14
|
+
import RNFetchBlobFS from './RNFetchBlobFS';
|
|
15
|
+
import RNFetchBlobReq, { FormData, ReqCallback } from './RNFetchBlobReq';
|
|
16
|
+
import RNFetchBlobStream from './RNFetchBlobStream';
|
|
17
|
+
import { RNFetchBlobConfig } from './RNFetchBlobConfig';
|
|
18
|
+
import hilog from '@ohos.hilog';
|
|
19
|
+
|
|
20
|
+
const DOMAIN: number = 0xFF00;
|
|
21
|
+
const TAG: string = 'RNFetchBlob';
|
|
22
|
+
|
|
23
|
+
export type SimpleCallback = (err: string | null) => void;
|
|
24
|
+
export type DataCallback = (err: string | null, data?: Object | null) => void;
|
|
25
|
+
export type ExistsCallback = (value: boolean, isDir?: boolean) => void;
|
|
26
|
+
export type WriteStreamCallback = (errCode: string | null, errMsg: string | null, streamId?: string) => void;
|
|
27
|
+
export type CancelCallback = (value: Object[]) => void;
|
|
28
|
+
|
|
29
|
+
export default class RNFetchBlobImpl {
|
|
30
|
+
private context: common.UIAbilityContext;
|
|
31
|
+
private ctx: UITurboModuleContext;
|
|
32
|
+
private fs: RNFetchBlobFS;
|
|
33
|
+
private stream: RNFetchBlobStream;
|
|
34
|
+
private taskMap: Map<string, RNFetchBlobReq> = new Map();
|
|
35
|
+
|
|
36
|
+
constructor(context: common.UIAbilityContext, ctx: UITurboModuleContext) {
|
|
37
|
+
this.context = context;
|
|
38
|
+
this.ctx = ctx;
|
|
39
|
+
this.fs = new RNFetchBlobFS(context);
|
|
40
|
+
this.stream = new RNFetchBlobStream(ctx);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
getSystemFolders(): Object {
|
|
44
|
+
return this.fs.getSystemFolders();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fetchBlob(options: RNFetchBlobConfig, taskId: string, method: string, url: string, headers: Object,
|
|
48
|
+
form: FormData, callback: ReqCallback): void {
|
|
49
|
+
let req = new RNFetchBlobReq(this.ctx, this.context);
|
|
50
|
+
this.taskMap.set(taskId, req);
|
|
51
|
+
req.startHttp(options, taskId, method, url, headers, form, callback);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
fetchBlobForm(options: RNFetchBlobConfig, taskId: string, method: string, url: string, headers: Object,
|
|
55
|
+
form: FormData, callback: ReqCallback): void {
|
|
56
|
+
this.fetchBlob(options, taskId, method, url, headers, form, callback);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
cancelRequest(taskId: string, callback: CancelCallback): void {
|
|
60
|
+
let req = this.taskMap.get(taskId);
|
|
61
|
+
if (req) {
|
|
62
|
+
req.cancelRequest();
|
|
63
|
+
this.taskMap.delete(taskId);
|
|
64
|
+
}
|
|
65
|
+
callback([]);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
enableProgressReport(taskId: string, interval: number, count: number): void {
|
|
69
|
+
let req = this.taskMap.get(taskId);
|
|
70
|
+
if (req) {
|
|
71
|
+
req.onProgressReport(interval, count);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
enableUploadProgressReport(taskId: string, interval: number, count: number): void {
|
|
76
|
+
let req = this.taskMap.get(taskId);
|
|
77
|
+
if (req) {
|
|
78
|
+
req.onUploadProgressReport(interval, count);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
removeSession(paths: string[], callback: SimpleCallback): void {
|
|
83
|
+
this.fs.removeSession(paths, callback);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
createFile(path: string, data: string, encoding: string): Promise<string> {
|
|
87
|
+
return this.fs.createFile(path, data, encoding);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
createFileASCII(path: string, data: number[]): Promise<void> {
|
|
91
|
+
return this.fs.createFileASCII(path, data);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
writeFile(path: string, encoding: string, data: string, append: boolean): Promise<number> {
|
|
95
|
+
return this.fs.writeFile(path, encoding, data, append);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
writeFileArray(path: string, data: number[], append: boolean): Promise<number> {
|
|
99
|
+
return this.fs.writeFileArray(path, data, append);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
readFile(path: string, encoding: string): Promise<Object> {
|
|
103
|
+
return this.fs.readFile(path, encoding);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
unlink(path: string, callback: SimpleCallback): void {
|
|
107
|
+
this.fs.unlink(path, callback);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
mkdir(path: string): Promise<void> {
|
|
111
|
+
return this.fs.mkdir(path);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
exists(path: string, callback: ExistsCallback): void {
|
|
115
|
+
this.fs.exists(path, callback);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
cp(path: string, dest: string, callback: DataCallback): void {
|
|
119
|
+
this.fs.cp(path, dest, callback);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
mv(path: string, dest: string, callback: DataCallback): void {
|
|
123
|
+
this.fs.mv(path, dest, callback);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
ls(path: string): Promise<string[]> {
|
|
127
|
+
return this.fs.ls(path);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
stat(path: string, callback: DataCallback): void {
|
|
131
|
+
this.fs.stat(path, callback);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
lstat(path: string, callback: DataCallback): void {
|
|
135
|
+
this.fs.lstat(path, callback);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
hash(path: string, algorithm: string): Promise<string> {
|
|
139
|
+
return this.fs.hash(path, algorithm);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
slice(src: string, dest: string, start: number, end: number): Promise<string> {
|
|
143
|
+
return this.fs.slice(src, dest, start, end);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
df(callback: DataCallback): void {
|
|
147
|
+
this.fs.df(callback);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
writeStream(path: string, encoding: string, append: boolean, callback: WriteStreamCallback): void {
|
|
151
|
+
this.stream.writeStream(path, encoding, append, callback);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
readStream(filePath: string, encoding: string, bufferSize: number, tick: number, streamId: string): void {
|
|
155
|
+
this.stream.readStream(filePath, encoding, bufferSize, tick, streamId);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
writeChunk(streamId: string, data: string, callback: SimpleCallback): void {
|
|
159
|
+
this.stream.writeChunk(streamId, data, callback);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
writeArrayChunk(streamId: string, data: number[], callback: SimpleCallback): void {
|
|
163
|
+
this.stream.writeArrayChunk(streamId, data, callback);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
closeStream(streamId: string, callback: SimpleCallback): void {
|
|
167
|
+
this.stream.close(streamId, callback);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// ---- Android-only APIs, mapped or degraded on HarmonyOS ----
|
|
171
|
+
|
|
172
|
+
actionViewIntent(path: string, mime: string): Promise<void> {
|
|
173
|
+
return this.fs.presentPreview(path).then(() => {
|
|
174
|
+
return Promise.resolve();
|
|
175
|
+
}).catch((err: Object) => {
|
|
176
|
+
return Promise.reject(err);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
getContentIntent(mime: string): Promise<string> {
|
|
181
|
+
return new Promise((resolve, reject) => {
|
|
182
|
+
try {
|
|
183
|
+
let documentViewPicker = new picker.DocumentViewPicker(this.context);
|
|
184
|
+
let options = new picker.DocumentSelectOptions();
|
|
185
|
+
documentViewPicker.select(options).then((uris: string[]) => {
|
|
186
|
+
if (uris.length > 0) {
|
|
187
|
+
resolve(uris[0]);
|
|
188
|
+
} else {
|
|
189
|
+
reject('user canceled file selection');
|
|
190
|
+
}
|
|
191
|
+
}).catch((err: BusinessError) => {
|
|
192
|
+
hilog.error(DOMAIN, TAG, '%{public}s', `getContentIntent select failed: ${err.message}`);
|
|
193
|
+
reject(`getContentIntent failed: ${err.message}`);
|
|
194
|
+
});
|
|
195
|
+
} catch (err) {
|
|
196
|
+
hilog.error(DOMAIN, TAG, '%{public}s', 'getContentIntent is not supported on HarmonyOS');
|
|
197
|
+
reject('getContentIntent is not supported on HarmonyOS');
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
addCompleteDownload(config: Object): Promise<void> {
|
|
203
|
+
// HarmonyOS has no DownloadManager.addCompletedDownload equivalent.
|
|
204
|
+
return Promise.reject('addCompleteDownload is not supported on HarmonyOS');
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
getSDCardDir(): Promise<string> {
|
|
208
|
+
// HarmonyOS sandbox has no external SD card concept; return app filesDir.
|
|
209
|
+
return Promise.resolve(this.context.filesDir);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
getSDCardApplicationDir(): Promise<string> {
|
|
213
|
+
return Promise.resolve(this.context.filesDir);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
scanFile(pairs: Object[], callback: SimpleCallback): void {
|
|
217
|
+
// Baseline: not supported (would require ohos.permission.WRITE_IMAGEVIDEO user_grant).
|
|
218
|
+
callback('scanFile is not supported on HarmonyOS');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// ---- iOS-only APIs, rejected on HarmonyOS ----
|
|
222
|
+
|
|
223
|
+
pathForAppGroup(groupName: string): Promise<string> {
|
|
224
|
+
return Promise.reject('pathForAppGroup is not supported on HarmonyOS');
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
syncPathAppGroup(groupName: string): string {
|
|
228
|
+
return '';
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
previewDocument(uri: string, scheme: string): Promise<void> {
|
|
232
|
+
return Promise.reject('previewDocument is not supported on HarmonyOS');
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
openDocument(uri: string, scheme: string): Promise<void> {
|
|
236
|
+
return Promise.reject('openDocument is not supported on HarmonyOS');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
excludeFromBackupKey(url: string): Promise<void> {
|
|
240
|
+
return Promise.reject('excludeFromBackupKey is not supported on HarmonyOS');
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
emitExpiredEvent(callback: () => void): void {
|
|
244
|
+
// Only used on iOS via AppState listener; no-op on HarmonyOS.
|
|
245
|
+
}
|
|
246
|
+
}
|