-
-
Notifications
You must be signed in to change notification settings - Fork 784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Progress bar (feature request) #42
Comments
All you need is to override default https://github.com/nodeca/pako/blob/master/lib/deflate.js#L254 When slice input to chunks and send those with Also, you can make wrapper to run pako in webworker when possible. |
Ah, even more simple - send input data bu chunks with push and update progress bar after each. |
Hi @puzrin, I'm interested by creating a progress bar when deflating a GZip file : I can increment the number of chunks. But how can i have the number of chunks before deflating. var binData = new Uint8Array(e.target.response);
var oPako = new pako.Inflate();
console.log("ungzip > binData.length", binData.length);
var iNumberChunks = 0;
oPako.onData = function(chunk){
iNumberChunks += 1;
// parent.onData()
this.chunks.push(chunk);
};
oPako.push(binData, true);
if (oPako.err) {
throw new Error(oPako.err);
}
console.log("ungzip > iNumberChunks", iNumberChunks);
var uInt8Array = new Uint8Array(oPako.result); |
Not sure that understand your question. Only you can decide how to split your data to chunks, how to push those to deftator instance and what to do between. |
Ah, if you asked about output chunks - you can't predict it, because it depends on content. You can only set chunk size (but i don't recomment to vary), and new chunk will be generated each time when buffer filled. Or when you finish (last data will be flushed) |
@puzrin I try to have in my onData a percent of the deflating operation. So I must to have a number of chunks current and a number of chunks total for calculating the percent. Is it possible to estimate the size of buffer ? Link : http://www.abeel.be/content/determine-uncompressed-size-gzip-file |
@puzrin If I take the 4 last bytes, I can have the filesize before unzipping. How can I access to them ? Thanks for advance |
You try to use wrong approach. Bind progress bar on input chunks, not on output chunks. Input size is known, split it as you wish, and calculate percent after each chunk push. If you push input data with one big peace, deftator/inflator will slice it anyway, but you will not have progress info. |
Thanks for your help : var binData = new Uint8Array(e.target.response);
var oPako = new pako.Inflate();
for (var i = 0; i < binData.length; i += 16384) {
if((i + 16384) >= binData.length){
oPako.push(binData.subarray(i, i + 16384), true);
} else {
oPako.push(binData.subarray(i, i + 16384), false);
}
}
if (oPako.err) {
throw new Error(oPako.err);
} |
Yes. Just fix condition when last chunk size is exactly 16384. In your code it will be pushed with |
Ups, sorry, seems there are no mistake, |
I found no way to make pako report its progress. That's an issue because browser lags for several seconds when the page is being loaded. Could you add some callbacks, please?
The text was updated successfully, but these errors were encountered: