Skip to content

Instantly share code, notes, and snippets.

@tomislacker
Created November 21, 2014 22:21
Show Gist options
  • Save tomislacker/14029f0259fe1d968a4f to your computer and use it in GitHub Desktop.
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`
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