Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #1/usr/bin/env python
- # this is from The Python
- # Standard Library by example
- # ISBN13: 9780321767349
- # pyflakes says imported hex but doesn't use?
- import codecs
- from cStringIO import StringIO
- from codecs_to_hex import to_hex
- buffer = StringIO()
- stream = codecs.getwriter('zlib')(buffer)
- text = 'abcdefghijklmnopqrstuvwxyz\n' * 50
- stream.write(text)
- stream.flush()
- print 'Original length :', len(text)
- compressed_data = buffer.getvalue()
- print 'ZIP compressed :', len(compressed_data)
- buffer = StringIO(compressed_data)
- stream = codecs.getreader('zlib')(buffer)
- first_line = stream.readline()
- print'Read first line :', repr(first_line)
- uncompressed_data = first_line + stream.read()
- print 'Uncompressed :', len(uncompressed_data)
- print 'Same :', text == uncompressed_data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement