| Store | Cart

gzip and file size

From: ToddW <taw_...@yahoo.com>
6 Nov 2001 08:28:20 -0800
Martin von Loewis <loewis at informatik.hu-berlin.de> wrote in message news:<j4u1w89rig.fsf at informatik.hu-berlin.de>...
> taw_usenet at yahoo.com (ToddW) writes:> > > It's simple to get the correct file size for a file. But if it is> > gzipped, is there a simple way to snag the file size of the> > uncompressed file?> > The last four bytes of the file contain the uncompressed size, unless> the file is corrupted. If the compressed file was created by> contatenating multiple compressed files, you can obtain the true> uncompressed size only by uncompressing the entire file.> > Regards,> Martin

Hey thanks. As I am using python 1.5.2 this was the answer I needed.
And here's my iittle function for those interested (notice the format
is little endian BTW):

def gzipFileSize(filename):
    """return UNCOMPRESSED filesize of a gzipped file.
    """
    fo = open(filename, 'rb')
    fo.seek(-4, 2)
    r = fo.read()
    fo.close()
    return struct.unpack('<I', r)[0]

Thanks for all of your replies. The references to getinfo, etc., applies to
python 2+.

Recent Messages in this Thread
ToddW Nov 05, 2001 11:34 pm
William Park Nov 06, 2001 12:07 am
Steve Holden Nov 06, 2001 02:29 am
Martin von Loewis Nov 06, 2001 09:29 am
ToddW Nov 06, 2001 04:28 pm
Messages in this thread