473,413 Members | 1,801 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,413 software developers and data experts.

compress string of data

Hi.

How i could compress string of data?.

I heart that it´s possible to make with librep, but i´dont know the way to
do it.

if somebody know any way to do it or any web where explain it i would thank
the help.

Regards.

José Carlos
ADV
www.siadv.com
Jul 18 '05 #1
6 4455
José Carlos wrote:
How i could compress string of data?.


Type "python compress string of data" in google and press "I'm feeling lucky".
That might help you out.

--Irmen
Jul 18 '05 #2
> How i could compress string of data?.
import zlib
zlib.compress("Hello, world")

'x\x9c\xf3H\xcd\xc9\xc9\xd7Q(\xcf/\xcaI\x01\x00\x1b\xd4\x04i'

http://www.python.org/doc/current/lib/module-zlib.html

Gerrit.

Jul 18 '05 #3
>>>>> Gerrit Holl <ge****@nl.linux.org> (GH) wrote:
How i could compress string of data?.
import zlib
zlib.compress("Hello, world")

GH> 'x\x9c\xf3H\xcd\xc9\xc9\xd7Q(\xcf/\xcaI\x01\x00\x1b\xd4\x04i'

GH> http://www.python.org/doc/current/lib/module-zlib.html

Waw, that compresses it from 12 bytes to 20 bytes :=)
--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.***********@hccnet.nl
Jul 18 '05 #4
Piet van Oostrum wrote:
>>Gerrit Holl <ge****@nl.linux.org> (GH) wrote:
How i could compress string of data?.

>import zlib
>zlib.compress("Hello, world")


GH> 'x\x9c\xf3H\xcd\xc9\xc9\xd7Q(\xcf/\xcaI\x01\x00\x1b\xd4\x04i'

GH> http://www.python.org/doc/current/lib/module-zlib.html

Waw, that compresses it from 12 bytes to 20 bytes :=)

There is no such thing as universal compression - some compressions
result in expansion.

- Josiah
Jul 18 '05 #5

"Josiah Carlson" <jc******@nospam.uci.edu> wrote in message
news:bv**********@news.service.uci.edu...
Piet van Oostrum wrote:
>>>Gerrit Holl <ge****@nl.linux.org> (GH) wrote:
How i could compress string of data?.

>>import zlib
>>zlib.compress("Hello, world")


GH> 'x\x9c\xf3H\xcd\xc9\xc9\xd7Q(\xcf/\xcaI\x01\x00\x1b\xd4\x04i'

GH> http://www.python.org/doc/current/lib/module-zlib.html

Waw, that compresses it from 12 bytes to 20 bytes :=)

There is no such thing as universal compression


Only if you specify invertibility (losslessness).

f(s) == '' compressess everything except '' itself ;-)

and that len(f(s)) < len(s) for some s and not just <= for all s (which
allows identity 'compression' f(s) == s).
- some compressions result in expansion.


Which is to say that if a 1-1 function maps some strings to smaller
strings, it must correspondingly map others to larger strings. An
interesting CS tidbit that people keep discovering by stumbling over.

Lossless universal expansion is possible: f(s) == ' '+s. But it is into
rather than onto, so only strings starting with ' ' can be inversely
mapped.
Terry J. Reedy


Jul 18 '05 #6
Terry Reedy wrote:
"Josiah Carlson" <jc******@nospam.uci.edu> wrote in message
news:bv**********@news.service.uci.edu...
Piet van Oostrum wrote:

>>>>Gerrit Holl <ge****@nl.linux.org> (GH) wrote:
>How i could compress string of data?.
>
>
>>>import zlib
>>>zlib.compress("Hello, world")

GH> 'x\x9c\xf3H\xcd\xc9\xc9\xd7Q(\xcf/\xcaI\x01\x00\x1b\xd4\x04i'

GH> http://www.python.org/doc/current/lib/module-zlib.html

Waw, that compresses it from 12 bytes to 20 bytes :=)

There is no such thing as universal compression

Only if you specify invertibility (losslessness).

f(s) == '' compressess everything except '' itself ;-)

and that len(f(s)) < len(s) for some s and not just <= for all s (which
allows identity 'compression' f(s) == s).

- some compressions result in expansion.

Which is to say that if a 1-1 function maps some strings to smaller
strings, it must correspondingly map others to larger strings. An
interesting CS tidbit that people keep discovering by stumbling over.

Lossless universal expansion is possible: f(s) == ' '+s. But it is into
rather than onto, so only strings starting with ' ' can be inversely
mapped.


Exactly (I was too short on time to say the equivalent this morning, and
even if I had said the equivalent, it likely would not have been as clear).

- Josiah
Jul 18 '05 #7

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

Similar topics

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: ...
0
by: Patrick Questembert | last post by:
I am developping with Visual Studio 2003 + C# + MySQL 4.1 and the OleDb components. My problem is that a stament using the COMPRESS() function seems to work or not depending on the data ... Here...
8
by: Jose L. Velazquez | last post by:
Hi all, I have made a webservice that returns an XML, but sometimes the connection is so slow and there is a lot of data to be returned. I would like to know if it is possible to send this data...
6
by: Champika Nirosh | last post by:
Hi, I have two machine where I needed to have a extended TCP/IP protocol to make the link between the two machines Mean,I need to write a application that compress every data the machine send...
3
by: kpmassey | last post by:
I'm using javascript to construct large tables from an array of data, using ideas from: http://www.oreillynet.com/pub/a/javascript/2003/05/06/dannygoodman.html The data itself cannot be...
6
by: Adriano | last post by:
Can anyone recommend a simple way to compress/decomress a String in .NET 1.1 ? I have a random string of 70 characters, the output from a DES3 encryption, and I wish to reduce the lengh of it, ...
5
by: zgh1970 | last post by:
Hi, Friends, default DB2 compression library. I am wondering if this option will have any new restriction on RESTORE in the following. (Can I used that backup imsage for restore at the...
0
by: vampire1986 | last post by:
Hi all. I have project compress file using C#. I'm using name space IO.Compression and i saw this code on Internet but it is compress to file bigger than source file. Can you help me, please.Thanks...
0
by: J. Clifford Dyer | last post by:
On Sun, May 18, 2008 at 07:06:10PM +0100, Matt Porter wrote regarding Compress a string: def compress_str(s): # str is a builtin keyword. Don't overload it. out = for c in s: if out and c ==...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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,...
0
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...
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.