我已经实现了下面的代码:
我可以从显示的zip文件有多大服务器与解压缩的目录有多大发送信息。但是,我怎么能检测是否存在设备上有足够的空间来下载并解压缩文件?我想一旦我算出这个我可以做这样的检查:
if (free_space_on_device > zip_size + unpacked_size){
proceed with steps 1 through 3 (listed above)
}
我不知道,RNFS有一个名为getFSInfo功能。有了这些知识,我可以只发出以下命令:
RNFS.getFSInfo()
.then ((info) => {
console.log("Free Space is" + info.freeSpace + "Bytes")
console.log("Free Space is" + info.freeSpace / 1024 + "KB")
})
如果你正在使用react-native-fetch-blob
而不是react-native-fs
这是你正在寻找的功能:
RNFetchBlob.fs.df().then( response => {
console.log('Free space in bytes: ' + response.free);
console.log('Total space in bytes: ' + response.total);
} );
在Android上,响应对象看起来是这样的:
RNFetchBlob.fs.df().then( response => {
console.log('External free space in bytes: ' + response.external_free);
console.log('External total space in bytes: ' + response.external_total);
console.log('Internal free space in bytes: ' + response.internal_free);
console.log('Internal total space in bytes: ' + response.internal_total);
} );