I am trying to utilize Zlib for text compression.
For example I have a text T='blah blah blah blah' I need to compress it for this I am using S=zlib.compress(T) Now what I want is to get the ASCII form of S so that I can decompress this T but in a different program. Thanks,
EDIT: I guess I got a method to solve it here is the way:
import zlib, base64 text = 'STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW ' code = base64.b64encode(zlib.compress(text,9)) print code which gives :
eNoLDnF09lbwD3MNcvPxD1cIHhxcAE9UKaU= Now I can copy this code to a different program to get the original program back:
import zlib, base64 s='eNoLDnF09lbwD3MNcvPxD1cIHhxcAE9UKaU=' data = zlib.decompress(base64.b64decode(s)) print data Please suggest if you are aware of any other compression method which would give better results while consistent to the same manner.