mirror of
https://github.com/status-im/react-native-fs.git
synced 2025-02-28 23:10:29 +00:00
Workaround for #346: try to better detect when an asset path is a directory or a (possible) compressed file
This commit is contained in:
parent
a23a70389a
commit
18ee5b35ef
@ -342,16 +342,17 @@ public class RNFSManager extends ReactContextBaseJavaModule {
|
||||
String path = directory.isEmpty() ? childFile : String.format("%s/%s", directory, childFile); // don't allow / at the start when directory is ""
|
||||
fileMap.putString("path", path);
|
||||
int length = 0;
|
||||
boolean isDirectory = false;
|
||||
boolean isDirectory = true;
|
||||
try {
|
||||
AssetFileDescriptor assetFileDescriptor = assetManager.openFd(path);
|
||||
if (assetFileDescriptor != null) {
|
||||
length = (int) assetFileDescriptor.getLength();
|
||||
assetFileDescriptor.close();
|
||||
isDirectory = false;
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
//.. ah.. is a directory!
|
||||
isDirectory = true;
|
||||
//.. ah.. is a directory or a compressed file?
|
||||
isDirectory = ex.getMessage().indexOf("compressed") == -1;
|
||||
}
|
||||
fileMap.putInt("size", length);
|
||||
fileMap.putInt("type", isDirectory ? 1 : 0); // if 0, probably a folder..
|
||||
|
Loading…
x
Reference in New Issue
Block a user