检查可用磁盘空间在本地做出反应

问题描述 投票:0回答:2

我已经实现了下面的代码:

  1. 下载使用RNFS.downloadFile一个zip文件()
  2. 解压缩使用ZipArchive.unzip文件()
  3. 删除使用RNFS.unlink zip文件()

我可以从显示的zip文件有多大服务器与解压缩的目录有多大发送信息。但是,我怎么能检测是否存在设备上有足够的空间来下载并解压缩文件?我想一旦我算出这个我可以做这样的检查:

if (free_space_on_device > zip_size + unpacked_size){
   proceed with steps 1 through 3 (listed above)
}
android ios react-native diskspace
2个回答
2
投票

我不知道,RNFS有一个名为getFSInfo功能。有了这些知识,我可以只发出以下命令:

RNFS.getFSInfo()
.then ((info) => {
   console.log("Free Space is" + info.freeSpace + "Bytes")
   console.log("Free Space is" + info.freeSpace / 1024 + "KB")
})

0
投票

如果你正在使用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);
} );
© www.soinside.com 2019 - 2024. All rights reserved.