Skip to content

Commit 74e5cc1

Browse files
author
Ron Radtke
committed
Merge remote-tracking branch 'origin/master' into develop
2 parents 20ab54e + e73e279 commit 74e5cc1

File tree

9 files changed

+45
-31
lines changed

9 files changed

+45
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ In `v0.5.0` we've added `writeStream` and `readStream`, which allows your app r
651651

652652
When calling `readStream` method, you have to `open` the stream, and start to read data. When the file is large, consider using an appropriate `bufferSize` and `interval` to reduce the native event dispatching overhead (see [Performance Tips](#user-content-performance-tips))
653653

654-
> The file stream event has a default throttle(10ms) and buffer size which preventing it cause too much overhead to main thread, yo can also [tweak these values](#user-content-performance-tips).
654+
> The file stream event has a default throttle(10ms) and buffer size which preventing it cause too much overhead to main thread, you can also [tweak these values](#user-content-performance-tips).
655655
656656
```js
657657
let data = ''

android/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ dependencies {
6262
}
6363

6464
afterEvaluate { project ->
65+
// do this only when building this lib alone as a root project
66+
if (project != rootProject) {
67+
return
68+
}
69+
6570
// some Gradle build hooks ref:
6671
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
6772
task androidJavadoc(type: Javadoc) {

android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtil.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -118,37 +118,29 @@ public void actionViewIntent(String path, String mime, @Nullable String chooserT
118118
this.getReactApplicationContext().getPackageName() + ".provider", new File(path));
119119

120120
Intent intent = new Intent(Intent.ACTION_VIEW);
121-
if (Build.VERSION.SDK_INT >= 24) {
121+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
122122
// Create the intent with data and type
123123
intent.setDataAndType(uriForFile, mime);
124-
if (chooserTitle != null) {
125-
intent = Intent.createChooser(intent, chooserTitle);
126-
}
127124

128125
// Set flag to give temporary permission to external app to use FileProvider
129126
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
130127
// All the activity to be opened outside of an activity
131128
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
132-
133-
// Validate that the device can open the file
134-
PackageManager pm = getCurrentActivity().getPackageManager();
135-
if (intent.resolveActivity(pm) != null) {
136-
this.getReactApplicationContext().startActivity(intent);
137-
}
138-
139129
} else {
140130
intent.setDataAndType(Uri.parse("file://" + path), mime).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
141-
if (chooserTitle != null) {
142-
intent = Intent.createChooser(intent, chooserTitle);
143-
}
131+
}
144132

145-
try {
146-
this.getReactApplicationContext().startActivity(intent);
147-
promise.resolve(true);
148-
} catch (ActivityNotFoundException ex) {
149-
promise.reject("ENOAPP", "No app installed for " + mime);
150-
}
133+
if (chooserTitle != null) {
134+
intent = Intent.createChooser(intent, chooserTitle);
151135
}
136+
137+
try {
138+
this.getReactApplicationContext().startActivity(intent);
139+
promise.resolve(true);
140+
} catch (ActivityNotFoundException ex) {
141+
promise.reject("ENOAPP", "No app installed for " + mime);
142+
}
143+
152144
ActionViewVisible = true;
153145

154146
final LifecycleEventListener listener = new LifecycleEventListener() {

android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static void writeFile(String path, String encoding, String data, final boolean a
5757

5858
if (!f.exists()) {
5959
if (dir != null && !dir.exists()) {
60-
if (!dir.mkdirs()) {
60+
if (!dir.mkdirs() && !dir.exists()) {
6161
promise.reject("EUNSPECIFIED", "Failed to create parent directory of '" + path + "'");
6262
return;
6363
}
@@ -129,7 +129,7 @@ static void writeFile(String path, ReadableArray data, final boolean append, fin
129129

130130
if (!f.exists()) {
131131
if (dir != null && !dir.exists()) {
132-
if (!dir.mkdirs()) {
132+
if (!dir.mkdirs() && !dir.exists()) {
133133
promise.reject("ENOTDIR", "Failed to create parent directory of '" + path + "'");
134134
return;
135135
}
@@ -445,7 +445,7 @@ void writeStream(String path, String encoding, boolean append, Callback callback
445445

446446
if (!dest.exists()) {
447447
if (dir != null && !dir.exists()) {
448-
if (!dir.mkdirs()) {
448+
if (!dir.mkdirs() && !dir.exists()) {
449449
callback.invoke("ENOTDIR", "Failed to create parent directory of '" + path + "'");
450450
return;
451451
}
@@ -1185,9 +1185,6 @@ static String normalizePath(String path) {
11851185
return null;
11861186
if (!path.matches("\\w+\\:.*"))
11871187
return path;
1188-
if (path.startsWith("file://")) {
1189-
return path.replace("file://", "");
1190-
}
11911188

11921189
Uri uri = Uri.parse(path);
11931190
if (path.startsWith(ReactNativeBlobUtilConst.FILE_PREFIX_BUNDLE_ASSET)) {

android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ private void done(Response resp) {
604604
ReactNativeBlobUtilFileResp ReactNativeBlobUtilFileResp;
605605

606606
try {
607-
ReactNativeBlobUtilFileResp = (ReactNativeBlobUtilFileResp) responseBody;
607+
ReactNativeBlobUtilFileResp = new ReactNativeBlobUtilFileResp(responseBody);
608608
} catch (ClassCastException ex) {
609609
// unexpected response type
610610
if (responseBody != null) {

android/src/main/java/com/ReactNativeBlobUtil/Response/ReactNativeBlobUtilFileResp.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public class ReactNativeBlobUtilFileResp extends ResponseBody {
3535
FileOutputStream ofStream;
3636
boolean isEndMarkerReceived;
3737

38+
public ReactNativeBlobUtilFileResp(ResponseBody body) {
39+
super();
40+
this.originalBody = body;
41+
}
42+
3843
public ReactNativeBlobUtilFileResp(ReactApplicationContext ctx, String taskId, ResponseBody body, String path, boolean overwrite) throws IOException {
3944
super();
4045
this.rctContext = ctx;

index.d.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,23 @@ export interface FS {
392392

393393
slice(src: string, dest: string, start: number, end: number): Promise<void>;
394394
asset(path: string): string;
395-
df(): Promise<{ free: number, total: number }>;
395+
df(): Promise<RNFetchBlobDf>;
396396
}
397397

398+
export interface RNFetchBlobDfIOS {
399+
free?: number;
400+
total?: number;
401+
}
402+
403+
export interface RNFetchBlobDfAndroid {
404+
external_free?: string;
405+
external_total?: string;
406+
internal_free?: string;
407+
internal_total?: string;
408+
}
409+
410+
export type RNFetchBlobDf = RNFetchBlobDfIOS & RNFetchBlobDfAndroid;
411+
398412
export interface Dirs {
399413
DocumentDir: string;
400414
CacheDir: string;
@@ -509,7 +523,7 @@ export interface AndroidApi {
509523
* @param mime Basically system will open an app according to this MIME type.
510524
* @param chooserTitle title for chooser, if not set the chooser won't be displayed (see [Android docs](https://developer.android.com/reference/android/content/Intent.html#createChooser(android.content.Intent,%20java.lang.CharSequence)))
511525
*/
512-
actionViewIntent(path: string, mime: string, chooserTitle?: string): Promise<any>;
526+
actionViewIntent(path: string, mime: string, chooserTitle?: string): Promise<boolean | null>;
513527

514528
/**
515529
*

ios/ReactNativeBlobUtilReqBuilder.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ +(void) buildOctetRequest:(NSDictionary *)options
115115
if([body hasPrefix:FILE_PREFIX]) {
116116
__block NSString * orgPath = [body substringFromIndex:[FILE_PREFIX length]];
117117
orgPath = [ReactNativeBlobUtilFS getPathOfAsset:orgPath];
118+
orgPath = [[NSURL URLWithString:orgPath] path];
118119
if([orgPath hasPrefix:AL_PREFIX])
119120
{
120121

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-blob-util",
3-
"version": "0.13.16",
3+
"version": "0.13.18",
44
"description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)