Last active
August 25, 2020 14:10
-
-
Save ozanturksever/4968827 to your computer and use it in GitHub Desktop.
python get uncompressed size of a .gz file
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_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 |
Hi @ozanturksever,
I think I am searching for exactly this functionality. I do have to know how large a file will be after decompressing and unpacking it. How come this coding does work and show me the same result as ?
> gzip -lv mongodb.tar
method crc date time compressed uncompressed ratio uncompressed_name
defla cfdff20d Mar 10 15:25 3037694 3102720000 99.9% mongodb.tar
How does this work?
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
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
taken from gzip.py