Live data from Hacker News

How are zlib, gzip and Zip related? (2013)

stackoverflow.com

21–30 of 145 posts

Re: How are zlib, gzip and Zip related? (2013)

#21

Not only is this a great read, but the follow up for citations is replied with "I am the reference". If this were reddit I'd post the hot fire gif. Eh, here it's anyway: http://i.imgur.com/VQLGJOL.gif

I thought he was joking.

Then I read the name: Adler: as in Adler-32 (the checksum function that zlib uses).

Then I knew it was real. The darn author of zlib answered the question. That's as close as you're gonna get to "primary source" folks!

Re: How are zlib, gzip and Zip related? (2013)

#22
post #17

It seems like it wouldn't be that hard to create an indexed tar.gz format that's backwards compatible. One way would be to use the last file in the tar as the index, and as files are added, you can remove the index, append the new file, append some basic file metadata and the compressed offset (maybe of the deflate chunk) into the index, update the index size in bytes in a small footer at the end of the index, and ap…

If I recall correctly and it's been a while: The initial header is x bytes from the beginning of the file, or that you have to search for a known key string PKsomething. Then you have to go back and forth between that and the compressed data as you decompress. When compressing files you have to go back to the beginning of the zip file ( or disk1 in a multi disk archive) and update that table with the CRC info. Just w…

Yeah, the above is with an assumption that the archive is in deflate's stream format. I'm not sure off the top of my head how gzip's different levels relate to that, or what tar defaults to when compressing as the tar is created compared to a full file tar compress after it's created.

Re: How are zlib, gzip and Zip related? (2013)

#23

Not only is this a great read, but the follow up for citations is replied with "I am the reference". If this were reddit I'd post the hot fire gif. Eh, here it's anyway: http://i.imgur.com/VQLGJOL.gif

I thought he was joking. Then I read the name: Adler: as in Adler-32 (the checksum function that zlib uses). Then I knew it was real. The darn author of zlib answered the question. That's as close as you're gonna get to "primary source" folks!

And then someone helpfully posted his wikipedia bio in a comment:

FYI: Mark Adler is an American software engineer, and has been heavily involved in space exploration. He is best known for his work in the field of data compression as the author of the Adler-32 checksum function, and a co-author of the zlib compression library and gzip. He has contributed to Info-ZIP, and has participated in developing the Portable Network Graphics (PNG) image format. Adler was also the Spirit Cruise Mission Manager for the Mars Exploration Rover mission. (wikipedia)

That's quite a résumé.

Re: How are zlib, gzip and Zip related? (2013)

#24

One important difference in practice is that zip files needs to be saved to disk to be extracted. gzip files on the other hand can be stream unzipped i.e curl http://example.com/foo.tar.gz | tar zxvf - is possible but not with zip files. I am not sure if this is a limitation of the unzip tool. I would love to know if there is a work around to this.

You can't do that with a .zip file because the file header information is actually at the end of the file. You could work around that by sending the header first, though.

How do you send the header first? Is that a feature of the http framework?

Re: How are zlib, gzip and Zip related? (2013)

#25
post #17

It seems like it wouldn't be that hard to create an indexed tar.gz format that's backwards compatible. One way would be to use the last file in the tar as the index, and as files are added, you can remove the index, append the new file, append some basic file metadata and the compressed offset (maybe of the deflate chunk) into the index, update the index size in bytes in a small footer at the end of the index, and ap…

If I recall correctly and it's been a while: The initial header is x bytes from the beginning of the file, or that you have to search for a known key string PKsomething. Then you have to go back and forth between that and the compressed data as you decompress. When compressing files you have to go back to the beginning of the zip file ( or disk1 in a multi disk archive) and update that table with the CRC info. Just w…

That can't be the case anymore because I implemented a streaming function a few years back that sends an unlimited number of files as a zip, but builds the zip on the fly streaming it to the client. Maybe it works because I am not using compression (files in my case are all JPG and/or compressed video so there is little benefit). But my process definitely starts streaming the zip right away and has to pull URLs on the fly to create the zip file.

Re: How are zlib, gzip and Zip related? (2013)

#26
post #13

Earlier quoted context omitted.

The accepted answer is often wrong (or obsolete) and grants a small number of points. The obsession with it on SO is a bit odd.

Yeah I tend to think if another answer has double the points of an accepted answer, that answer should come first.

Plus, often there is a decent and accepted answer given quickly and then a much more complete answer given later on that is really the one that should be considered in the archive.

Re: How are zlib, gzip and Zip related? (2013)

#27

Where do the other popular compression utilities (e.g. bzip2, xzip, lzma, 7zip) fit in to this?

The big picture is that there's a few compression algorithms.

Run Length Encoding

Huffman Encoding

Lempel Ziv (LZ77)

Burrows Wheeler Transform

The interesting part of all these specific implementations is their own specialized way of extending or combining these algorithms for their own niche (or tradeoff point).

Bzip2 is for example, compresses really well because BWT is expensive, but clever - rzip extends the LZ part of bzip2 to look further across the file (instead of a few hundred kb).

Zlib itself has enough of these flags exposed out, so all Zlib isn't really the same - Z_FILTERED, Z_HUFFMAN_ONLY, Z_FIXED, Z_RLE etc. Look at something like Zopfli to see how they can be remixed, provided the tradeoffs of CPU change from the historic positions of Zlib.

Re: How are zlib, gzip and Zip related? (2013)

#28

One important difference in practice is that zip files needs to be saved to disk to be extracted. gzip files on the other hand can be stream unzipped i.e curl http://example.com/foo.tar.gz | tar zxvf - is possible but not with zip files. I am not sure if this is a limitation of the unzip tool. I would love to know if there is a work around to this.

You can't do that with a .zip file because the file header information is actually at the end of the file. You could work around that by sending the header first, though.

You can't put the header first. It is an intentional feature of .zip that the header is at the end so you can update a large zip file by just appending a new header to the end. That way the entire file does not have to be rewritten. Just read the old header, append new files, append new header. This was important back in floppy disk days

Re: How are zlib, gzip and Zip related? (2013)

#29

Not only is this a great read, but the follow up for citations is replied with "I am the reference". If this were reddit I'd post the hot fire gif. Eh, here it's anyway: http://i.imgur.com/VQLGJOL.gif

I thought he was joking. Then I read the name: Adler: as in Adler-32 (the checksum function that zlib uses). Then I knew it was real. The darn author of zlib answered the question. That's as close as you're gonna get to "primary source" folks!

Plus his profile lists http://zlib.net as his personal page
Post reply on HN