Skip to content
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

Decompress a typed array. #21

Closed
kapadia opened this issue Oct 3, 2012 · 2 comments
Closed

Decompress a typed array. #21

kapadia opened this issue Oct 3, 2012 · 2 comments

Comments

@kapadia
Copy link

kapadia commented Oct 3, 2012

Is there a way to decompress a typed array? After a file is read part of it is stored in a typed array. Portions of this typed array are gzip'ed. I would to input a typed array for decompression.

@gildas-lormeau
Copy link
Owner

Here are implementations of ArrayBuffer reader and writer

function ArrayBufferReader(arrayBuffer) {
    var that = this;

    function init(callback, onerror) {
        that.size = arrayBuffer.byteLength;
        callback();
    }

    function readUint8Array(index, length, callback, onerror) {
        callback(new Uint8Array(arrayBuffer.slice(index, index   length)));
    }

    that.size = 0;
    that.init = init;
    that.readUint8Array = readUint8Array;
}
ArrayBufferReader.prototype = new zip.Reader();
ArrayBufferReader.prototype.constructor = ArrayBufferReader;

function ArrayBufferWriter() {
    var array, that = this;

    function init(callback, onerror) {
        array = new Uint8Array();
        callback();
    }

    function writeUint8Array(arr, callback, onerror) {
        var tmpArray = new Uint8Array(array.length   arr.length);
        tmpArray.set(array);
        tmpArray.set(arr, array.length);
        array = tmpArray;
        callback();
    }

    function getData(callback) {
        callback(array.buffer);
    }

    that.init = init;
    that.writeUint8Array = writeUint8Array;
    that.getData = getData;
}
ArrayBufferWriter.prototype = new zip.Writer();
ArrayBufferWriter.prototype.constructor = ArrayBufferWriter;

There is a usage example here : https://github.com/gildas-lormeau/zip.js/blob/master/WebContent/tests/test18.js

@gildas-lormeau
Copy link
Owner

BTW, sorry for the late answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants