根据gz规范,文件大小保存在.gz文件的最后4个字节中。
我已经创建了2个文件
dd if=/dev/urandom of=500M bs=1024 count=500000
dd if=/dev/urandom of=5G bs=1024 count=5000000
我给他们上了拉链
gzip 500M 5G
我检查了最后4个字节
tail -c4 500M|od -I (returns 512000000 as expected)
tail -c4 5G|od -I (returns 825032704 as not expected)
似乎命中不可见的32位屏障,使得写入ISIZE的值完全没有意义。这比他们使用一些错误比特更烦人。
有没有人知道一种不用解压就能从.gz中获取未压缩的.gz文件大小的方法?
谢谢
规格:http://www.gzip.org/zlib/rfc-gzip.html
编辑:如果有人想尝试一下,可以使用/dev/zero而不是/dev/urandom
发布于 2009-12-27 17:26:49
根本就没有。
获得压缩流的确切大小的唯一方法是实际解压它(即使您将所有内容都写入/dev/null并只计算字节数)。
值得注意的是,ISIZE被定义为
ISIZE (输入大小)
它包含原始(未压缩)输入的大小
数据模数2^32。
在gzip RFC中,它实际上没有突破32位的界限,你看到的是预期的行为。
发布于 2009-12-27 17:24:36
我没有尝试过使用您提到的这种大小的文件,但我经常使用以下命令找到.gz文件的未压缩大小
zcat file.gz | wc -c
当我不想留下未压缩的文件,或费心再次压缩它时。
显然,数据是未压缩的,但随后会通过管道传输到wc
。
不管怎么说,这值得一试。
编辑:当我尝试使用/dev/中的数据创建5G文件时,它生成了一个大小为5120000000的文件5G
,尽管我的文件管理器报告为4.8G
然后我用gzip 5G
压缩它,结果5G.gz
是相同的大小(没有太多的随机数据压缩)。
然后,zcat 5G.gz | wc -c
报告了与原始文件相同的大小: 5120000000字节。因此,我的建议似乎对这次试验起到了作用。
感谢您的等待
发布于 2013-10-18 04:15:25
gzip确实有一个-l选项:
-l --list
For each compressed file, list the following fields:
compressed size: size of the compressed file
uncompressed size: size of the uncompressed file
ratio: compression ratio (0.0% if unknown)
uncompressed_name: name of the uncompressed file
The uncompressed size is given as -1 for files not in gzip format, such as compressed .Z files. To
get the uncompressed size for such a file, you can use:
zcat file.Z | wc -c
In combination with the --verbose option, the following fields are also displayed:
method: compression method
crc: the 32-bit CRC of the uncompressed data
date & time: time stamp for the uncompressed file
The compression methods currently supported are deflate, compress, lzh (SCO compress -H) and pack.
The crc is given as ffffffff for a file not in gzip format.
With --name, the uncompressed name, date and time are those stored within the compress file if
present.
With --verbose, the size totals and compression ratio for all files is also displayed, unless some
sizes are unknown. With --quiet, the title and totals lines are not displayed.
https://stackoverflow.com/questions/1965567
复制相似问题