Live data from Hacker News

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

stackoverflow.com

61–70 of 145 posts

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

#63

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.

In fact .zip file contains file header information twice: before every compressed file (local file header) and at the end of the .zip file (central directory). It's possible to omit file size in local file header, but most most compressing utilities doesn't use this option. So most .zip files could be extracted without seeking to the end.

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

#64
post #55

In other compression news, Apple open sourced their implementation of lzfse yesterday: https://github.com/lzfse/lzfse . It's based on a relatively new type of coding - asymmetric numeral systems. Huffman coding is only optimal if you consider one bit as the smallest unit of information. ANS (and more broadly, arithmetic coding) allows for fractional bits and gets closer to the Shannon limit. It's also simpler to impl…

Strange that Apple didn't publish it on https://github.com/apple (which holds all of their open Swift repos).

Also, to clarify, ANS is relatively new (2009) but arithmetic coding has been around for a long time. Historically it was avoided because of patents, many (all?) of which have now expired. Apparently ANS isn't going to be patented.

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

#65

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

Neat how involved he still is this long after the initial work. When brotli came out he implemented his own decoder ( https://github.com/madler/brotli/ ) to check the spec, and got some things clarified in RFC. Brotli is pretty DEFLATE-y in spirit, with changes that take advantage of today's hardware (larger history window, contexts in the entropy encoding) and a bunch of tweaks (different match encoding, static dict…

On the other hand he isn't making new zlib versions. There are a lot of patches posted on the mailing list going nowhere. Also there's a valgrind issue I reported that he ignored.

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

#66
post #64
post #55

In other compression news, Apple open sourced their implementation of lzfse yesterday: https://github.com/lzfse/lzfse . It's based on a relatively new type of coding - asymmetric numeral systems. Huffman coding is only optimal if you consider one bit as the smallest unit of information. ANS (and more broadly, arithmetic coding) allows for fractional bits and gets closer to the Shannon limit. It's also simpler to impl…

Strange that Apple didn't publish it on https://github.com/apple (which holds all of their open Swift repos). Also, to clarify, ANS is relatively new (2009) but arithmetic coding has been around for a long time. Historically it was avoided because of patents, many (all?) of which have now expired. Apparently ANS isn't going to be patented.

Question not about ANS, but patenting: Wouldn't it make more sense for Apple (or anybody) to actually patent it, and keep those patents, but make it open via licensing ? If there's patentable material and $developer passes on filing for it, doesn't that leave it open for poaching by $third_party ?

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

#67

Earlier quoted context omitted.

>> Just read the old header, append new files, append new header. This was important back in floppy disk days Don't forget 'overwrite old header' Important for floppy disks in two ways, one because of space constraints and two, because of how slow floppies were.

Don't forget 'overwrite old header' Why? The new one will become the 'real' one since it will be at the end of the modified file. So it doesn't really matter if you delete the old one. If you're really trying to squeeze file sizes down, you could reference the old 'header' from the new one, so that you do not have to list the entire archive's contents again.

Having written code to extract files from a ZIP file, it's because the header is variable sized, anywhere from 22 to 65,557 bytes in size (22 bytes fixed, up to 65,535 bytes for a comment). There are two ways to scan for the header, one is to seek just 22 bytes shy of the end of the file and start checking backwards (since the majority of ZIPs I've encountered do not have the comment) or, seek 65,557 bytes from the end and scan forward.

This fact has been used to construct pathological ZIP files where one tool will report one list of files and another tool will list a different set of files. That's why you really need to overwrite the old header.

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

#69
post #3

It's annoyingly common how the OP doesn't mark this answer as accepted, or even acknowledge how amazing this answer is from one of the technology's creators -- instead just goes on to ask a followup.

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.

In the vast majority of cases the accepted answer is the most upvoted answer http://meta.stackexchange.com/questions/178439/can-we-exempt...

But then again: the most upvoted answer doesn't mean that it is the most correct (whatever it means) one. Though likely it is.

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

#70

But can he invert a binary tree and is he willing to relocate to San Francisco?

What does "invert a binary tree" mean?

Other people have explained the reference, but as for what it means: AFAIK it basically means to produce a binary tree with the same values but with parent-child relationships reversed.
Post reply on HN