开发者

Is there a way to get the expanded gzip file size without actually expanding?

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 += I开发者_Python百科O.read(file_name, 1, original_size - i)[0] * (2**8) ** (4 - i)
end


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


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)?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜