| 
				
			 | 
			
			
				@@ -1,6 +1,7 @@ 
			 | 
		
	
		
			
			| 
				1
			 | 
			
				1
			 | 
			
			
				 package com.RNFetchBlob; 
			 | 
		
	
		
			
			| 
				2
			 | 
			
				2
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				3
			 | 
			
				3
			 | 
			
			
				 import android.net.Uri; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				4
			 | 
			
			
				+import android.os.Environment; 
			 | 
		
	
		
			
			| 
				4
			 | 
			
				5
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				5
			 | 
			
				6
			 | 
			
			
				 import com.facebook.react.bridge.Arguments; 
			 | 
		
	
		
			
			| 
				6
			 | 
			
				7
			 | 
			
			
				 import com.facebook.react.bridge.Callback; 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -10,6 +11,7 @@ import com.facebook.react.bridge.ReactMethod; 
			 | 
		
	
		
			
			| 
				10
			 | 
			
				11
			 | 
			
			
				 import com.facebook.react.bridge.ReadableArray; 
			 | 
		
	
		
			
			| 
				11
			 | 
			
				12
			 | 
			
			
				 import com.facebook.react.bridge.ReadableMap; 
			 | 
		
	
		
			
			| 
				12
			 | 
			
				13
			 | 
			
			
				 import com.facebook.react.bridge.ReadableMapKeySetIterator; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				14
			 | 
			
			
				+import com.facebook.react.bridge.WritableArray; 
			 | 
		
	
		
			
			| 
				13
			 | 
			
				15
			 | 
			
			
				 import com.facebook.react.bridge.WritableMap; 
			 | 
		
	
		
			
			| 
				14
			 | 
			
				16
			 | 
			
			
				 import com.facebook.react.modules.core.DeviceEventManagerModule; 
			 | 
		
	
		
			
			| 
				15
			 | 
			
				17
			 | 
			
			
				 import com.loopj.android.http.AsyncHttpClient; 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -34,6 +36,20 @@ public class RNFetchBlob extends ReactContextBaseJavaModule { 
			 | 
		
	
		
			
			| 
				34
			 | 
			
				36
			 | 
			
			
				         return "RNFetchBlob"; 
			 | 
		
	
		
			
			| 
				35
			 | 
			
				37
			 | 
			
			
				     } 
			 | 
		
	
		
			
			| 
				36
			 | 
			
				38
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				
			 | 
			
				39
			 | 
			
			
				+    @ReactMethod 
			 | 
		
	
		
			
			| 
				
			 | 
			
				40
			 | 
			
			
				+    public ReadableArray getSystemDirs() { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				41
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				42
			 | 
			
			
				+        WritableArray results = Arguments.createArray(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				43
			 | 
			
			
				+        ReactApplicationContext ctx = this.getReactApplicationContext(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				44
			 | 
			
			
				+        results.pushString(String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES))); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				45
			 | 
			
			
				+        results.pushString(String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES))); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				46
			 | 
			
			
				+        results.pushString(String.valueOf(ctx.getFilesDir())); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				47
			 | 
			
			
				+        results.pushString(String.valueOf(ctx.getCacheDir())); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				48
			 | 
			
			
				+        results.pushString(String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC))); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				49
			 | 
			
			
				+        results.pushString(String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM))); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				50
			 | 
			
			
				+        return results; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				51
			 | 
			
			
				+    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				52
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				37
			 | 
			
				53
			 | 
			
			
				     @ReactMethod 
			 | 
		
	
		
			
			| 
				38
			 | 
			
				54
			 | 
			
			
				     public void flush(String taskId) { 
			 | 
		
	
		
			
			| 
				39
			 | 
			
				55
			 | 
			
			
				         try { 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -49,14 +65,14 @@ public class RNFetchBlob extends ReactContextBaseJavaModule { 
			 | 
		
	
		
			
			| 
				49
			 | 
			
				65
			 | 
			
			
				     } 
			 | 
		
	
		
			
			| 
				50
			 | 
			
				66
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				51
			 | 
			
				67
			 | 
			
			
				     @ReactMethod 
			 | 
		
	
		
			
			| 
				52
			 | 
			
				
			 | 
			
			
				-    public void readStream(String taskId, String encoding) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				68
			 | 
			
			
				+    public void readStream(String path, String encoding) { 
			 | 
		
	
		
			
			| 
				53
			 | 
			
				69
			 | 
			
			
				         RNFetchBlobFS fs = new RNFetchBlobFS(this.getReactApplicationContext()); 
			 | 
		
	
		
			
			| 
				54
			 | 
			
				
			 | 
			
			
				-        fs.readStream(taskId, encoding); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				70
			 | 
			
			
				+        fs.readStream(path, encoding); 
			 | 
		
	
		
			
			| 
				55
			 | 
			
				71
			 | 
			
			
				     } 
			 | 
		
	
		
			
			| 
				56
			 | 
			
				72
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				57
			 | 
			
				73
			 | 
			
			
				     @ReactMethod 
			 | 
		
	
		
			
			| 
				58
			 | 
			
				74
			 | 
			
			
				     public void fetchBlob(ReadableMap options, String taskId, String method, String url, ReadableMap headers, String body, final Callback callback) { 
			 | 
		
	
		
			
			| 
				59
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				
			 | 
			
				75
			 | 
			
			
				+        RNFetchBlobConfig config = new RNFetchBlobConfig(options); 
			 | 
		
	
		
			
			| 
				60
			 | 
			
				76
			 | 
			
			
				         try { 
			 | 
		
	
		
			
			| 
				61
			 | 
			
				77
			 | 
			
			
				             Uri uri = Uri.parse(url); 
			 | 
		
	
		
			
			| 
				62
			 | 
			
				78
			 | 
			
			
				             AsyncHttpClient req = new AsyncHttpClient(); 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -87,8 +103,8 @@ public class RNFetchBlob extends ReactContextBaseJavaModule { 
			 | 
		
	
		
			
			| 
				87
			 | 
			
				103
			 | 
			
			
				             AsyncHttpResponseHandler handler; 
			 | 
		
	
		
			
			| 
				88
			 | 
			
				104
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				89
			 | 
			
				105
			 | 
			
			
				             // create handler 
			 | 
		
	
		
			
			| 
				90
			 | 
			
				
			 | 
			
			
				-            if(options.getBoolean("fileCache") || options.getString("path") != null) 
			 | 
		
	
		
			
			| 
				91
			 | 
			
				
			 | 
			
			
				-                handler = new RNFetchBlobFileHandler(this.getReactApplicationContext(), taskId, callback); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				106
			 | 
			
			
				+            if(config.fileCache || config.path != null) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				107
			 | 
			
			
				+                handler = new RNFetchBlobFileHandler(this.getReactApplicationContext(), taskId, config, callback); 
			 | 
		
	
		
			
			| 
				92
			 | 
			
				108
			 | 
			
			
				             else 
			 | 
		
	
		
			
			| 
				93
			 | 
			
				109
			 | 
			
			
				                 handler = new RNFetchBlobBinaryHandler(this.getReactApplicationContext(), taskId, callback); 
			 | 
		
	
		
			
			| 
				94
			 | 
			
				110
			 | 
			
			
				  
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -116,6 +132,7 @@ public class RNFetchBlob extends ReactContextBaseJavaModule { 
			 | 
		
	
		
			
			| 
				116
			 | 
			
				132
			 | 
			
			
				     @ReactMethod 
			 | 
		
	
		
			
			| 
				117
			 | 
			
				133
			 | 
			
			
				     public void fetchBlobForm(ReadableMap options, String taskId, String method, String url, ReadableMap headers, ReadableArray body, final Callback callback) { 
			 | 
		
	
		
			
			| 
				118
			 | 
			
				134
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				
			 | 
			
				135
			 | 
			
			
				+        RNFetchBlobConfig config = new RNFetchBlobConfig(options); 
			 | 
		
	
		
			
			| 
				119
			 | 
			
				136
			 | 
			
			
				         try { 
			 | 
		
	
		
			
			| 
				120
			 | 
			
				137
			 | 
			
			
				             Uri uri = Uri.parse(url); 
			 | 
		
	
		
			
			| 
				121
			 | 
			
				138
			 | 
			
			
				             AsyncHttpClient req = new AsyncHttpClient(); 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -177,8 +194,8 @@ public class RNFetchBlob extends ReactContextBaseJavaModule { 
			 | 
		
	
		
			
			| 
				177
			 | 
			
				194
			 | 
			
			
				             AsyncHttpResponseHandler handler; 
			 | 
		
	
		
			
			| 
				178
			 | 
			
				195
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				179
			 | 
			
				196
			 | 
			
			
				             // create handler 
			 | 
		
	
		
			
			| 
				180
			 | 
			
				
			 | 
			
			
				-            if(options.getBoolean("fileCache") || options.getString("path") != null) 
			 | 
		
	
		
			
			| 
				181
			 | 
			
				
			 | 
			
			
				-                handler = new RNFetchBlobFileHandler(this.getReactApplicationContext(), taskId, callback); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				197
			 | 
			
			
				+            if(config.fileCache || config.path != null) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				198
			 | 
			
			
				+                handler = new RNFetchBlobFileHandler(this.getReactApplicationContext(), taskId, config, callback); 
			 | 
		
	
		
			
			| 
				182
			 | 
			
				199
			 | 
			
			
				             else 
			 | 
		
	
		
			
			| 
				183
			 | 
			
				200
			 | 
			
			
				                 handler = new RNFetchBlobBinaryHandler(this.getReactApplicationContext(), taskId, callback); 
			 | 
		
	
		
			
			| 
				184
			 | 
			
				201
			 | 
			
			
				  
			 |