Skip to content

Commit 7448173

Browse files
authored
fix: reading file from assets
There is no need to call `getAssets().openFd` to get the file length, It is also causing strange error such as `This file can not be opened as a file descriptor; it is probably compressed` when loading a file from assets on android.
1 parent 2531333 commit 7448173

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,9 @@ static void readFile(String path, String encoding, final boolean transformFile,
257257
if (resolved != null && resolved.startsWith(ReactNativeBlobUtilConst.FILE_PREFIX_BUNDLE_ASSET)) {
258258
String assetName = path.replace(ReactNativeBlobUtilConst.FILE_PREFIX_BUNDLE_ASSET, "");
259259
// This fails should an asset file be >2GB
260-
length = (int) ReactNativeBlobUtilImpl.RCTContext.getAssets().openFd(assetName).getLength();
261-
bytes = new byte[length];
262260
InputStream in = ReactNativeBlobUtilImpl.RCTContext.getAssets().open(assetName);
261+
length = in.available();
262+
bytes = new byte[length];
263263
bytesRead = in.read(bytes, 0, length);
264264
in.close();
265265
}

0 commit comments

Comments
 (0)