[Q] About compressing

Lex Spoon lex at cc.gatech.edu
Thu May 26 01:43:51 UTC 2005

Hmm, here's some code that seems to work.

outputStream _ RWBinaryOrTextStream on: ''.
zipper _ GZipWriteStream on: outputStream.
zipper nextPutAll: 'hello, world!'.

zipper close.
zipped _ outputStream contents.

This achieves a marvelous "compression" ratio of 33/13 = 254%.  :)

To decode it:

inputStream _ RWBinaryOrTextStream with: zipped.
inputStream reset.
unzipper _ GZipReadStream on: inputStream.
unzipper upToEnd asString

Note that there is a trick here in that you have to reset the
RWBinaryOrTextStream after creating it -- the stream's position starts
out at the end of the data instead of the beginning.  That trips me up
all the time.

I hope this helps,


More information about the Squeak-dev mailing list