Git Product home page Git Product logo

Comments (11)

Progi1984 avatar Progi1984 commented on August 20, 2024 1

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);
    }

from pako.

puzrin avatar puzrin commented on August 20, 2024

All you need is to override default onData / onEnd handlers

https://github.com/nodeca/pako/blob/master/lib/deflate.js#L254

When slice input to chunks and send those with push()

Also, you can make wrapper to run pako in webworker when possible.

from pako.

puzrin avatar puzrin commented on August 20, 2024

Ah, even more simple - send input data bu chunks with push and update progress bar after each.

http://nodeca.github.io/pako/#Deflate.prototype.push

from pako.

Progi1984 avatar Progi1984 commented on August 20, 2024

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);

from pako.

puzrin avatar puzrin commented on August 20, 2024

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.

from pako.

puzrin avatar puzrin commented on August 20, 2024

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)

from pako.

Progi1984 avatar Progi1984 commented on August 20, 2024

@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

from pako.

Progi1984 avatar Progi1984 commented on August 20, 2024

@puzrin If I take the 4 last bytes, I can have the filesize before unzipping. How can I access to them ? Thanks for advance

from pako.

puzrin avatar puzrin commented on August 20, 2024

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.

from pako.

puzrin avatar puzrin commented on August 20, 2024

Yes. Just fix condition when last chunk size is exactly 16384. In your code it will be pushed with fasle

from pako.

puzrin avatar puzrin commented on August 20, 2024

Ups, sorry, seems there are no mistake,

from pako.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.