Skip to content

Instantly share code, notes, and snippets.

@ozanturksever
Last active August 25, 2020 14:10
Show Gist options
  • Save ozanturksever/4968827 to your computer and use it in GitHub Desktop.
Save ozanturksever/4968827 to your computer and use it in GitHub Desktop.
python get uncompressed size of a .gz file
def get_uncompressed_size(self, file):
fileobj = open(file, 'r')
fileobj.seek(-8, 2)
crc32 = gzip.read32(fileobj)
isize = gzip.read32(fileobj) # may exceed 2GB
fileobj.close()
return isize
@webysther
Copy link

webysther commented Oct 1, 2018

@fabianschwarzfritz

def get_uncompressed_size(file):
    pipe_in = os.popen('gzip -l %s' % file)
    list_1 = pipe_in.readlines()
    list_2 = list_1[1].split()
    c , u , r , n = list_2
    return int(u)

Source: https://bytes.com/topic/python/answers/36089-uncompressed-size-gz-file

@nerohmot
Copy link

import gzip

def get_uncompressed_size(FileName):
    with gzip.open(FileName, 'rb') as fd:
        fd.seek(0, 2)
        size = fd.tell()
    return size

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment