rn-fetch-blob
rn-fetch-blob copied to clipboard
RNFetchBlob.fs.stat size of directory is incorrect
Hi ! I met an error When in use RNFetchBlob.fs.stat couldn't get correct size of directory. I want to get whole directory RNFetchBlob.fs.dirs.CacheDir's size, which contain cached images by react-native-img-cache. But get wrong data, directory size smaller than file or sub-directory.
Versions
"react": "^16.0.0",
"react-native": "^0.50.0",
"react-native-fetch-blob": "^0.10.8",
Code
RNFetchBlob.fs.stat(RNFetchBlob.fs.dirs.CacheDir)
.then((stats) => {
console.log(stats);
if (stats && stats.size) {
this.setState({ cacheSize: stats.size });
}
})
.catch(() => { });
RNFetchBlob.fs.stat(`${RNFetchBlob.fs.dirs.CacheDir}/react-native-img-cache`)
.then((stats) => {
console.log(stats);
})
.catch(() => { });
RNFetchBlob.fs.stat(`${RNFetchBlob.fs.dirs.CacheDir}/react-native-img-cache/7393ba9b6f2f1b0e379e2c7ebf219b515d85f666.jpg`)
.then((stats) => {
console.log(stats);
})
.catch(() => { });
But Print Result

Anything wrong in my code? Or I need traverse all cache sub-directory and calculate directory and files' size?
I use another method. But I think it is not the best way. Here is the snippet
componentDidMount() {
this.cacheSize = 0
this._statisticsCacheSize(RNFetchBlob.fs.dirs.CacheDir)
}
_statisticsCacheSize(path) {
RNFetchBlob.fs.lstat(path).then((lstat => {
for (let stat of lstat) {
if (stat.type === "directory") {
this._statisticsCacheSize(stat.path)
} else {
this.cacheSize += parseInt(stat.size)
this.setState({
size: this.cacheSize
})
}
}
})).catch(err => {
console.warn(err)
})
}
Yeah I'm doing the same as @echokk11 however its obviously not the best way.
My guess is that by reporting 320 bytes as the size of the directory is that our stat method is literally getting the size of just the folder with various folder metaData. I don't think that information would ever be of value to anyone so I think we should consider this a bug and report the size of a directory as the true size with the aggregation of all the children within that directory.
i got this error
Please report: Excessive number of pending callbacks: 501. Some pending callbacks that might have leaked by never being called from native code: {"4142":{"module":"ReceiveSharingIntent","method":"getFileNames"},"18900":{},"18901":{},"18902":{},"18903":{},"18904":{},"18905":{},"18906":{},"18907":{},"18908":{},"18909":{},"18910":{},"18911":{},"18912":{},"18913":{},"18914":{},"18915":{},"18916":{},"18917":{},"18918":{},"18919":{},"18920":{},"18921":{},"18922":{},"18923":{},"18924":{},"18925":{},"18926":{},"18927":{},"18928":{},"18929":{},"18930":{},"18931":{},"18932":{},"18933":{},"18934":{},"18935":{},"18936":{},"18937":{},"18938":{},"18939":{},"18940":{},"18941":{},"18942":{},"18943":{},"18944":{},"18945":{},"18946":{},"18947":{},"18948":{},"...(truncated keys)...":451}