zlib and gzip
Hornberger, Chris
Chris.Hornberger at blackrock.com
Wed May 12 13:03:35 EDT 2004
Silly questions first: Is it just a matter of 72 column-bounding to make it email-compliant? (keep in mind I haven't run your sample code yet, I'm sitting here perusing while on a conference call - meetings suck!!!)
--------------------------
Chris Hornberger
Blackrock - 302.797.2318
chris.hornberger at blackrock.com
Card carrying MSDN member since 2004.
No, really. I've got the card to prove it.
-----Original Message-----
From: python-list-bounces+chris.hornberger=blackrock.com at python.org
[mailto:python-list-bounces+chris.hornberger=blackrock.com at python.org]On
Behalf Of Greg Bakken
Sent: Wednesday, May 12, 2004 12:57 PM
To: python-list at python.org
Subject: zlib and gzip
I am writing a python program that recieves 'compressed and encoded'
strings from another piece of software. I can successfully uncompress
and decode the strings via
import base64, zlib
def getString(s):
s = base64.decodestring(s)
s = zlib.decompress(s, -15)
return s
Now, I want to take a 'readable' text string, and compress and encode
it the same way as the other piece of software. I first tried the
seemingly obvious (but incorrect)
import base64, zlib
def makeString(s):
s = zlib.compress(s, 9)
s = base64.encodestring(s)
return s
I have also tried using the gzip module to do this like
import base64, gzip, StringIO
def makeString(s):
sio = StringIO.StringIO()
gzipper = gzip.GzipFile(mode="wb", fileobj=sio)
gzipper.write(s)
s = base64.encodestring(sio.getvalue())
return s
What I would like to be able to do is take a string s, pass it through
the makeString function, and pass the result through the getString
function, and end up with the original string s back. I have to stick
with the way getString is, so I can handle strings from another
program, so I need to adapt makeString accordingly, but cannot figure
out how.
Greg
--
http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list