473,654 Members | 3,115 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.decodest ring(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.encodest ring(s)
return s

I have also tried using the gzip module to do this like

import base64, gzip, StringIO
def makeString(s):
sio = StringIO.String IO()
gzipper = gzip.GzipFile(m ode="wb", fileobj=sio)
gzipper.write(s )
s = base64.encodest ring(sio.getval ue())
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 1381

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

Similar topics

2
11389
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 a file and run gunzip with the expected results:
3
3739
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 certain file: /usr/lib/python2.2/lib-dynload/zlibmodule.so. Unable to find a more elegant solution, I copied the file from my Python 2.2 directory into my Python 2.4 directory. When running my Python script it gives a warning: ...
0
3521
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
2496
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. PLEASE HELP!
4
1865
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 program to zip/unzip files. When I use the zipper class in zlib to zip a folder, I got a zip file with the SAME SIZE of zip file created (on the same folder) with the 'ZipTest' program downloaded from the site. But the problem is that the zip file...
1
2464
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 Content-Encoding header does not get set at all in the response. Therefore, a browser that advertises itself as supporting gzip compression (Accept-Encoding: gzip,deflate) receives compressed content but does not know it is compressed.
1
2342
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 impossible to determine if a file, once added to an archive, will cause the archive size to exceed the maximum size. I believe that to do this properly, you need to copy the state of tar file (basically the current file offset as well as the state of...
2
5281
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
1345
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 read some regular data from it. When I get to the position where my zlib compressed information starts, I make these calls: $zlib_filter = stream_filter_append($cellfile, 'zlib.inflate',
0
8376
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8708
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8489
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8594
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7307
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5622
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2716
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1596
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.