3 ms·
That doesn't explain why it's smaller than zip though.
by sp332 3y ago
That doesn't explain why it's smaller than zip though.
- tarr11 3y agoOP converted a Unicode file to an ascii file. Isn’t the loss of precision what is “compressing” the file? The Shakespeare corpus probably doesn’t use any Unicode characters.
- mbb70 3y agoA file cannot be 'Unicode'. Unicode is just a catalog of symbols one might want to express in writing. An encoding (like ASCII or UTF-8) describes how bytes are mapped to such symbols. ASCII only describes 128 characters whereas UTF-8 can represent any Unicode symbol in bytes. Notably though, UTF-8 is a strict superset of ASCII. That is, every character ASCII represents is represented by the same bytes in UTF-8. So encoding Romeo and Juliet in ASCII or UTF-8 results in the same exact file.
- TonyTrapp 3y agozlib offers multiple compression levels, and of course there are other deflate implementations as well. The Zip file might have been created with a different deflate implementation, or with different compression settings. Some PNG optimizers really take it to the extremes and brute-force the most optimal (or at least close to optiomal) deflate encoding, which is not something normal Zip tools usually do. PNG filters might also play a role in here, because the difference to the previous pixel row may be easier to encode than the ASCII text on its own (there are fewer and smaller delta values to encode).
- joshuanapoli 3y agoProbably the delta encoding step is occasionally useful. A lot of areas in the "document" are only going to use the 26 lowercase letters.
- edflsafoiewq 3y agoNope, every scanline uses filter type 0 (no filtering). Also the filesize decreases as you increase image width, presumably because you decrease the overhead of the filter bytes. I think the small size difference is just the difference in overhead of the framing formats (Zip encodes eg. local file headers and the central directory record) and compression options.
- lifthrasiir 3y agoMore concretely speaking, ZIP needs a base overhead of 22+ bytes, plus a per-file overhead of 76+ bytes plus twice the length of the file name. In comparison PNG needs only 64 bytes of overhead.