jszip
jszip copied to clipboard
Zipping paused when other tabs are open
I want to use JSZip to zip max 1000 images from an array of urls. The max size of images could be 5 GB. Till now I have just zipped 2 GB. I am facing two problems :
- When I open new tab on browser or work on other software(maximized to full screen) then zipping pauses and as I go to that tab it resumes again.
- When I tested it with 1000 urls, sized 1.9 GB, it zipped normally but when it came to download my browser (chrome ) was not responding and my PC was slowed down too. Though it downloaded zip file after a while. It is not the case when I zip small sizes.
Here is what code I am using
var zip = new JSZip();
var count = 0;
var imageUrl= [
'https://image-url-1',
'https://image-url-2',
'https://image-url-3'
];
imageUrl.forEach(function(image){
var filename = "filename";
// loading a file and add it in a zip file
JSZipUtils.getBinaryContent(image, function (err, data) {
if(err) {
throw err; // or handle the error
}
zip.file(filename, data, {binary:true});
count++;
if (count == imageUrl.length) {
zip.generateAsync({type:'blob'}).then(function(content) {
saveAs(content, "ZippedImages.zip");
});
}
});
});
Related to JSZip v3.5.0. Humm I have a different behaviour to report. JSZip doesn't download if the tab is not in the foreground. As soon as I bring the tab to the focus/foreground it starts downloading the zip. Having other tab opened doesn't create any problem.
Related to JSZip v3.5.0. Humm I have a different behaviour to report. JSZip doesn't download if the tab is not in the foreground. As soon as I bring the tab to the focus/foreground it starts downloading the zip. Having other tab opened doesn't create any problem.
I actually wanted to say this when I said "working on other software"
@miniGweek I see a similar problem (zip doesn't work when browser is not in foreground) but it occurs in 3.2.0 That is: jszip version 3.1.5 does not show the problem, version 3.2.0 does. I suspect it has something to do with the web.immediate module being removed. However, I have no idea what that module is.
@miniGweek
I see a similar problem (zip doesn't work when browser is not in foreground) but it occurs in 3.2.0
That is: jszip version 3.1.5 does not show the problem, version 3.2.0 does.
I suspect it has something to do with the web.immediate module being removed. However, I have no idea what that module is.
ok thanks. will try that out!
@miniGweek, @stuk More information, I think web.immediate is provides a stub for https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate. According to docs "This method is used to break up long running operations and run a callback function immediately after the browser has completed other operations such as events and display updates".
Anyway, with version 3.7.1 if I change https://github.com/Stuk/jszip/blob/3f2f0da8b29c2477bca982911caa8392679c13b2/lib/utils.js#L379-L383
to this (i.e. Ignore setImmediate, because in my context it's already running a Promise)
exports.delay = function(callback, args, self) {
callback.apply(self || null, args || []);
};
it works for me
@miniGweek @abkn9977 Workaround I was given by @Synteresis, is to polyfill setImmediate() before loading the jszip library e.g.
window.setImmediate = (fn) => {fn();};
It works in my case, because I'm already calling jszip inside a Promise.
I am still facing that issue. Zipping pauses when I switch to another tab.
is there any solution?
@liudaohui404 As I said above, polyfill setImmediate() works, provided you're already calling jszip inside a Promise.
@liudaohui404 As I said above, polyfill setImmediate() works, provided you're already calling jszip inside a Promise.
I apologize for the confusion. I forgot to mention my usage environment. I am using jszip in a Node environment. When my app is minimized, I cannot unzip files, but it works fine when the window is restored. Is this situation similar to yours?
@liudaohui404 I'm running in a Chrome extension. So, somewhat similar. You could try the pollyfill approach.