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

Accessing contents of GZip file #50

Closed
jetsnguns opened this issue Feb 14, 2016 · 6 comments
Closed

Accessing contents of GZip file #50

jetsnguns opened this issue Feb 14, 2016 · 6 comments

Comments

@jetsnguns
Copy link

My use case is pretty simple: I have a single large csv file gzipped and I need to access it's contents as a string.
So far I understand that I need to start with:

jBinary.load(zipfile, GZIP).then(function (jb) {
    var data = jb.readAll();
    console.log(data);
    // future code for parsing csv
    console.log('Unzipping finished');
});

I'm stuck after that: what object is in data now? hot do I access the actual compressed data of the archive?

@RReverser
Copy link
Member

Can you show what you are getting when logging data? And which typeset where you using - this one https://github.com/jDataView/jBinary.Repo/blob/gh-pages/typeSets/gzip.js?

@jetsnguns
Copy link
Author

Yes, here it is:

Unzipping started
Object {_id1: 31, _id2: 139, compression: "Deflate", _reserved: 0, _hasComment: 0,_hasExtra: 0, hasHeaderCRC: 0, _hasName: 1, content: function(b), crc32: 1309749442, extraFlags: 0, input_size: 287, isText: 0, mod_time: Sat Feb 13 2016 03:16:11 GMT+0300 (Russia TZ 2 Standard Time), name: "dWA-compact-1.csvx", os: "FAT", __proto__: Object}
Unzipping finished

The file name of the archived file is correct, as well as byte size (287 byte unarchived).
I am using gzip.js with a slight modification to get rid of require.js. I use raw sources of inflate/deflate with it.

@RReverser
Copy link
Member

So yeah, as you can see from structure in that file, it should be in content property, except that decompression happens lazily for performance reason (so you need to call .content() to actually decompress data).

@jetsnguns
Copy link
Author

Yes, I tried that and it is not working - I receive an object instead of a string:

jBinary.load(zipfile, GZIP).then(function (jb) {

    var data = jb.readAll();

    var c = data.content();

    console.log(c);

    console.log('Unzipping finished');
});
Unzipping started
h {view: e, contexts: Array[0], typeSet: Object, cacheKey: "jBinary.Cache.3"}cacheKey: "jBinary.Cache.3"contexts: Array[0]typeSet: Objectview: e__proto__: h
Unzipping finished

@jetsnguns
Copy link
Author

Thanks for help.
I have finally figured it out: need to call .content().read('string').

@RReverser
Copy link
Member

@jetsnguns Yeah, sorry for not clarifying - it returns another jBinary into decompressed data to give you ability to work with it as regular file.

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