Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

It's well known that GZIP or DEFLATE (or any compression mechanism) can increase file size sometimes. Is there a maximum (either percentage or constant) that a file can be increased? What is it?

If a file is X bytes, and I'm going to gzip it, and I need to budget for file space in advance - what's the worst case scenario?

UPDATE: There are two overheads: GZIP adds a header, typically 18 bytes but essentially arbitrarily long. What about DEFLATE? That can expand content by a multiplicative factor, which I don't know. Does anyone know what it is?

like image 313
SRobertJames Avatar asked May 09 '14 18:05

SRobertJames


People also ask

Can gzip increase size?

Yes, it can. It has been fixed in . NET 4. The compression algorithms for the System.

How much does gzip reduce file size?

Gzip, the most popular compression method, is used by web servers and browsers to seamlessly compress and decompress content as it's transmitted over the Internet. Used mostly on code and text files, gzip can reduce the size of JavaScript, CSS, and HTML files by up to 90%.

What is the average compression ratio for gzip?

Gzip has a high compression ratio around 95% with CSV and JSON.

What is gzip size?

"gzip" is often also used to refer to the gzip file format, which is: a 10-byte header, containing a magic number ( 1f 8b ), the compression method ( 08 for DEFLATE), 1-byte of header flags, a 4-byte timestamp, compression flags and the operating system ID.


1 Answers

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:

n+5(floor(n/16383)+1)

like image 113
Mark Adler Avatar answered Oct 20 '22 18:10

Mark Adler