Grupos de Google ya no admite nuevas publicaciones ni suscripciones de Usenet. El contenido anterior sigue siendo visible.

how to gunzip a string ?

Visto 0 veces
Saltar al primer mensaje no leído

Bill Loren

no leída,
30 jul 2003, 10:16:3230/7/03
a
I guess I really need some sort of library that will do a gzip decoding to a
compressed string.
assume that I have a gzipped_string_reply I got from an HTTP server,
It'd be superb to have a gunzip class that takes it and return its decoded
equivalent.

I managed to do it with the gzip library only after saving the string to a
file and then opening and reading it
with gzip.open, but it's extremely ugly.

any suggestions ?

thanks!
~ B

Fredrik Lundh

no leída,
30 jul 2003, 13:47:4330/7/03
a

trying again:

http://effbot.org/zone/consumer-gzip.htm
(GzipConsumer module)

interface code (based on john j. lee's posting):

from GzipConsumer import GzipConsumer

class stupid_gzip_consumer:
def __init__(self): self.data = []
def feed(self, data): self.data.append(data)

def gunzip(data):
c = stupid_gzip_consumer()
gzc = GzipConsumer(c)
gzc.feed(data)
gzc.close()
return "".join(c.data)

unzipped_data = gunzip(gzipped_data)

</F>


Andreas Kuntzagk

no leída,
31 jul 2003, 4:33:2231/7/03
a
On Wed, 30 Jul 2003 16:16:32 +0200, Bill Loren wrote:

> I guess I really need some sort of library that will do a gzip decoding to
> a compressed string.
> assume that I have a gzipped_string_reply I got from an HTTP server, It'd
> be superb to have a gunzip class that takes it and return its decoded
> equivalent.


You could put your string in an cStringIO:

c_string= cStringIO.StringIO(compressed_string)
gzip_handle=gzip.GzipFile(fileobj=c)
gzip_handle.read()

HtH, Andreas

Bill Loren

no leída,
31 jul 2003, 5:11:2831/7/03
a
Thanks !!! it works fine.
question: upon calling GzipConsumer's close methos, it in turn invokes a
consumer close method, too.
on the stupid_consumer you demonstrated there is no such method. the
question is whether an extremely_stupid
"def close(self): pass" method is just fine or is there something important
to do with the data ?

~B

----- Original Message -----
From: "Fredrik Lundh" <fre...@pythonware.com>
To: <pytho...@python.org>
Sent: Wednesday, July 30, 2003 7:47 PM
Subject: Re: how to gunzip a string ?


> Bill Loren wrote:
> > I guess I really need some sort of library that will do a gzip decoding
to a
> > compressed string.
> > assume that I have a gzipped_string_reply I got from an HTTP server,
> > It'd be superb to have a gunzip class that takes it and return its
decoded
> > equivalent.
> >

> > I managed to do it with the gzip library only after saving the string to
a
> > file and then opening and reading it
> > with gzip.open, but it's extremely ugly.
> >
> > any suggestions ?
>
> trying again:
>
> http://effbot.org/zone/consumer-gzip.htm
> (GzipConsumer module)
>
> interface code (based on john j. lee's posting):
>
> from GzipConsumer import GzipConsumer
>
> class stupid_gzip_consumer:
> def __init__(self): self.data = []
> def feed(self, data): self.data.append(data)
>
> def gunzip(data):
> c = stupid_gzip_consumer()
> gzc = GzipConsumer(c)
> gzc.feed(data)
> gzc.close()
> return "".join(c.data)
>
> unzipped_data = gunzip(gzipped_data)
>
> </F>
>
>
>
>

> --
> http://mail.python.org/mailman/listinfo/python-list
>

Bill Loren

no leída,
31 jul 2003, 5:19:2431/7/03
a
oh and another extremely_important question:
were the library+dummy_interface tested ?

thanks
~ B

0 mensajes nuevos