@@ -229,15 +229,14 @@ static public String getTmpPath(ReactApplicationContext ctx, String taskId) {
229229 * @param encoding File stream decoder, should be one of `base64`, `utf8`, `ascii`
230230 * @param bufferSize Buffer size of read stream, default to 4096 (4095 when encode is `base64`)
231231 */
232- public void readStream ( String path , String encoding , int bufferSize ) {
232+ public void readStream (String path , String encoding , int bufferSize , final String streamId ) {
233233 path = normalizePath (path );
234234 AsyncTask <String , Integer , Integer > task = new AsyncTask <String , Integer , Integer >() {
235235 @ Override
236236 protected Integer doInBackground (String ... args ) {
237237 String path = args [0 ];
238238 String encoding = args [1 ];
239239 int bufferSize = Integer .parseInt (args [2 ]);
240- String eventName = "RNFetchBlobStream+" + path ;
241240 try {
242241
243242 int chunkSize = encoding .equalsIgnoreCase ("base64" ) ? 4095 : 4096 ;
@@ -259,7 +258,7 @@ protected Integer doInBackground(String ... args) {
259258 if (encoding .equalsIgnoreCase ("utf8" )) {
260259 while ((cursor = fs .read (buffer )) != -1 ) {
261260 String chunk = new String (buffer , 0 , cursor , "UTF-8" );
262- emitStreamEvent (eventName , "data" , chunk );
261+ emitStreamEvent (streamId , "data" , chunk );
263262 }
264263 } else if (encoding .equalsIgnoreCase ("ascii" )) {
265264 while ((cursor = fs .read (buffer )) != -1 ) {
@@ -268,7 +267,7 @@ protected Integer doInBackground(String ... args) {
268267 {
269268 chunk .pushInt ((int )buffer [i ]);
270269 }
271- emitStreamEvent (eventName , "data" , chunk );
270+ emitStreamEvent (streamId , "data" , chunk );
272271 }
273272 } else if (encoding .equalsIgnoreCase ("base64" )) {
274273 while ((cursor = fs .read (buffer )) != -1 ) {
@@ -277,24 +276,24 @@ protected Integer doInBackground(String ... args) {
277276 for (int i =0 ;i <cursor ;i ++) {
278277 copy [i ] = buffer [i ];
279278 }
280- emitStreamEvent (eventName , "data" , Base64 .encodeToString (copy , Base64 .NO_WRAP ));
279+ emitStreamEvent (streamId , "data" , Base64 .encodeToString (copy , Base64 .NO_WRAP ));
281280 }
282281 else
283- emitStreamEvent (eventName , "data" , Base64 .encodeToString (buffer , Base64 .NO_WRAP ));
282+ emitStreamEvent (streamId , "data" , Base64 .encodeToString (buffer , Base64 .NO_WRAP ));
284283 }
285284 } else {
286285 String msg = "unrecognized encoding `" + encoding + "`" ;
287- emitStreamEvent (eventName , "error" , msg );
286+ emitStreamEvent (streamId , "error" , msg );
288287 error = true ;
289288 }
290289
291290 if (!error )
292- emitStreamEvent (eventName , "end" , "" );
291+ emitStreamEvent (streamId , "end" , "" );
293292 fs .close ();
294293 buffer = null ;
295294
296295 } catch (Exception err ) {
297- emitStreamEvent (eventName , "error" , err .getLocalizedMessage ());
296+ emitStreamEvent (streamId , "error" , err .getLocalizedMessage ());
298297 }
299298 return null ;
300299 }
0 commit comments