react-native-blob-util 0.19.8 → 0.19.9
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/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java +38 -39
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilStream.java +15 -18
- package/ios/PrivacyInfo.xcprivacy +28 -0
- package/ios/ReactNativeBlobUtil.xcodeproj/project.pbxproj +2 -0
- package/package.json +1 -1
- package/react-native-blob-util.podspec +3 -0
- package/android/proguard-rules.pro +0 -17
|
@@ -519,15 +519,15 @@ class ReactNativeBlobUtilFS {
|
|
|
519
519
|
* @param callback JS context callback
|
|
520
520
|
*/
|
|
521
521
|
static void cp(String path, String dest, Callback callback) {
|
|
522
|
-
path = ReactNativeBlobUtilUtils.normalizePath(path);
|
|
523
522
|
dest = ReactNativeBlobUtilUtils.normalizePath(dest);
|
|
524
523
|
InputStream in = null;
|
|
525
524
|
OutputStream out = null;
|
|
526
525
|
String message = "";
|
|
527
526
|
|
|
528
527
|
try {
|
|
529
|
-
|
|
530
|
-
|
|
528
|
+
in = inputStreamFromPath(path);
|
|
529
|
+
if (in == null) {
|
|
530
|
+
callback.invoke("Source file at path`" + path + "` does not exist or can not be opened");
|
|
531
531
|
return;
|
|
532
532
|
}
|
|
533
533
|
if (!new File(dest).exists()) {
|
|
@@ -538,7 +538,6 @@ class ReactNativeBlobUtilFS {
|
|
|
538
538
|
}
|
|
539
539
|
}
|
|
540
540
|
|
|
541
|
-
in = inputStreamFromPath(path);
|
|
542
541
|
out = new FileOutputStream(dest);
|
|
543
542
|
|
|
544
543
|
byte[] buf = new byte[10240];
|
|
@@ -681,37 +680,36 @@ class ReactNativeBlobUtilFS {
|
|
|
681
680
|
*/
|
|
682
681
|
static void slice(String path, String dest, int start, int end, String encode, Promise promise) {
|
|
683
682
|
try {
|
|
684
|
-
path = ReactNativeBlobUtilUtils.normalizePath(path);
|
|
685
683
|
dest = ReactNativeBlobUtilUtils.normalizePath(dest);
|
|
686
|
-
|
|
687
|
-
if (
|
|
688
|
-
|
|
689
|
-
|
|
684
|
+
|
|
685
|
+
if (!path.startsWith(ReactNativeBlobUtilConst.FILE_PREFIX_CONTENT)) {
|
|
686
|
+
File file = new File(ReactNativeBlobUtilUtils.normalizePath(path));
|
|
687
|
+
if (file.isDirectory()) {
|
|
688
|
+
promise.reject("EISDIR", "Expecting a file but '" + path + "' is a directory");
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
690
691
|
}
|
|
691
|
-
|
|
692
|
+
|
|
693
|
+
InputStream in = inputStreamFromPath(path);
|
|
694
|
+
if (in == null) {
|
|
692
695
|
promise.reject("ENOENT", "No such file '" + path + "'");
|
|
693
696
|
return;
|
|
694
697
|
}
|
|
695
|
-
int size = (int) source.length();
|
|
696
|
-
int max = Math.min(size, end);
|
|
697
|
-
int expected = max - start;
|
|
698
|
-
int now = 0;
|
|
699
|
-
FileInputStream in = new FileInputStream(new File(path));
|
|
700
698
|
FileOutputStream out = new FileOutputStream(new File(dest));
|
|
701
699
|
int skipped = (int) in.skip(start);
|
|
702
700
|
if (skipped != start) {
|
|
703
|
-
promise.reject("EUNSPECIFIED", "Skipped " + skipped + " instead of the specified " + start + " bytes
|
|
701
|
+
promise.reject("EUNSPECIFIED", "Skipped " + skipped + " instead of the specified " + start + " bytes");
|
|
704
702
|
return;
|
|
705
703
|
}
|
|
706
704
|
byte[] buffer = new byte[10240];
|
|
707
|
-
|
|
705
|
+
int remain = end - start;
|
|
706
|
+
while (remain > 0) {
|
|
708
707
|
int read = in.read(buffer, 0, 10240);
|
|
709
|
-
int remain = expected - now;
|
|
710
708
|
if (read <= 0) {
|
|
711
709
|
break;
|
|
712
710
|
}
|
|
713
711
|
out.write(buffer, 0, (int) Math.min(remain, read));
|
|
714
|
-
|
|
712
|
+
remain -= read;
|
|
715
713
|
}
|
|
716
714
|
in.close();
|
|
717
715
|
out.flush();
|
|
@@ -847,31 +845,27 @@ class ReactNativeBlobUtilFS {
|
|
|
847
845
|
return;
|
|
848
846
|
}
|
|
849
847
|
|
|
850
|
-
path
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
return;
|
|
848
|
+
if (!path.startsWith(ReactNativeBlobUtilConst.FILE_PREFIX_CONTENT)) {
|
|
849
|
+
File file = new File(ReactNativeBlobUtilUtils.normalizePath(path));
|
|
850
|
+
if (file.isDirectory()) {
|
|
851
|
+
promise.reject("EISDIR", "Expecting a file but '" + path + "' is a directory");
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
857
854
|
}
|
|
858
855
|
|
|
859
|
-
|
|
856
|
+
MessageDigest md = MessageDigest.getInstance(algorithms.get(algorithm));
|
|
857
|
+
|
|
858
|
+
InputStream inputStream = inputStreamFromPath(path);
|
|
859
|
+
if (inputStream == null) {
|
|
860
860
|
promise.reject("ENOENT", "No such file '" + path + "'");
|
|
861
861
|
return;
|
|
862
862
|
}
|
|
863
|
-
|
|
864
|
-
MessageDigest md = MessageDigest.getInstance(algorithms.get(algorithm));
|
|
865
|
-
|
|
866
|
-
FileInputStream inputStream = new FileInputStream(path);
|
|
867
863
|
int chunkSize = 4096 * 256; // 1Mb
|
|
868
864
|
byte[] buffer = new byte[chunkSize];
|
|
869
865
|
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
md.update(buffer, 0, bytesRead);
|
|
874
|
-
}
|
|
866
|
+
int bytesRead;
|
|
867
|
+
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
|
868
|
+
md.update(buffer, 0, bytesRead);
|
|
875
869
|
}
|
|
876
870
|
|
|
877
871
|
StringBuilder hexString = new StringBuilder();
|
|
@@ -1018,8 +1012,10 @@ class ReactNativeBlobUtilFS {
|
|
|
1018
1012
|
}
|
|
1019
1013
|
|
|
1020
1014
|
/**
|
|
1021
|
-
* Get input stream of the given path
|
|
1022
|
-
* the stream is created by Assets Manager
|
|
1015
|
+
* Get input stream of the given path.
|
|
1016
|
+
* When the path starts with bundle-assets:// the stream is created by Assets Manager
|
|
1017
|
+
* When the path starts with content:// the stream is created by ContentResolver
|
|
1018
|
+
* otherwise use FileInputStream.
|
|
1023
1019
|
*
|
|
1024
1020
|
* @param path The file to open stream
|
|
1025
1021
|
* @return InputStream instance
|
|
@@ -1029,7 +1025,10 @@ class ReactNativeBlobUtilFS {
|
|
|
1029
1025
|
if (path.startsWith(ReactNativeBlobUtilConst.FILE_PREFIX_BUNDLE_ASSET)) {
|
|
1030
1026
|
return ReactNativeBlobUtilImpl.RCTContext.getAssets().open(path.replace(ReactNativeBlobUtilConst.FILE_PREFIX_BUNDLE_ASSET, ""));
|
|
1031
1027
|
}
|
|
1032
|
-
|
|
1028
|
+
if (path.startsWith(ReactNativeBlobUtilConst.FILE_PREFIX_CONTENT)) {
|
|
1029
|
+
return ReactNativeBlobUtilImpl.RCTContext.getContentResolver().openInputStream(Uri.parse(path));
|
|
1030
|
+
}
|
|
1031
|
+
return new FileInputStream(new File(ReactNativeBlobUtilUtils.normalizePath(path)));
|
|
1033
1032
|
}
|
|
1034
1033
|
|
|
1035
1034
|
/**
|
|
@@ -148,11 +148,15 @@ public class ReactNativeBlobUtilStream {
|
|
|
148
148
|
* @param callback Callback
|
|
149
149
|
*/
|
|
150
150
|
void writeStream(String path, String encoding, boolean append, Callback callback) {
|
|
151
|
+
String resolved = ReactNativeBlobUtilUtils.normalizePath(path);
|
|
152
|
+
if (resolved != null)
|
|
153
|
+
path = resolved;
|
|
154
|
+
|
|
151
155
|
try {
|
|
152
156
|
File dest = new File(path);
|
|
153
157
|
File dir = dest.getParentFile();
|
|
154
158
|
|
|
155
|
-
if (!dest.exists()) {
|
|
159
|
+
if (resolved != null && !dest.exists()) {
|
|
156
160
|
if (dir != null && !dir.exists()) {
|
|
157
161
|
if (!dir.mkdirs()) {
|
|
158
162
|
callback.invoke("ENOTDIR", "Failed to create parent directory of '" + path + "'");
|
|
@@ -168,7 +172,16 @@ public class ReactNativeBlobUtilStream {
|
|
|
168
172
|
return;
|
|
169
173
|
}
|
|
170
174
|
|
|
171
|
-
OutputStream fs
|
|
175
|
+
OutputStream fs;
|
|
176
|
+
if (resolved != null && path.startsWith(ReactNativeBlobUtilConst.FILE_PREFIX_BUNDLE_ASSET)) {
|
|
177
|
+
fs = ReactNativeBlobUtilImpl.RCTContext.getAssets().openFd(path.replace(ReactNativeBlobUtilConst.FILE_PREFIX_BUNDLE_ASSET, "")).createOutputStream ();
|
|
178
|
+
}
|
|
179
|
+
// fix issue 287
|
|
180
|
+
else if (resolved == null) {
|
|
181
|
+
fs = ReactNativeBlobUtilImpl.RCTContext.getContentResolver().openOutputStream(Uri.parse(path));
|
|
182
|
+
} else {
|
|
183
|
+
fs = new FileOutputStream(path, append);
|
|
184
|
+
}
|
|
172
185
|
this.encoding = encoding;
|
|
173
186
|
String streamId = UUID.randomUUID().toString();
|
|
174
187
|
ReactNativeBlobUtilStream.fileStreams.put(streamId, this);
|
|
@@ -274,20 +287,4 @@ public class ReactNativeBlobUtilStream {
|
|
|
274
287
|
eventData.putString("streamId", streamName);
|
|
275
288
|
this.emitter.emit(EVENT_FILESYSTEM, eventData);
|
|
276
289
|
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Get input stream of the given path, when the path is a string starts with bundle-assets://
|
|
280
|
-
* the stream is created by Assets Manager, otherwise use FileInputStream.
|
|
281
|
-
*
|
|
282
|
-
* @param path The file to open stream
|
|
283
|
-
* @return InputStream instance
|
|
284
|
-
* @throws IOException If the given file does not exist or is a directory FileInputStream will throw a FileNotFoundException
|
|
285
|
-
*/
|
|
286
|
-
public static InputStream inputStreamFromPath(String path) throws IOException {
|
|
287
|
-
if (path.startsWith(ReactNativeBlobUtilConst.FILE_PREFIX_BUNDLE_ASSET)) {
|
|
288
|
-
return ReactNativeBlobUtilImpl.RCTContext.getAssets().open(path.replace(ReactNativeBlobUtilConst.FILE_PREFIX_BUNDLE_ASSET, ""));
|
|
289
|
-
}
|
|
290
|
-
return new FileInputStream(new File(path));
|
|
291
|
-
}
|
|
292
|
-
|
|
293
290
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>NSPrivacyCollectedDataTypes</key>
|
|
6
|
+
<array/>
|
|
7
|
+
<key>NSPrivacyAccessedAPITypes</key>
|
|
8
|
+
<array>
|
|
9
|
+
<dict>
|
|
10
|
+
<key>NSPrivacyAccessedAPIType</key>
|
|
11
|
+
<string>NSPrivacyAccessedAPICategoryDiskSpace</string>
|
|
12
|
+
<key>NSPrivacyAccessedAPITypeReasons</key>
|
|
13
|
+
<array>
|
|
14
|
+
<string>85F4.1</string>
|
|
15
|
+
<string>E174.1</string>
|
|
16
|
+
</array>
|
|
17
|
+
</dict>
|
|
18
|
+
<dict>
|
|
19
|
+
<key>NSPrivacyAccessedAPIType</key>
|
|
20
|
+
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
|
|
21
|
+
<key>NSPrivacyAccessedAPITypeReasons</key>
|
|
22
|
+
<array>
|
|
23
|
+
<string>0A2A.1</string>
|
|
24
|
+
</array>
|
|
25
|
+
</dict>
|
|
26
|
+
</array>
|
|
27
|
+
</dict>
|
|
28
|
+
</plist>
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
A15C30111CD25C330074CB35 /* ReactNativeBlobUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ReactNativeBlobUtil.h; path = ReactNativeBlobUtil/ReactNativeBlobUtil.h; sourceTree = "<group>"; };
|
|
54
54
|
A19B48231D98100800E6868A /* ReactNativeBlobUtilProgress.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ReactNativeBlobUtilProgress.h; sourceTree = "<group>"; };
|
|
55
55
|
A1AAE2971D300E3E0051D11C /* ReactNativeBlobUtilReqBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ReactNativeBlobUtilReqBuilder.h; sourceTree = "<group>"; };
|
|
56
|
+
CBE41E482BB345A0004922E9 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
|
|
56
57
|
E83F89B1EFF498D9833537A4 /* Pods-ReactNativeBlobUtil.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeBlobUtil.debug.xcconfig"; path = "Target Support Files/Pods-ReactNativeBlobUtil/Pods-ReactNativeBlobUtil.debug.xcconfig"; sourceTree = "<group>"; };
|
|
57
58
|
/* End PBXFileReference section */
|
|
58
59
|
|
|
@@ -87,6 +88,7 @@
|
|
|
87
88
|
A15C30051CD25C330074CB35 = {
|
|
88
89
|
isa = PBXGroup;
|
|
89
90
|
children = (
|
|
91
|
+
CBE41E482BB345A0004922E9 /* PrivacyInfo.xcprivacy */,
|
|
90
92
|
11A307F22A06E47400E56674 /* ReactNativeBlobUtil */,
|
|
91
93
|
11A307F42A06E47500E56674 /* ReactNativeBlobUtilConst.mm */,
|
|
92
94
|
11A307F32A06E47400E56674 /* ReactNativeBlobUtilFileTransformer.mm */,
|
package/package.json
CHANGED
|
@@ -13,6 +13,9 @@ Pod::Spec.new do |s|
|
|
|
13
13
|
s.source = { :git => "https://github.com/RonRadtke/react-native-blob-util" }
|
|
14
14
|
s.author = 'RonRadtke'
|
|
15
15
|
s.source_files = 'ios/**/*.{h,m,mm,swift}'
|
|
16
|
+
s.resource_bundles = {
|
|
17
|
+
'ReactNativeBlobUtilPrivacyInfo' => ['ios/PrivacyInfo.xcprivacy'],
|
|
18
|
+
}
|
|
16
19
|
s.platforms = { :ios => "11.0" }
|
|
17
20
|
s.framework = 'AssetsLibrary'
|
|
18
21
|
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# Add project specific ProGuard rules here.
|
|
2
|
-
# By default, the flags in this file are appended to flags specified
|
|
3
|
-
# in /Users/xeiyan/Library/Android/sdk/tools/proguard/proguard-android.txt
|
|
4
|
-
# You can edit the include path and order by changing the proguardFiles
|
|
5
|
-
# directive in build.gradle.
|
|
6
|
-
#
|
|
7
|
-
# For more details, see
|
|
8
|
-
# http://developer.android.com/guide/developing/tools/proguard.html
|
|
9
|
-
|
|
10
|
-
# Add any project specific keep options here:
|
|
11
|
-
|
|
12
|
-
# If your project uses WebView with JS, uncomment the following
|
|
13
|
-
# and specify the fully qualified class name to the JavaScript interface
|
|
14
|
-
# class:
|
|
15
|
-
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
|
16
|
-
# public *;
|
|
17
|
-
#}
|