据文件大小被保存在一个文件名为.gz的最后4字节的gz的specifiction。

我已创建了2个文件

dd if=/dev/urandom of=500M bs=1024 count=500000
dd if=/dev/urandom of=5G bs=1024 count=5000000

我gziped他们

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文件大小不提取它有谁知道?

感谢

规格: http://www.gzip.org/zlib/rfc-gzip。 HTML

编辑: 如果有人尝试一下,你可以使用/ dev /零代替的/ dev / urandom的

有帮助吗?

解决方案

没有一个。

要得到一个压缩流的确切大小的唯一方法是实际去解压它(即使你写的一切到/ dev / null的,只是算个字节)。

其值得注意的是ISIZE被定义为

  

ISIZE(输入大小),点击               这包含原始(未压缩)输入结果的大小               数据模2 ^ 32

在gzip的 RFC ,以便它实际上不是断裂在32位阻挡,你所看到的是预期的行为。

其他提示

我没有和你提到的大小的文件试过,但我经常发现的未压缩的名为.gz文件的大小

zcat file.gz | wc -c

当我不想离开未压缩文件躺在身边,或者懒得再压缩。

显然,数据是未压缩的,但是然后用管道输送到wc

这是值得一试,反正。

修改:当我试图创建一个文件5G与数据从/ dev /随机它产生尺寸51.2亿的一个文件5G,虽然我的文件管理器报告此作为4.8G

然后,我gzip 5G压缩它,结果5G.gz是相同的尺寸(没有太大压缩随机数据)。

然后zcat 5G.gz | wc -c报告大小与原始文件相同的:51.2亿个字节。所以我的建议似乎已经工作了这项试验,反正。

感谢等待

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.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top