ngCordova$cordovaZip不解压缩,Ionic应用程序

ngCordova $cordovaZip not unzipping, Ionic app

本文关键字:Ionic 应用程序 解压缩 cordovaZip ngCordova      更新时间:2023-09-26

在过去的几个小时里,我一直在努力尝试使用$cordovaZip解压缩特定的 .epub 文件,但运气不佳。

zip和文件插件安装正确,$cordovaZip也注入到特定的控制器。当我尝试解压缩本地/远程 .epub 文件时,我只收到错误回调而不是成功回调。

这是我的代码示例。

$cordovaZip
.unzip(
'/templates/test.epub'
cordova.file.dataDirectory).then(function (data) {
  console.log('success', data);
}, function (err) {
  console.log('error', err);
}, function (progressEvent) {
  // https://github.com/MobileChromeApps/zip#usage
  console.log(progressEvent);
});

如果遇到相同问题的人可以帮我一把,我将不胜感激。

我相信绝对

URL是必需的,而不是相对URL。例如

var PathToFileInString  = cordova.file.externalRootDirectory+"HereIsMyFolder",
    PathToResultZip     = cordova.file.externalRootDirectory;
JJzip.zip(PathToFileInString, {target:PathToResultZip,name:"SuperZip"},function(data){
    /* Wow everiting goes good, but just in case verify data.success*/
},function(error){
    /* Wow something goes wrong, check the error.message */
})

来源: https://www.npmjs.com/package/cordova-zip-plugin

你可以

这样做:

$cordovaZip.unzip(
    '/templates/test.zip',
    cordova.file.dataDirectory + extracted_file_name
).then(
    function (data) {
      console.log('success', data);
    }
);