首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >获取64位平台上非常大的.gz文件的文件大小

获取64位平台上非常大的.gz文件的文件大小
EN

Stack Overflow用户
提问于 2009-12-27 17:18:57
回答 3查看 2.7K关注 0票数 7

根据gz规范,文件大小保存在.gz文件的最后4个字节中。

我已经创建了2个文件

代码语言:javascript
运行
复制
dd if=/dev/urandom of=500M bs=1024 count=500000
dd if=/dev/urandom of=5G bs=1024 count=5000000

我给他们上了拉链

代码语言:javascript
运行
复制
gzip 500M 5G

我检查了最后4个字节

代码语言:javascript
运行
复制
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

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2009-12-27 17:26:49

根本就没有。

获得压缩流的确切大小的唯一方法是实际解压它(即使您将所有内容都写入/dev/null并只计算字节数)。

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

ISIZE (输入大小)

它包含原始(未压缩)输入的大小

数据模数2^32。

在gzip RFC中,它实际上没有突破32位的界限,你看到的是预期的行为。

票数 8
EN

Stack Overflow用户

发布于 2009-12-27 17:24:36

我没有尝试过使用您提到的这种大小的文件,但我经常使用以下命令找到.gz文件的未压缩大小

代码语言:javascript
运行
复制
zcat file.gz | wc -c

当我不想留下未压缩的文件,或费心再次压缩它时。

显然,数据是未压缩的,但随后会通过管道传输到wc

不管怎么说,这值得一试。

编辑:当我尝试使用/dev/中的数据创建5G文件时,它生成了一个大小为5120000000的文件5G,尽管我的文件管理器报告为4.8G

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

然后,zcat 5G.gz | wc -c报告了与原始文件相同的大小: 5120000000字节。因此,我的建议似乎对这次试验起到了作用。

感谢您的等待

票数 3
EN

Stack Overflow用户

发布于 2013-10-18 04:15:25

gzip确实有一个-l选项:

代码语言:javascript
运行
复制
       -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.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1965567

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档