alpha0010 / react-native-file-access

Filesystem access for React Native
MIT License
298 stars 18 forks source link

[REQ] lstat functionality #47

Closed efstathiosntonas closed 2 years ago

efstathiosntonas commented 2 years ago

Hi @alpha0010,

I'm the maintainer of georstat/react-native-image-cache, we want to implement lstat for directories so I can get the file info.

Right now I just ls and then iterate over files to get the stat from each file and this has performance impact since the cached images could be thousands.

rn-fetch-blob has lstat , we want exactly this.

Can you implement the lstat feature? Thanks!

alpha0010 commented 2 years ago

Named api statDir() to avoid confusion with system lstat (check status of symlink).

efstathiosntonas commented 2 years ago

Thanks @alpha0010! Will try it tomorrow, I want to see how this will perform in big directories.

efstathiosntonas commented 2 years ago

@alpha0010 i think we got an extra / (on iOS, haven't tested Adnroid yet):

[{
"filename": "dfad955ed4b975ead480412fdd6dd725429b88b2.jpg", 
"lastModified": 1648792879016.788, 
"path": "/Users/stathis/Library/Developer/CoreSimulator/Devices/90F248ED-570F-463D-8D18-FF9151CF1F77/data/Containers/Data/Application/D7B5FD9D-E472-4CB3-A554-33212E60CC04/Library/Caches/images_cache// <----- HERE dfad955ed4b975ead480412fdd6dd725429b88b2.jpg", 
"size": 5710544, 
"type": "file"
}, 
{
"filename": "dfad955ed4b975ead480412fdd6dd725429b88b2 copy.jpg", 
"lastModified": 1648792879016.788, 
"path": "/Users/stathis/Library/Developer/CoreSimulator/Devices/90F248ED-570F-463D-8D18-FF9151CF1F77/data/Containers/Data/Application/D7B5FD9D-E472-4CB3-A554-33212E60CC04/Library/Caches/images_cache// <--- HERE dfad955ed4b975ead480412fdd6dd725429b88b2 copy.jpg", 
"size": 5710544,
"type": "file"
}]

BaseDir has this format: baseDir: ${Dirs.CacheDir}/images_cache/ otherwise the images are thrown in Caches/image.png instead of Caches/images_cache/image.png if I remove the trailing /.

edit: On Android the file path is fine:

[{"filename": "fa9b55edf623d5de305fb269167a1eda44cb1daf.jpg", "lastModified": 1648803976000, "path": "/data/user/0/com.reactnativeimagecacheexample/cache/images_cache/fa9b55edf623d5de305fb269167a1eda44cb1daf.jpg", "size": 4396619, "type": "file"}]
efstathiosntonas commented 2 years ago

^^ this has been fixed on 2.4.1, just for the record. Thanks @alpha0010 !