Decompress gzip data without header using Node.JS zlib module - node.js

I have a binary data which is a GZIP compressed string. Both header and footer are absent, but the string is otherwise correct. I verified this by using Node.js zlib.gzip() to compress the same string and then comparing the two binary files.
Is it possible to use zlib library to uncompress files without header and footer?

I think you want zlib.inflateRaw() and friends.

Related

How to Generate and Verify Checksum of a file without downloading the file in Node JS

Is there a way to generate a checksum of an mp3 file without downloading it?
I am using the crypto library, but it seems that I have to download the file.
Since a "checksum" is a value derived from a collection of data, you'd need a copy of those data to be able to generate the checksum.

Parse bytes of a zip file?

I am requesting a zip file from an API and I'm trying to retrieve it by bytes range (setting a Range header) and then parsing each of the parts individually. After reading some about gzip and zip compression, I'm having a hard time figuring out:
Can I parse a portion out of a zip file?
I know that gzip files usually compresses a single file so you can decompress and parse it in parts, but what about zip files?
I am using node-js and tried several libraries like adm-zip or zlib but it doesn't look like they allow this kind of possibility.
Zip files have a catalog at the end of the file (in addition to the same basic information before each item), which lists the file names and the location in the zip file of each item. Generally each item is compressed using deflate, which is the same algorithm that gzip uses (but gzip has a custom header before the deflate stream).
So yes, it's entirely feasible to extract the compressed byte stream for one item in a zip file, and prepend a fabricated gzip header (IIRC 14 bytes is the minimum size of this header) to allow you to decompress just that file by passing it to gunzip.
If you want to write code to inflate the deflated stream yourself, I recommend you make a different plan. I've done it, and it's really not fun. Use zlib if you must do it, don't try to reimplement the decompression.

md5 different after decompressing the file and compressing it again

Host: Ubuntu 14.04
Command md5sum
File size: Before/After decompressing: 77.8 M - 323.9
I downloaded the file from Ubuntu official website.
Where I download it from ( device.tar.xz )
Before decompressing the file, I use md5sum to generate the md5 number for this compressed file.
After this, I decompressed the file, however, I dont modify any content inside. And then I re-compressed the file ( device2.tar.xz ).
By comparing two md5 number, it is different. I doubt my decompression may cause something changed.
Is there anyway to ensure that the content will be exactly the same after re-compressing ?
Thanks
You're hashing two different compressed representations of the same uncompressed data.
The xz file format includes some meta-data, which you can see with xz -l foo.xz. So even if you used the same version of the same compression program with the same settings, you could get output files that weren't byte-for-byte identical.

How to add zip file without compression using node.js?

I am converting docx to epub using pandoc. After converting epub, i do changes with zip file and converting epub also. At that time,
I got the following issue after converting zip file to epub on mimetype file.
Mimetype contains wrong type (application/epub+zip expected).
I am searching a lot and get two logic
First one e.g., extra spaces, new line characters but it was going vain(there is no extra spaces, new line).
Add the mimetype file without compression in zip.
I am getting struck with second point. How to add mimetype file without compression in zip using node.js coding.
var archiver = require('archiver');
var archive = archiver('zip');
archive.file('d:\\xxxx'+'\\mimetype', { name:'mimetype'});
What is the problem in the above code and any attribute for zip?
Can any one assist me for adding file without compression in zip?
Thanks in advance.
add the zip option {store:true} for without compression
https://www.npmjs.com/package/archiver#store-boolean

Zip in j2me using jazzlib

I am using jazzlib package in j2me application to compress the xml file in zip format using ZipOutputStream and the send the compress stream to the server as a string . I am able to do unzip the in mobile using ZipInputStream. But in server i am not able to unzip , i got
EOF exception. when i copy the compressed stream from console and put into browser, the empty space put special character like [] in compressed stream. I didnt understand what happened. Plz help
You send the compressed stream as a String? That's your problem(s) right there:
compressed data is binary data (i.e. byte[]).
String is designed to handle textual (Unicode) data and not arbitrary binary data
converting arbitrary binary data to String is bound to lead to problems
So if you want to handle (send/receive/...) binary data, make sure you never use a String/Reader/Writer to handle the data anywhere in the process. Stay with byte[]/InputStream/OutputStream.

Resources