GZIP或DEFLATE最多可以增加文件大小? [英] What's the most that GZIP or DEFLATE can increase a file size?

查看:122
本文介绍了GZIP或DEFLATE最多可以增加文件大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,GZIP或DEFLATE(或任何压缩机制)有时可以增加文件大小.是否可以增加文件的最大值(百分比或常数)?什么事?

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?

如果文件是X字节,并且我要对其进行gzip压缩,则需要提前预算文件空间-最坏的情况是什么?

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?

更新:有两个开销:GZIP添加了一个标头,通常为18个字节,但本质上是任意长的.那DEFLATE呢?这可以通过一个乘数来扩展内容,我不知道.有人知道这是什么吗?

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?

推荐答案

gzip将添加至少 18个字节的标头和结尾.标头还可以包含路径名,该路径名将添加那么多字节加尾随零.

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.

gzip中的deflate实现可以选择每个块存储16383个字节,开销为5个字节.如果替代方案将占用更多字节,它将始终选择这样做.因此, n 个输入字节的最大压缩字节数为:

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:

这篇关于GZIP或DEFLATE最多可以增加文件大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆