What's the most that GZIP or DEFLATE can increase a file size?

拥有回忆 提交于 2019-12-05 04:31:00

gzip will add a header and trailer of at least 18 bytes. The header can also contain a path name, which will add that many bytes plus a trailing zero.

The deflate implementation in gzip has the option to store 16383 bytes per block, with an overhead of five bytes. It will always choose to do so if the alternative would take more bytes. So the maximum number of compressed bytes for n input bytes is:

Compressed files always have a header indicating how to decompress them.

The size of that header represents the worst case overhead when compressing a file that cannot be compressed (because there is no order/pattern to the data; it is random).

The header varies based on the specific algorithm, and may contain variable-length information as well such as a list of files in the archive.

GZip has at least 18 bytes of overhead (header + CRC-32 in the footer), and may contain optionally a list of files in the archive.

http://en.wikipedia.org/wiki/Gzip#File_format

Note that in special situations, custom compression algorithms can reduce or eliminate the header overhead. For example, I have used a custom compression dictionary known by the compressing and decompressing software to compress short texts, so that a header was not needed. That was a rather rare use case, and probably not useful in most situations (given that storage and bandwidth are relatively cheap).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!