Browse Source

Fix Android fs.readStream bug when reading UTF8 format data

Ben Hsieh 7 years ago
parent
commit
d67d79e45e
1 changed files with 2 additions and 2 deletions
  1. 2
    2
      src/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

+ 2
- 2
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java View File

@@ -248,9 +248,9 @@ public class RNFetchBlobFS {
248 248
                 CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
249 249
                 while ((cursor = fs.read(buffer)) != -1) {
250 250
                     encoder.encode(ByteBuffer.wrap(buffer).asCharBuffer());
251
-                    // if the data contains invalid characters the following lines will be
252
-                    // skipped.
253 251
                     String chunk = new String(buffer);
252
+                    if(cursor != bufferSize)
253
+                        chunk = chunk.substring(0, cursor);
254 254
                     emitStreamEvent(streamId, "data", chunk);
255 255
                     if(tick > 0)
256 256
                         SystemClock.sleep(tick);