469,572 Members | 1,199 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,572 developers. It's quick & easy.

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
Jul 18 '05 #1
0 1224

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by enrio | last post: by
3 posts views Thread by Alan Toppen | last post: by
reply views Thread by Tony | last post: by
5 posts views Thread by -Mr. Coder- | last post: by
4 posts views Thread by Peter | last post: by
1 post views Thread by chris.atlee | last post: by
2 posts views Thread by flebber | last post: by
reply views Thread by Bint | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.