uncompressed size of .gz file
frankabel
frankabel at tesla.cujae.edu.cu
Mon Sep 20 01:32:21 EDT 2004
Thank to Fredrik Lundh and Cousin Stanley.
I had a similar solution of Cousin Stanley:
import commands
status, output = commands.getstatusoutput('gunzip -l ' +
name_of_gz_file)
if not status:
long(filter(None, output.splitlines()[1].split(' '))[1])
but the problem of this kind of solutions is that depend of
the OS(some OS not have gunzip command), for this reason I
make the question.
However solution of Fredrik Lundh is totally OS unaware.
Just a question: in line "return struct.unpack("<i", f.read())[0]"
I think that better will be "<I" instead "<i", but you are the guru :),
please tell me if I'm wrong.
Thank for all.
Frank Abel
-----Mensaje original-----
De: python-list-bounces+frankabel=tesla.cujae.edu.cu at python.org
[mailto:python-list-bounces+frankabel=tesla.cujae.edu.cu at python.org] En
nombre de Fredrik Lundh
Enviado el: Sunday, September 19, 2004 1:35 AM
Para: python-list at python.org
Asunto: Re: uncompressed size of .gz file
"frankabel at tesla.cujae.edu.cu" wrote:
> What python function give me the uncompressed size of .gz file like
> "gzip -l name_of_compress_file".
the size is stored as a 32-bit integer at the end of the file. to get
it, you
can use something like:
def getsize(gzipfile):
import struct
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]
usage:
>>> print getsize("Python-2.4a3.tgz")
38758400
hope this helps!
</F>
--
http://mail.python.org/mailman/listinfo/python-list
__________________________________________
Aniversario 40 de la CUJAE
Visite:
XII Convencion de Ingenieria y Arquitectura
http://www.cujae.edu.cu/eventos/convencion/
More information about the Python-list
mailing list