Skip to content

Commit

Permalink
Workaround for #346: try to better detect when an asset path is a dir…
Browse files Browse the repository at this point in the history
…ectory or a (possible) compressed file
  • Loading branch information
jacargentina committed Sep 21, 2017
1 parent a23a703 commit 18ee5b3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions android/src/main/java/com/rnfs/RNFSManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,17 @@ public void readDirAssets(String directory, Promise promise) {
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..
Expand Down

0 comments on commit 18ee5b3

Please sign in to comment.