MobileChromeApps / cordova-plugin-zip

Zip plugin for Cordova apps
Other
168 stars 207 forks source link

Progress Event Callback does not give correct value of loaded #35

Open limmouyleng opened 10 years ago

limmouyleng commented 10 years ago

The unzip function works fine. However, it doesnot work with the progress event. It provides the wrong value of loaded.

mmocny commented 10 years ago

Its worked for us.. may you please provide a gist or zip of your simple app that exhibits this behaviour so that we can address the issue better?

limmouyleng commented 10 years ago

Here is the code:

zip.unzip(source, destination, function() { alert("unzip success"); }, function(progressEvent) { var perc = Math.round((progressEvent.loaded / progressEvent.total) * 100); progressBar.setValue('#slider', perc); $("span#progressText").text("processing : " + perc + '%'); });

var progressBar = { setValue: function(id, value) { $(id).val(value); $(id).slider("refresh"); } };

limmouyleng commented 10 years ago

Can you help me with this problem? If you do not understand with my code, please let's me know.

mmocny commented 10 years ago

Indeed, something is up!

Just tried it and I get negative progress events: Object {loaded: -895, total: 30139425}, which happened to appear to be 0% after the math provided in the readme example, and jumping directly to 100% when done.

Tracking this down now.

mmocny commented 10 years ago

One quick note: zip plugin has tests, one of which tests progress, and it seems to work and pass fine.

The progress does reach 99% and stall for a bit but that likely is just be a result of unzip implementation itself.

I'm going to see whats different about the testcase I had come up with.

mmocny commented 10 years ago

More details: The progress events either work/not depending on the input zip file used! Not sure how the zips differ, or if the problem is due to actual unzip implementation, specific file contents, or something silly like math errors depending on file size.

tvervest commented 10 years ago

I'm experiencing the same issue (negative value of the loaded property on the progress event). Note that (in our case) the problem only occurs on Android (4.1.2), but not on iOS (7.1), using the same code base.

AleZork commented 10 years ago

Unfortunately I've the issue on a Nexus 4 (4.4.2). With an 150mb zip file.

Thanks for your work

Alessandro

AleZork commented 10 years ago

I've noticed something that could be intersting: the loaded property gives negative values to me too, but those values seems to reflect the number of files unpacked. In my case i have a zip containing 3071 images and the loaded property goes from 0 to -3071.

Alessandro

mmocny commented 10 years ago

That is interesting. Its a busy week for us, but hopefully I can take a look next week. Please do share any more discoveries.

macdonst commented 9 years ago

It's a problem with Java and not the plugin. Somewhere in there they are using an int which overflows on large files.

danicarla commented 7 years ago

Hi... I try use this code but I do not know what name I should put in my div I try with <span id="slider"></span> and <span id="progressBar"></span>

What am I doing wrong?

sport4minus commented 6 years ago

Hey everybody, i am backing up @mmocny on this one. It is a problem with the zip file. The plugin calls[ ZipEntry.getCompressedSize()](https://developer.android.com/reference/java/util/zip/ZipEntry.html#getCompressedSize()). In the documentation it says that the function returns -1 if the file size is not known. I tried with a zip i created using OSX' built-in "compress" option, this gave me -1 per file, so a negative progress. I used an alternative tool on the same files, this worked fine. There should be some "computable = true/false" flag, as exists in the file transfer plugin for cordova.

qroft commented 5 years ago

I am also having the trouble on showing the percent not only on certain ZIP files but also on different devices, depending on how quick they work. I my case, i have several ZIP files of around 100 MB - they are downlaoded via the File Transfer plugin and once downloaded unzip with this plugin. The unzipping works perfectly as i can check by refreshing every second with Total Commander to see the files inside my folder, but the progress does notw work on my older tablet. On my new smartphone everything works as expected.