GZipReadStream, etc.

Raab, Andreas Andreas.Raab at disney.com
Sun Feb 6 08:16:22 UTC 2000


Andrew,

Here you go:

	| reader writer stuff compressed |
	"9631 bytes to read"
	stuff _ (InterpreterSupportCode class sourceCodeAt: #macDNRFile)
asString.
	writer _ GZipWriteStream on: ByteArray new.
	"Note: Must use #asByteArray if compressing to a ByteArray"
	writer nextPutAll: stuff asByteArray.
	"Important: Always #close the compressor to force compression"
	writer close.
	"Note: The compressed contents is held in the encodedStream"
	"3049 bytes compressed"
	compressed _ writer encodedStream contents.
	"Decompression is a bit simpler"
	reader _ GZipReadStream on: compressed.
	"9631 bytes decompressed"
	reader upToEnd asString.


  Andreas

> -----Original Message-----
> From: Andrew C. Greenberg [mailto:werdna at gate.net]
> Sent: Saturday, February 05, 2000 11:44 PM
> To: squeak at cs.uiuc.edu
> Cc: recipient list not shown
> Subject: GZipReadStream, etc.
> 
> 
> Thought I'd ask you directly to save some time.
> 
> How does one use GZipReadStream and GZipWriteStream to 
> decompress/compress data stored in, say, a ByteArray?  My feeble 
> efforts along the lines of:
> 
> | writer |
> writer := GZipWriteStream on: (ByteArray new).
> writer nextPutAll: stuff.
> writer close.
> writer contents
> 
> | writer |
> writer := GZipWriteStream on: (WriteStream on: (ByteArray new)).
> writer nextPutAll: stuff.
> writer close.
> writer contents
> 
> doesn't seem to be doing what I hoped it would be doing.  Either the 
> data comes through uncompressed, doesn't come through at all, or it 
> comes through smaller, but unreadable by GZReadStream.
> 
> Strangely, parallel code using FileStreams works flawlessly.
> 
> Am I missing something?
> 





More information about the Squeak-dev mailing list