jjdltc / jjdltc-cordova-plugin-zip

A plugin to zip and unzip files or directories
MIT License
23 stars 25 forks source link

Added browser support. #11

Closed fefc closed 5 months ago

fefc commented 5 years ago

Ability to zip and unzip with JSZip library (https://github.com/Stuk/jszip).

jjdltc commented 4 years ago

Hi there @fefc,

Sorry for the delay and thanks for the contribution. I try to test this but didn't figure out how to. Any suggestions (I'm using browser platform and try with both, input file and absolute paths)

pawelzwronek commented 4 years ago

I think this implementation is based on chrome's only api https://developer.mozilla.org/en-US/docs/Web/API/Window/requestFileSystem

fefc commented 4 years ago

Hi @jjdltc ,

I used the code this way:

JJzip.zip(this.file.dataDirectory + 'toZipDirectory', {target: this.file.cacheDirectory, name: 'zipName'}, (data) => {
 if (data.success) {

} else {

}

}, (error) => {

});

Based on the File Plugin (https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/)

this.file.dataDirectory => localhost/persistant this.data.cacheDirectory => localhost/temporary

So the content of 'toZipDirectory' will be at localhost/temporary/zipName.zip. I doubt you can access the zip trough the url because of security implementations on web browsers.

However you could use the fileOpener Plugin (https://github.com/pwlin/cordova-plugin-file-opener2) where I implemented the Browser version with following code:

        this.fileOpener.open(this.file.cacheDirectory + 'zipName' + '.zip', 'application/zip').then(() => {
        }).catch((error) => {
          alert("Something went wrong while exporting: " + error);
        });

Which will open a download dialog where you can get the zip.

At time of coding zip/unzip where working on Firefox and Safarai. Chrome has permission issues so it doesn't work properly.

Does that helps in any point?