react-native-blob-util 0.14.1 → 0.16.1
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 +101 -1
- package/android/src/main/AndroidManifest.xml +0 -3
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtil.java +7 -7
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilBody.java +30 -6
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilConfig.java +2 -0
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java +25 -2
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFileTransformer.java +10 -0
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilMediaCollection.java +20 -5
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java +100 -1
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilUtils.java +5 -17
- package/android/src/main/java/com/ReactNativeBlobUtil/Response/ReactNativeBlobUtilFileResp.java +4 -0
- package/class/ReactNativeBlobUtilBlobResponse.js +1 -1
- package/fs.js +42 -3
- package/index.d.ts +30 -1
- package/index.js +2 -2
- package/ios/ReactNativeBlobUtil/ReactNativeBlobUtil.m +4 -3
- package/ios/ReactNativeBlobUtil.xcodeproj/project.pbxproj +6 -2
- package/ios/ReactNativeBlobUtilConst.h +1 -0
- package/ios/ReactNativeBlobUtilConst.m +1 -0
- package/ios/ReactNativeBlobUtilFS.h +2 -1
- package/ios/ReactNativeBlobUtilFS.m +30 -2
- package/ios/ReactNativeBlobUtilFileTransformer.h +24 -0
- package/ios/ReactNativeBlobUtilFileTransformer.m +21 -0
- package/ios/ReactNativeBlobUtilReqBuilder.m +3 -4
- package/ios/ReactNativeBlobUtilRequest.m +35 -7
- package/mediacollection.js +6 -1
- package/package.json +7 -2
- package/polyfill/Fetch.js +4 -2
- package/polyfill/XMLHttpRequest.js +6 -0
- package/types.js +1 -0
- package/ios/IOS7Polyfill.h +0 -27
- package/react-native.config.js +0 -7
- package/scripts/prelink.js +0 -71
package/android/src/main/java/com/ReactNativeBlobUtil/Response/ReactNativeBlobUtilFileResp.java
CHANGED
|
@@ -72,6 +72,10 @@ public class ReactNativeBlobUtilFileResp extends ResponseBody {
|
|
|
72
72
|
|
|
73
73
|
@Override
|
|
74
74
|
public long contentLength() {
|
|
75
|
+
if (originalBody.contentLength() > Integer.MAX_VALUE) {
|
|
76
|
+
// This is a workaround for a bug Okio buffer where it can't handle larger than int.
|
|
77
|
+
return Integer.MAX_VALUE;
|
|
78
|
+
}
|
|
75
79
|
return originalBody.contentLength();
|
|
76
80
|
}
|
|
77
81
|
|
package/fs.js
CHANGED
|
@@ -160,7 +160,20 @@ function readFile(path: string, encoding: string = 'utf8'): Promise<any> {
|
|
|
160
160
|
if (typeof path !== 'string') {
|
|
161
161
|
return Promise.reject(addCode('EINVAL', new TypeError('Missing argument "path" ')));
|
|
162
162
|
}
|
|
163
|
-
return ReactNativeBlobUtil.readFile(path, encoding);
|
|
163
|
+
return ReactNativeBlobUtil.readFile(path, encoding, false);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Reads the file, then transforms it before returning the content
|
|
168
|
+
* @param {string} path Path of the file.
|
|
169
|
+
* @param {'base64' | 'utf8' | 'ascii'} encoding Encoding of read stream.
|
|
170
|
+
* @return {Promise<Array<number> | string>}
|
|
171
|
+
*/
|
|
172
|
+
function readFileWithTransform(path: string, encoding: string = 'utf8'): Promise<any> {
|
|
173
|
+
if (typeof path !== 'string') {
|
|
174
|
+
return Promise.reject(addCode('EINVAL', new TypeError('Missing argument "path" ')))
|
|
175
|
+
}
|
|
176
|
+
return ReactNativeBlobUtil.readFile(path, encoding, true);
|
|
164
177
|
}
|
|
165
178
|
|
|
166
179
|
/**
|
|
@@ -186,7 +199,31 @@ function writeFile(path: string, data: string | Array<number>, encoding: ?string
|
|
|
186
199
|
return Promise.reject(addCode('EINVAL', new TypeError(`"data" must be a String when encoding is "utf8" or "base64", but it is "${typeof data}"`)));
|
|
187
200
|
}
|
|
188
201
|
else
|
|
189
|
-
return ReactNativeBlobUtil.writeFile(path, encoding, data, false);
|
|
202
|
+
return ReactNativeBlobUtil.writeFile(path, encoding, data, false, false);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Transforms the data and then writes to the file.
|
|
208
|
+
* @param {string} path Path of the file.
|
|
209
|
+
* @param {string | number[]} data Data to write to the file.
|
|
210
|
+
* @param {string} encoding Encoding of data (Optional).
|
|
211
|
+
* @return {Promise}
|
|
212
|
+
*/
|
|
213
|
+
function writeFileWithTransform(path: string, data: string | Array<number>, encoding: ?string = 'utf8'): Promise {
|
|
214
|
+
if (typeof path !== 'string') {
|
|
215
|
+
return Promise.reject(addCode('EINVAL', new TypeError('Missing argument "path" ')))
|
|
216
|
+
}
|
|
217
|
+
if (encoding.toLocaleLowerCase() === 'ascii') {
|
|
218
|
+
return Promise.reject(addCode('EINVAL', new TypeError('ascii is not supported for converted files')))
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
if (typeof data !== 'string') {
|
|
222
|
+
return Promise.reject(addCode('EINVAL', new TypeError(`"data" must be a String when encoding is "utf8" or "base64", but it is "${typeof data}"`)))
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
else
|
|
226
|
+
return ReactNativeBlobUtil.writeFile(path, encoding, data, true, false)
|
|
190
227
|
}
|
|
191
228
|
}
|
|
192
229
|
|
|
@@ -206,7 +243,7 @@ function appendFile(path: string, data: string | Array<number>, encoding?: strin
|
|
|
206
243
|
return Promise.reject(addCode('EINVAL'), new TypeError(`"data" must be a String when encoding is "utf8" or "base64", but it is "${typeof data}"`));
|
|
207
244
|
}
|
|
208
245
|
else
|
|
209
|
-
return ReactNativeBlobUtil.writeFile(path, encoding, data, true);
|
|
246
|
+
return ReactNativeBlobUtil.writeFile(path, encoding, data, false, true);
|
|
210
247
|
}
|
|
211
248
|
}
|
|
212
249
|
|
|
@@ -415,6 +452,8 @@ export default {
|
|
|
415
452
|
cp,
|
|
416
453
|
writeStream,
|
|
417
454
|
writeFile,
|
|
455
|
+
writeFileWithTransform,
|
|
456
|
+
readFileWithTransform,
|
|
418
457
|
appendFile,
|
|
419
458
|
pathForAppGroup,
|
|
420
459
|
syncPathAppGroup,
|
package/index.d.ts
CHANGED
|
@@ -399,6 +399,14 @@ export interface FS {
|
|
|
399
399
|
*/
|
|
400
400
|
writeFile(path: string, data: string | number[], encoding?: Encoding): Promise<void>;
|
|
401
401
|
|
|
402
|
+
/**
|
|
403
|
+
* Processes the data and then writes to the file.
|
|
404
|
+
* @param path Path of the file.
|
|
405
|
+
* @param data Data to write to the file.
|
|
406
|
+
* @param encoding Encoding of data (Optional).
|
|
407
|
+
*/
|
|
408
|
+
writeFileWithTransform(path: string, data: string | number[], encoding?: Encoding): Promise<void>;
|
|
409
|
+
|
|
402
410
|
appendFile(path: string, data: string | number[], encoding?: Encoding | "uri"): Promise<number>;
|
|
403
411
|
|
|
404
412
|
/**
|
|
@@ -408,6 +416,13 @@ export interface FS {
|
|
|
408
416
|
*/
|
|
409
417
|
readFile(path: string, encoding: Encoding, bufferSize?: number): Promise<any>;
|
|
410
418
|
|
|
419
|
+
/**
|
|
420
|
+
* Reads from a file and then processes the data before returning
|
|
421
|
+
* @param path Path of the file.
|
|
422
|
+
* @param encoding Encoding of read stream.
|
|
423
|
+
*/
|
|
424
|
+
readFileWithTransform(path: string, encoding: Encoding, bufferSize?: number): Promise<any>;
|
|
425
|
+
|
|
411
426
|
/**
|
|
412
427
|
* Check if file exists and if it is a folder.
|
|
413
428
|
* @param path Path to check
|
|
@@ -475,7 +490,7 @@ export interface ReactNativeBlobUtilWriteStream {
|
|
|
475
490
|
|
|
476
491
|
write(data: string): Promise<void>;
|
|
477
492
|
|
|
478
|
-
close(): void
|
|
493
|
+
close(): Promise<void>;
|
|
479
494
|
}
|
|
480
495
|
|
|
481
496
|
export interface ReactNativeBlobUtilReadStream {
|
|
@@ -698,6 +713,13 @@ export interface ReactNativeBlobUtilConfig {
|
|
|
698
713
|
*/
|
|
699
714
|
fileCache?: boolean;
|
|
700
715
|
|
|
716
|
+
/**
|
|
717
|
+
* Set this property to true if you want the data to be processed before it gets written onto disk.
|
|
718
|
+
* This only has effect if the FileTransformer has been registered and the library is configured to write
|
|
719
|
+
* response onto disk.
|
|
720
|
+
*/
|
|
721
|
+
transformFile?: boolean;
|
|
722
|
+
|
|
701
723
|
/**
|
|
702
724
|
* Set this property to change temp file extension that created by fetch response data.
|
|
703
725
|
*/
|
|
@@ -808,6 +830,13 @@ export interface MediaCollection {
|
|
|
808
830
|
*/
|
|
809
831
|
writeToMediafile(uri: string, path: string): Promise<string>
|
|
810
832
|
|
|
833
|
+
/**
|
|
834
|
+
* Copies and transforms an existing file to a mediastore file. Make sure FileTransformer is set
|
|
835
|
+
* @param uri URI of the destination mediastore file
|
|
836
|
+
* @param path Path to the existing file which should be copied
|
|
837
|
+
*/
|
|
838
|
+
writeToMediafileWithTransform(uri: string, path: string): Promise<string>
|
|
839
|
+
|
|
811
840
|
/**
|
|
812
841
|
* Copies a file from the mediastore to the apps internal storage
|
|
813
842
|
* @param contenturi URI of the mediastore file
|
package/index.js
CHANGED
|
@@ -56,9 +56,9 @@ if (!ReactNativeBlobUtil || !ReactNativeBlobUtil.fetchBlobForm || !ReactNativeBl
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
export {ReactNativeBlobUtilConfig, ReactNativeBlobUtilResponseInfo, ReactNativeBlobUtilStream} from './types';
|
|
59
|
-
export URIUtil from './utils/uri';
|
|
59
|
+
export { URIUtil } from './utils/uri';
|
|
60
60
|
export {FetchBlobResponse} from './class/ReactNativeBlobUtilBlobResponse';
|
|
61
|
-
export getUUID from './utils/uuid';
|
|
61
|
+
export { getUUID } from './utils/uuid';
|
|
62
62
|
export default {
|
|
63
63
|
fetch,
|
|
64
64
|
base64,
|
|
@@ -252,9 +252,9 @@ RCT_EXPORT_METHOD(exists:(NSString *)path callback:(RCTResponseSenderBlock)callb
|
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
#pragma mark - fs.writeFile
|
|
255
|
-
RCT_EXPORT_METHOD(writeFile:(NSString *)path encoding:(NSString *)encoding data:(NSString *)data append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
255
|
+
RCT_EXPORT_METHOD(writeFile:(NSString *)path encoding:(NSString *)encoding data:(NSString *)data transformFile:(BOOL)transformFile append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
256
256
|
{
|
|
257
|
-
[ReactNativeBlobUtilFS writeFile:path encoding:[NSString stringWithString:encoding] data:data append:append resolver:resolve rejecter:reject];
|
|
257
|
+
[ReactNativeBlobUtilFS writeFile:path encoding:[NSString stringWithString:encoding] data:data transformFile:transformFile append:append resolver:resolve rejecter:reject];
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
#pragma mark - fs.writeArray
|
|
@@ -494,11 +494,12 @@ RCT_EXPORT_METHOD(mkdir:(NSString *)path resolver:(RCTPromiseResolveBlock)resolv
|
|
|
494
494
|
#pragma mark - fs.readFile
|
|
495
495
|
RCT_EXPORT_METHOD(readFile:(NSString *)path
|
|
496
496
|
encoding:(NSString *)encoding
|
|
497
|
+
transformFile:(BOOL) transformFile
|
|
497
498
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
498
499
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
499
500
|
{
|
|
500
501
|
|
|
501
|
-
[ReactNativeBlobUtilFS readFile:path encoding:encoding onComplete:^(NSData * content, NSString * code, NSString * err) {
|
|
502
|
+
[ReactNativeBlobUtilFS readFile:path encoding:encoding transformFile:transformFile onComplete:^(NSData * content, NSString * code, NSString * err) {
|
|
502
503
|
if(err != nil) {
|
|
503
504
|
reject(code, err, nil);
|
|
504
505
|
return;
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
/* Begin PBXBuildFile section */
|
|
10
10
|
8C4801A6200CF71700FED7ED /* ReactNativeBlobUtilRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C4801A5200CF71700FED7ED /* ReactNativeBlobUtilRequest.m */; };
|
|
11
|
+
9FD8D3C326F1736000009F35 /* ReactNativeBlobUtilFileTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FD8D3C226F1736000009F35 /* ReactNativeBlobUtilFileTransformer.m */; };
|
|
11
12
|
A158F4271D052E49006FFD38 /* ReactNativeBlobUtilFS.m in Sources */ = {isa = PBXBuildFile; fileRef = A158F4261D052E49006FFD38 /* ReactNativeBlobUtilFS.m */; };
|
|
12
13
|
A158F42D1D0535BB006FFD38 /* ReactNativeBlobUtilConst.m in Sources */ = {isa = PBXBuildFile; fileRef = A158F42C1D0535BB006FFD38 /* ReactNativeBlobUtilConst.m */; };
|
|
13
14
|
A158F4301D0539DB006FFD38 /* ReactNativeBlobUtilNetwork.m in Sources */ = {isa = PBXBuildFile; fileRef = A158F42F1D0539DB006FFD38 /* ReactNativeBlobUtilNetwork.m */; };
|
|
@@ -32,6 +33,8 @@
|
|
|
32
33
|
/* Begin PBXFileReference section */
|
|
33
34
|
8C4801A4200CF71700FED7ED /* ReactNativeBlobUtilRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ReactNativeBlobUtilRequest.h; sourceTree = "<group>"; };
|
|
34
35
|
8C4801A5200CF71700FED7ED /* ReactNativeBlobUtilRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ReactNativeBlobUtilRequest.m; sourceTree = "<group>"; };
|
|
36
|
+
9FD8D3C126F1709A00009F35 /* ReactNativeBlobUtilFileTransformer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ReactNativeBlobUtilFileTransformer.h; sourceTree = "<group>"; };
|
|
37
|
+
9FD8D3C226F1736000009F35 /* ReactNativeBlobUtilFileTransformer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ReactNativeBlobUtilFileTransformer.m; sourceTree = "<group>"; };
|
|
35
38
|
A158F4261D052E49006FFD38 /* ReactNativeBlobUtilFS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReactNativeBlobUtilFS.m; sourceTree = "<group>"; };
|
|
36
39
|
A158F4281D052E57006FFD38 /* ReactNativeBlobUtilFS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ReactNativeBlobUtilFS.h; sourceTree = "<group>"; };
|
|
37
40
|
A158F4291D0534A9006FFD38 /* ReactNativeBlobUtilConst.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ReactNativeBlobUtilConst.h; sourceTree = "<group>"; };
|
|
@@ -45,7 +48,6 @@
|
|
|
45
48
|
A19B48241D98102400E6868A /* ReactNativeBlobUtilProgress.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReactNativeBlobUtilProgress.m; sourceTree = "<group>"; };
|
|
46
49
|
A1AAE2971D300E3E0051D11C /* ReactNativeBlobUtilReqBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ReactNativeBlobUtilReqBuilder.h; sourceTree = "<group>"; };
|
|
47
50
|
A1AAE2981D300E4D0051D11C /* ReactNativeBlobUtilReqBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReactNativeBlobUtilReqBuilder.m; sourceTree = "<group>"; };
|
|
48
|
-
A1F950181D7E9134002A95A6 /* IOS7Polyfill.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IOS7Polyfill.h; sourceTree = "<group>"; };
|
|
49
51
|
/* End PBXFileReference section */
|
|
50
52
|
|
|
51
53
|
/* Begin PBXFrameworksBuildPhase section */
|
|
@@ -69,9 +71,10 @@
|
|
|
69
71
|
A15C30051CD25C330074CB35 = {
|
|
70
72
|
isa = PBXGroup;
|
|
71
73
|
children = (
|
|
74
|
+
9FD8D3C226F1736000009F35 /* ReactNativeBlobUtilFileTransformer.m */,
|
|
75
|
+
9FD8D3C126F1709A00009F35 /* ReactNativeBlobUtilFileTransformer.h */,
|
|
72
76
|
A19B48241D98102400E6868A /* ReactNativeBlobUtilProgress.m */,
|
|
73
77
|
A19B48231D98100800E6868A /* ReactNativeBlobUtilProgress.h */,
|
|
74
|
-
A1F950181D7E9134002A95A6 /* IOS7Polyfill.h */,
|
|
75
78
|
A1AAE2981D300E4D0051D11C /* ReactNativeBlobUtilReqBuilder.m */,
|
|
76
79
|
A1AAE2971D300E3E0051D11C /* ReactNativeBlobUtilReqBuilder.h */,
|
|
77
80
|
A158F42E1D0539CE006FFD38 /* ReactNativeBlobUtilNetwork.h */,
|
|
@@ -156,6 +159,7 @@
|
|
|
156
159
|
A166D1AA1CE0647A00273590 /* ReactNativeBlobUtil.h in Sources */,
|
|
157
160
|
8C4801A6200CF71700FED7ED /* ReactNativeBlobUtilRequest.m in Sources */,
|
|
158
161
|
A158F42D1D0535BB006FFD38 /* ReactNativeBlobUtilConst.m in Sources */,
|
|
162
|
+
9FD8D3C326F1736000009F35 /* ReactNativeBlobUtilFileTransformer.m in Sources */,
|
|
159
163
|
A158F4271D052E49006FFD38 /* ReactNativeBlobUtilFS.m in Sources */,
|
|
160
164
|
A158F4301D0539DB006FFD38 /* ReactNativeBlobUtilNetwork.m in Sources */,
|
|
161
165
|
A19B48251D98102400E6868A /* ReactNativeBlobUtilProgress.m in Sources */,
|
|
@@ -29,6 +29,7 @@ extern NSString *const AL_PREFIX;
|
|
|
29
29
|
|
|
30
30
|
// config
|
|
31
31
|
extern NSString *const CONFIG_USE_TEMP;
|
|
32
|
+
extern NSString *const CONFIG_TRANSFORM_FILE;
|
|
32
33
|
extern NSString *const CONFIG_FILE_PATH;
|
|
33
34
|
extern NSString *const CONFIG_FILE_EXT;
|
|
34
35
|
extern NSString *const CONFIG_TRUSTY;
|
|
@@ -13,6 +13,7 @@ NSString *const AL_PREFIX = @"assets-library://";
|
|
|
13
13
|
|
|
14
14
|
// fetch configs
|
|
15
15
|
NSString *const CONFIG_USE_TEMP = @"fileCache";
|
|
16
|
+
NSString *const CONFIG_TRANSFORM_FILE = @"transformFile";
|
|
16
17
|
NSString *const CONFIG_FILE_PATH = @"path";
|
|
17
18
|
NSString *const CONFIG_FILE_EXT = @"appendExt";
|
|
18
19
|
NSString *const CONFIG_TRUSTY = @"trusty";
|
|
@@ -72,7 +72,8 @@
|
|
|
72
72
|
+ (NSDictionary *) stat:(NSString *) path error:(NSError **) error;
|
|
73
73
|
+ (void) exists:(NSString *) path callback:(RCTResponseSenderBlock)callback;
|
|
74
74
|
+ (void) writeFileArray:(NSString *)path data:(NSArray *)data append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
|
|
75
|
-
+ (void) writeFile:(NSString *)path encoding:(NSString *)encoding data:(NSString *)data append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
|
|
75
|
+
+ (void) writeFile:(NSString *)path encoding:(NSString *)encoding data:(NSString *)data transformFile:(BOOL)transformFile append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
|
|
76
|
+
+ (void) readFile:(NSString *)path encoding:(NSString *)encoding transformFile:(BOOL)transformFile onComplete:(void (^)(NSData * content, NSString* code, NSString * errMsg))onComplete;
|
|
76
77
|
+ (void) readFile:(NSString *)path encoding:(NSString *)encoding onComplete:(void (^)(NSData * content, NSString* code, NSString * errMsg))onComplete;
|
|
77
78
|
+ (void) readAssetFile:(NSData *)assetUrl completionBlock:(void(^)(NSData * content))completionBlock failBlock:(void(^)(NSError * err))failBlock;
|
|
78
79
|
+ (void) slice:(NSString *)path
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
#import "ReactNativeBlobUtil.h"
|
|
11
11
|
#import "ReactNativeBlobUtilFS.h"
|
|
12
12
|
#import "ReactNativeBlobUtilConst.h"
|
|
13
|
-
#import "
|
|
13
|
+
#import "ReactNativeBlobUtilFileTransformer.h"
|
|
14
14
|
@import AssetsLibrary;
|
|
15
15
|
|
|
16
16
|
#import <CommonCrypto/CommonDigest.h>
|
|
@@ -347,6 +347,7 @@ NSMutableDictionary *fileStreams = nil;
|
|
|
347
347
|
+ (void) writeFile:(NSString *)path
|
|
348
348
|
encoding:(NSString *)encoding
|
|
349
349
|
data:(NSString *)data
|
|
350
|
+
transformFile:(BOOL)transformFile
|
|
350
351
|
append:(BOOL)append
|
|
351
352
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
352
353
|
rejecter:(RCTPromiseRejectBlock)reject
|
|
@@ -379,7 +380,7 @@ NSMutableDictionary *fileStreams = nil;
|
|
|
379
380
|
|
|
380
381
|
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:path];
|
|
381
382
|
NSData * content = nil;
|
|
382
|
-
if([encoding
|
|
383
|
+
if([encoding containsString:@"base64"]) {
|
|
383
384
|
content = [[NSData alloc] initWithBase64EncodedString:data options:0];
|
|
384
385
|
}
|
|
385
386
|
else if([encoding isEqualToString:@"uri"]) {
|
|
@@ -394,6 +395,16 @@ NSMutableDictionary *fileStreams = nil;
|
|
|
394
395
|
else {
|
|
395
396
|
content = [data dataUsingEncoding:NSUTF8StringEncoding];
|
|
396
397
|
}
|
|
398
|
+
|
|
399
|
+
if (transformFile) {
|
|
400
|
+
NSObject<FileTransformer>* fileTransformer = [ReactNativeBlobUtilFileTransformer getFileTransformer];
|
|
401
|
+
if (fileTransformer) {
|
|
402
|
+
content = [fileTransformer onWriteFile:content];
|
|
403
|
+
} else {
|
|
404
|
+
return reject(@"EUNSPECIFIED",@"Transform specified but transformer not set", nil);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
397
408
|
if(append == YES) {
|
|
398
409
|
[fileHandle seekToEndOfFile];
|
|
399
410
|
[fileHandle writeData:content];
|
|
@@ -488,6 +499,7 @@ NSMutableDictionary *fileStreams = nil;
|
|
|
488
499
|
|
|
489
500
|
+ (void) readFile:(NSString *)path
|
|
490
501
|
encoding:(NSString *)encoding
|
|
502
|
+
transformFile:(BOOL) transformFile
|
|
491
503
|
onComplete:(void (^)(NSData * content, NSString * codeStr, NSString * errMsg))onComplete
|
|
492
504
|
{
|
|
493
505
|
[[self class] getPathFromUri:path completionHandler:^(NSString *path, ALAssetRepresentation *asset) {
|
|
@@ -522,6 +534,22 @@ NSMutableDictionary *fileStreams = nil;
|
|
|
522
534
|
|
|
523
535
|
}
|
|
524
536
|
|
|
537
|
+
if (transformFile) {
|
|
538
|
+
NSObject<FileTransformer>* fileTransformer = [ReactNativeBlobUtilFileTransformer getFileTransformer];
|
|
539
|
+
if (fileTransformer) {
|
|
540
|
+
@try{
|
|
541
|
+
fileContent = [fileTransformer onReadFile:fileContent];
|
|
542
|
+
} @catch (NSException * ex)
|
|
543
|
+
{
|
|
544
|
+
onComplete(nil, @"EUNSPECIFIED", [NSString stringWithFormat:@"Exception on File Transformer: '%@' ", [ex description]]);
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
} else {
|
|
548
|
+
onComplete(nil, @"EUNSPECIFIED", @"Transform specified but transformer not set");
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
525
553
|
if(encoding != nil)
|
|
526
554
|
{
|
|
527
555
|
if([[encoding lowercaseString] isEqualToString:@"utf8"])
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// ReactNativeBlobUtilFileTransformer.h
|
|
2
|
+
// ReactNativeBlobUtil
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#ifndef ReactNativeBlobUtilDataConverter_h
|
|
6
|
+
#define ReactNativeBlobUtilDataConverter_h
|
|
7
|
+
|
|
8
|
+
#import <UIKit/UIKit.h>
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@protocol FileTransformer <NSObject>
|
|
12
|
+
- (NSData*) onWriteFile:(NSData*)data;
|
|
13
|
+
- (NSData*) onReadFile:(NSData*)data;
|
|
14
|
+
@end
|
|
15
|
+
|
|
16
|
+
@interface ReactNativeBlobUtilFileTransformer : NSObject
|
|
17
|
+
|
|
18
|
+
+ (void) setFileTransformer:(NSObject<FileTransformer>*) fileTransformer;
|
|
19
|
+
+ (NSObject<FileTransformer>*) getFileTransformer;
|
|
20
|
+
|
|
21
|
+
@end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
#endif /* ReactNativeBlobUtilFileTransformer_h */
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// ReactNativeBlobUtilFileTransformer.m
|
|
2
|
+
// ReactNativeBlobUtil
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#import "ReactNativeBlobUtilFileTransformer.h"
|
|
6
|
+
|
|
7
|
+
static NSObject<FileTransformer> *sharedFileTransformer;
|
|
8
|
+
|
|
9
|
+
@implementation ReactNativeBlobUtilFileTransformer
|
|
10
|
+
|
|
11
|
+
+ (void) setFileTransformer:(NSObject<FileTransformer> *)fileTransformer {
|
|
12
|
+
sharedFileTransformer = fileTransformer;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
+ (NSObject<FileTransformer>*) getFileTransformer {
|
|
16
|
+
return sharedFileTransformer;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@end
|
|
20
|
+
|
|
21
|
+
// PHOENIX:PATCH-PACKAGE END
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
#import "ReactNativeBlobUtilNetwork.h"
|
|
12
12
|
#import "ReactNativeBlobUtilConst.h"
|
|
13
13
|
#import "ReactNativeBlobUtilFS.h"
|
|
14
|
-
#import "IOS7Polyfill.h"
|
|
15
14
|
|
|
16
15
|
#if __has_include(<React/RCTAssert.h>)
|
|
17
16
|
#import <React/RCTLog.h>
|
|
@@ -119,7 +118,7 @@
|
|
|
119
118
|
if([orgPath hasPrefix:AL_PREFIX])
|
|
120
119
|
{
|
|
121
120
|
|
|
122
|
-
[ReactNativeBlobUtilFS readFile:orgPath encoding:nil onComplete:^(id content, NSString* code, NSString * err) {
|
|
121
|
+
[ReactNativeBlobUtilFS readFile:orgPath encoding:nil transformFile:false onComplete:^(id content, NSString* code, NSString * err) {
|
|
123
122
|
if(err != nil)
|
|
124
123
|
{
|
|
125
124
|
onComplete(nil, nil);
|
|
@@ -151,7 +150,7 @@
|
|
|
151
150
|
|
|
152
151
|
__block NSString * cType = [[self class]getHeaderIgnoreCases:@"content-type" fromHeaders:mheaders];
|
|
153
152
|
// when content-type is application/octet* decode body string using BASE64 decoder
|
|
154
|
-
if([[cType lowercaseString] hasPrefix:@"application/octet"] || [[cType lowercaseString]
|
|
153
|
+
if([[cType lowercaseString] hasPrefix:@"application/octet"] || [[cType lowercaseString] containsString:@";base64"])
|
|
155
154
|
{
|
|
156
155
|
__block NSString * ncType = [[cType stringByReplacingOccurrencesOfString:@";base64" withString:@""]stringByReplacingOccurrencesOfString:@";BASE64" withString:@""];
|
|
157
156
|
if([mheaders valueForKey:@"content-type"] != nil)
|
|
@@ -223,7 +222,7 @@
|
|
|
223
222
|
NSString * orgPath = [content substringFromIndex:[FILE_PREFIX length]];
|
|
224
223
|
orgPath = [ReactNativeBlobUtilFS getPathOfAsset:orgPath];
|
|
225
224
|
|
|
226
|
-
[ReactNativeBlobUtilFS readFile:orgPath encoding:nil onComplete:^(NSData *content, NSString* code, NSString * err) {
|
|
225
|
+
[ReactNativeBlobUtilFS readFile:orgPath encoding:nil transformFile:false onComplete:^(NSData *content, NSString* code, NSString * err) {
|
|
227
226
|
if(err != nil)
|
|
228
227
|
{
|
|
229
228
|
onComplete(formData, YES);
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
|
|
11
11
|
#import "ReactNativeBlobUtilFS.h"
|
|
12
12
|
#import "ReactNativeBlobUtilConst.h"
|
|
13
|
+
#import "ReactNativeBlobUtilFileTransformer.h"
|
|
13
14
|
#import "ReactNativeBlobUtilReqBuilder.h"
|
|
14
15
|
|
|
15
|
-
#import "IOS7Polyfill.h"
|
|
16
16
|
#import <CommonCrypto/CommonDigest.h>
|
|
17
17
|
|
|
18
18
|
|
|
@@ -156,6 +156,12 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
|
|
|
156
156
|
} else {
|
|
157
157
|
destPath = [ReactNativeBlobUtilFS getTempPath:cacheKey withExtension:[self.options valueForKey:CONFIG_FILE_EXT]];
|
|
158
158
|
}
|
|
159
|
+
|
|
160
|
+
// We still need to initialize this as a placeholder in memory before we perform
|
|
161
|
+
// the conversion
|
|
162
|
+
if ([self ShouldTransformFile]) {
|
|
163
|
+
respData = [[NSMutableData alloc] init];
|
|
164
|
+
}
|
|
159
165
|
} else {
|
|
160
166
|
respData = [[NSMutableData alloc] init];
|
|
161
167
|
respFile = NO;
|
|
@@ -215,20 +221,20 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
|
|
|
215
221
|
|
|
216
222
|
return;
|
|
217
223
|
} else {
|
|
218
|
-
self.isServerPush = [[respCType lowercaseString]
|
|
224
|
+
self.isServerPush = [[respCType lowercaseString] containsString:@"multipart/x-mixed-replace;"];
|
|
219
225
|
}
|
|
220
226
|
|
|
221
227
|
if(respCType)
|
|
222
228
|
{
|
|
223
229
|
NSArray * extraBlobCTypes = [options objectForKey:CONFIG_EXTRA_BLOB_CTYPE];
|
|
224
230
|
|
|
225
|
-
if ([respCType
|
|
231
|
+
if ([respCType containsString:@"text/"]) {
|
|
226
232
|
respType = @"text";
|
|
227
|
-
} else if ([respCType
|
|
233
|
+
} else if ([respCType containsString:@"application/json"]) {
|
|
228
234
|
respType = @"json";
|
|
229
235
|
} else if(extraBlobCTypes) { // If extra blob content type is not empty, check if response type matches
|
|
230
236
|
for (NSString * substr in extraBlobCTypes) {
|
|
231
|
-
if ([respCType
|
|
237
|
+
if ([respCType containsString:[substr lowercaseString]]) {
|
|
232
238
|
respType = @"blob";
|
|
233
239
|
respFile = YES;
|
|
234
240
|
destPath = [ReactNativeBlobUtilFS getTempPath:taskId withExtension:nil];
|
|
@@ -286,7 +292,7 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
|
|
|
286
292
|
|
|
287
293
|
// if not set overwrite in options, defaults to TRUE
|
|
288
294
|
BOOL overwrite = [options valueForKey:@"overwrite"] == nil ? YES : [[options valueForKey:@"overwrite"] boolValue];
|
|
289
|
-
BOOL appendToExistingFile = [destPath
|
|
295
|
+
BOOL appendToExistingFile = [destPath containsString:@"?append=true"];
|
|
290
296
|
|
|
291
297
|
appendToExistingFile = !overwrite;
|
|
292
298
|
|
|
@@ -333,7 +339,9 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
|
|
|
333
339
|
chunkString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
|
334
340
|
}
|
|
335
341
|
|
|
336
|
-
|
|
342
|
+
// If we need to process the data, we defer writing into the file until the we have all the data, at which point
|
|
343
|
+
// we can perform the processing and then write into the file
|
|
344
|
+
if (respFile && ![self ShouldTransformFile]) {
|
|
337
345
|
[writeStream write:[data bytes] maxLength:[data length]];
|
|
338
346
|
} else {
|
|
339
347
|
[respData appendData:data];
|
|
@@ -390,6 +398,22 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
|
|
|
390
398
|
}
|
|
391
399
|
|
|
392
400
|
if (respFile) {
|
|
401
|
+
if ([self ShouldTransformFile]) {
|
|
402
|
+
// At this point, we have the data that we deferred to write into a file. We can now
|
|
403
|
+
// perform the conversion and write the converted data into the file.
|
|
404
|
+
NSObject<FileTransformer>* fileTransformer = [ReactNativeBlobUtilFileTransformer getFileTransformer];
|
|
405
|
+
if (!fileTransformer) {
|
|
406
|
+
errMsg = @"Transform file specified but file transfomer not set";
|
|
407
|
+
} else {
|
|
408
|
+
@try{
|
|
409
|
+
NSData* transformedData = [fileTransformer onWriteFile:respData];
|
|
410
|
+
[writeStream write:[transformedData bytes] maxLength:[transformedData length]];
|
|
411
|
+
} @catch(NSException * ex)
|
|
412
|
+
{
|
|
413
|
+
errMsg = [NSString stringWithFormat:@"Exception on File Transformer: '%@' ", [ex description]];
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
393
417
|
[writeStream close];
|
|
394
418
|
rnfbRespType = RESP_TYPE_PATH;
|
|
395
419
|
respStr = destPath;
|
|
@@ -430,6 +454,10 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
|
|
|
430
454
|
|
|
431
455
|
}
|
|
432
456
|
|
|
457
|
+
- (BOOL) ShouldTransformFile{
|
|
458
|
+
return [[options valueForKey:CONFIG_TRANSFORM_FILE] boolValue];
|
|
459
|
+
}
|
|
460
|
+
|
|
433
461
|
// upload progress handler
|
|
434
462
|
- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesWritten totalBytesExpectedToSend:(int64_t)totalBytesExpectedToWrite
|
|
435
463
|
{
|
package/mediacollection.js
CHANGED
|
@@ -9,7 +9,11 @@ function createMediafile(fd: filedescriptor, mediatype: string): Promise {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
function writeToMediafile(uri: string, path: string) {
|
|
12
|
-
return ReactNativeBlobUtil.writeToMediaFile(uri, path);
|
|
12
|
+
return ReactNativeBlobUtil.writeToMediaFile(uri, path, false);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function writeToMediafileWithTransform(uri: string, path: string) {
|
|
16
|
+
return ReactNativeBlobUtil.writeToMediaFile(uri, path, true);
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
function copyToInternal(contenturi: string, destpath: string) {
|
|
@@ -27,6 +31,7 @@ function copyToMediaStore(fd: filedescriptor, mediatype: string, path: string) {
|
|
|
27
31
|
export default {
|
|
28
32
|
createMediafile,
|
|
29
33
|
writeToMediafile,
|
|
34
|
+
writeToMediafileWithTransform,
|
|
30
35
|
copyToInternal,
|
|
31
36
|
getBlob,
|
|
32
37
|
copyToMediaStore
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-blob-util",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -35,11 +35,16 @@
|
|
|
35
35
|
"wkh237 <xeiyan@gmail.com>"
|
|
36
36
|
],
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"react
|
|
38
|
+
"react": "16.13.1",
|
|
39
|
+
"react-native": "^0.68.2",
|
|
39
40
|
"@typescript-eslint/parser": "^3.4.0",
|
|
40
41
|
"@react-native-community/eslint-config": "^3.0.0",
|
|
41
42
|
"eslint-config-defaults": "^9.0.0",
|
|
42
43
|
"eslint-plugin-react": "^7.24.0",
|
|
43
44
|
"eslint": "^6.8.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"react": "*",
|
|
48
|
+
"react-native": "*"
|
|
44
49
|
}
|
|
45
50
|
}
|
package/polyfill/Fetch.js
CHANGED
|
@@ -59,10 +59,12 @@ class ReactNativeBlobUtilFetchPolyfill {
|
|
|
59
59
|
// task.then is not, so we have to extend task.then with progress and
|
|
60
60
|
// cancel function
|
|
61
61
|
let progressHandler, uploadHandler, cancelHandler;
|
|
62
|
+
let scopedTask = null;
|
|
62
63
|
let statefulPromise = promise
|
|
63
64
|
.then((body) => {
|
|
64
65
|
let task = RNconfig(config)
|
|
65
66
|
.fetch(options.method, url, options.headers, body);
|
|
67
|
+
scopedTask = task;
|
|
66
68
|
if (progressHandler)
|
|
67
69
|
task.progress(progressHandler);
|
|
68
70
|
if (uploadHandler)
|
|
@@ -87,8 +89,8 @@ class ReactNativeBlobUtilFetchPolyfill {
|
|
|
87
89
|
};
|
|
88
90
|
statefulPromise.cancel = () => {
|
|
89
91
|
cancelHandler = true;
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
+
if (scopedTask && scopedTask.cancel)
|
|
93
|
+
scopedTask.cancel();
|
|
92
94
|
};
|
|
93
95
|
|
|
94
96
|
return statefulPromise;
|
|
@@ -170,6 +170,12 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget {
|
|
|
170
170
|
log.verbose('sending request with args', _method, _url, _headers, body);
|
|
171
171
|
log.verbose(typeof body, body instanceof FormData);
|
|
172
172
|
|
|
173
|
+
if (body instanceof FormData) {
|
|
174
|
+
log.debug('creating blob and setting header from FormData instance');
|
|
175
|
+
body = new Blob(body);
|
|
176
|
+
this._headers['Content-Type'] = `multipart/form-data; boundary=${body.multipartBoundary}`;
|
|
177
|
+
}
|
|
178
|
+
|
|
173
179
|
if (body instanceof Blob) {
|
|
174
180
|
log.debug('sending blob body', body._blobCreated);
|
|
175
181
|
promise = new Promise((resolve, reject) => {
|
package/types.js
CHANGED
package/ios/IOS7Polyfill.h
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// IOS7Polyfill.h
|
|
3
|
-
// ReactNativeBlobUtil
|
|
4
|
-
//
|
|
5
|
-
// Created by Ben Hsieh on 2016/9/6.
|
|
6
|
-
// Copyright © 2016年 wkh237.github.io. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
#ifndef IOS7Polyfill_h
|
|
10
|
-
#define IOS7Polyfill_h
|
|
11
|
-
|
|
12
|
-
@interface NSString (Contains)
|
|
13
|
-
|
|
14
|
-
- (BOOL)RNFBContainsString:(NSString*)other;
|
|
15
|
-
|
|
16
|
-
@end
|
|
17
|
-
|
|
18
|
-
@implementation NSString (Contains)
|
|
19
|
-
|
|
20
|
-
- (BOOL)RNFBContainsString:(NSString*)other {
|
|
21
|
-
NSRange range = [self rangeOfString:other];
|
|
22
|
-
return range.length != 0;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
@end
|
|
27
|
-
#endif /* IOS7Polyfill_h */
|