有没有办法在不实际扩展的情况下获得扩展后的 gzip 文件大小?

发布于 2024-08-17 05:24:31 字数 366 浏览 2 评论 0原文

由于扩展一个大的 gzip 文件需要相当长的时间(有时超过半分钟),因此我想在开始扩展之前知道扩展后的大小(用于进度报告目的)。有没有一种方法可以在不实际扩展的情况下了解它?

更新

对于大于 4G 字节(扩展大小)的文件,如果不实际扩展 gzip 文件,则无法确定其大小。然而,对于小于 4G 字节(扩展大小)的文件,实际扩展大小存储为 gzip 文件的最后 4 个字节,并且可以轻松检索:

(1..4).inject(0) do |v, i| 
  v += IO.read(file_name, 1, original_size - i)[0] * (2**8) ** (4 - i)
end

Since expanding a large gzip file takes quite long time (sometimes over half a minute), I'd like to know the expanded size before I start the expansion (for progression report purpose). Is there a way of knowing it without actually expanding?

Update:

For file larger than 4G bytes (expanded size), there's no sure way of knowing the size without actually expanding the gzip file. However, for files smaller than 4G bytes (expanded size), the actual expanded size is stored as the last 4 bytes of the gzip file and could be retrieved easily:

(1..4).inject(0) do |v, i| 
  v += IO.read(file_name, 1, original_size - i)[0] * (2**8) ** (4 - i)
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撩心不撩汉 2024-08-24 05:24:32

只是想结束这个问题,因为我已经找到了解决方案。上面已经更新了。

Just want to close this question as I've found the solution. Have updated it above.

记忆之渊 2024-08-24 05:24:32

我认为您无法获得确切的大小,因为这需要知道文件中各种字符串的实际频率,并且如果不扫描文件就无法做到这一点。您能否进入实际的解压函数并让它指示输入的距离(与输出的距离)?

I don't think you can get an exact size, as that would require knowing the actual frequencies of various strings in a file, and you can't do that without scanning the file. Can you go into the actual decompression function and have it indicate how far through the input it is (vs how far into the output it is)?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文