473,414 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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 1371

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: enrio | last post by:
I have a string which I try to decompress: body = zlib.decompress(body) but I get zlib.error: Error -3 while decompressing data: incorrect header check However, I can write the string to...
3
by: Alan Toppen | last post by:
I was unable to use the ZipFile class in the zipfile module in Python2.4. I got an error that zlib could not be found. Comparing my Python 2.2 installation I noticed Python 2.4 was missing a...
0
by: Tony | last post by:
Hello, Any assistance would be appreciated: As the subject suggests I am trying to gunzip files using the Compress::Zlib module. The following is basically the code that I am working with: ...
5
by: -Mr. Coder- | last post by:
Hi, I've got a problem with including ZLib in to my application. I've downloaded the newest Version from http://gzip.org and unzipped it. ->I do not know what file I've got to include. ...
4
by: Peter | last post by:
Hi, Not sure if this is a proper ng to post this question. Is here anybody who has used zlib? I downloaded 1.2.1 of zlib from www.gzip.org/zlib (for windows 98/nt/2000/xp), and used it in my...
1
by: Leif Wessman | last post by:
I enabled automatic gzip compression with the following lines in ..htaccess: php_value zlib.output_compression On php_value zlib.output_compression_level 5 The problem is that the...
1
by: chris.atlee | last post by:
I'm writing a program in python that creates tar files of a certain maximum size (to fit onto CD/DVD). One of the problems I'm running into is that when using compression, it's pretty much...
2
by: flebber | last post by:
Hi Can anyone show me a working example of how to use gzip to decompress a file. I have read the docs at python.org and had many goes at it but just can't get it to work. Cheers flebber
0
by: Bint | last post by:
Hello, I am trying to decompress some data in a file, from PHP. It's data that has been zlib-compressed on a handheld device and sent wirelessly to the PHP server. I can open the file and...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.