Created
November 21, 2014 22:21
-
-
Save tomislacker/14029f0259fe1d968a4f to your computer and use it in GitHub Desktop.
How to find out the uncompressed size of a .gz file without calling `gzip -l`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_gz_size(gzipfile): | |
f = open(gzipfile, "rb") | |
if f.read(2) != "\x1f\x8b": | |
raise IOError("not a gzip file") | |
f.seek(-4, 2) | |
return struct.unpack("<i", f.read())[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment