[英]ionic 2 Unzip zip file in assets
我这样做:
this.zip.unzip('../../assets/eval.zip', '../../assets/folder', (progress) => console.log('Unzipping, ' + Math.round((progress.loaded / progress.total) * 100) + '%'))
.then((result) => {
console.log();
if(result === 0) console.log('SUCCESS');
if(result === -1) console.log('FAILED');
});
我在浏览器和android中对其进行了测试,但始终“失败”;
在android设备上运行它,并查看android studio设备日志记录工具(android设备监视器)上的日志。 您将找到错误的确切原因。 我有这个错误。 原因是离子找不到指定的文件夹,因此我使用了this.file.externalDataDirectory或您选择的目录,格式为“ file:/// storage / emulated / 0 / yourPath”。
// this.import(this.file.externalDataDirectory + '/Spark.epub', this.file.externalDataDirectory + '/spark');
this.file.checkDir(this.file.externalDataDirectory +'assets/folder','')
.then(_ => {
this.file.checkFile(this.file.externalDataDirectory +'assets/eval.zip','')
.then(_ => {
this.zip.unzip(this.file.externalDataDirectory +'assets/eval.zip', this.file.externalDataDirectory +'assets/folder',
(progress) => console.log('Unzipping, ' + Math.round((progress.loaded / progress.total) * 100) + '%'))
.then((data) => {
/* Wow everything goes good, but just in case verify data.success */
console.log(data);
}).then((error) => {
/* Wow something goes wrong, check the error.message */
console.log(error);
debugger;
})
}).catch(err => console.log('file doesn\'t exist'));
}).catch(err => console.log('Directory doesn\'t exist'));
我可以告诉您,您无法从www/assets
文件夹解压缩,您需要将该zip文件复制到设备的系统目录中,例如this.file.dataDirectory ,然后在此处执行解压缩。
我已经测试过,它可以工作。
参考: https : //github.com/MobileChromeApps/cordova-plugin-zip/issues/56
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.