检查 React Native 中的可用磁盘空间 [英] Checking for available disk space in React Native
本文介绍了检查 React Native 中的可用磁盘空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经实现了以下代码:
I have implemented the following code:
- 使用 RNFS.downloadFile() 下载 zip 文件
- 使用 ZipArchive.unzip() 解压缩文件
- 使用 RNFS.unlink() 删除 zip 文件
我可以从服务器发送信息,表明 zip 文件有多大以及解压后的目录有多大.但是,如何检测设备上是否有足够的空间来下载和解压缩文件?我想一旦我弄清楚了,我就可以做这样的检查:
I can send info from the server indicating how big the zip file is and how big the unpacked directory is. However, how can I detect if there is enough space on the device to download and unzip the file? I assume once I figure this out I can just do a check like this:
if (free_space_on_device > zip_size + unpacked_size){
proceed with steps 1 through 3 (listed above)
}
推荐答案
我没有意识到 RNFS 有一个名为 getFSInfo 的函数.有了这些知识,我可以发出以下命令:
I did not realize that RNFS had a function called getFSInfo. With that knowledge, I can just issue the following command:
RNFS.getFSInfo()
.then ((info) => {
console.log("Free Space is" + info.freeSpace + "Bytes")
console.log("Free Space is" + info.freeSpace / 1024 + "KB")
})
这篇关于检查 React Native 中的可用磁盘空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文