tags:

views:

82

answers:

2

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
+1  A: 

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

Yuliy
+1  A: 

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

bryantsai