I did this:
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');
});
i testes it in browser & android but it always "FAILED";
Run it on android device and see the log on android studio device logging tool (android device monitor). You will find the exact cause of the error. I had this error. The cause was ionic couldn't find the specified folder so i used this.file.externalDataDirectory or the directory you chose in a format like "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'));
I can tell you that you cannot unzip from www/assets
folder, you need to copy that zip file into system directory of the device like this.file.dataDirectory , then execute unzip in here.
I've tested, it works.
Reference: https://github.com/MobileChromeApps/cordova-plugin-zip/issues/56
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.