DeflateStream unable to write binary streams?
Matthew Fulmer
tapplek at gmail.com
Wed Sep 26 07:04:18 UTC 2007
On Tue, Sep 25, 2007 at 11:33:26PM -0700, Andreas Raab wrote:
> 3) Embedding compressed binary data in the midst of text:
>
> stream := RWBinaryOrTextStream on: String new.
> stream nextPutAll: 'Binary data: '.
> stream binary.
> (GZipWriteStream on: stream) nextPut: 123; nextPut: 234; finish.
> stream ascii.
> stream nextPutAll: 'More data follows' asByteArray.
> stream contents.
Ah. I needed to switch the stream *before* I start writing. I
also didn't know about the #finish message.
> All of the above examples work fine.
>
> >Second, it wouldn't accept the binary data that DataStream was
> >feeding it. It seems to only accept character data, as sending
> >the message #binary to a DeflateStream does nothing.
>
> DeflateStreams accept binary data if and only if the target stream is
> binary. They do not allow switching between binary and non-binary in the
> middle of things.
Didn't know that. Thank you
> >So, should DeflateStreams be general purpose streams, or is
> >there a good reason they are text-only and not embeddable?
>
> Besides it being not true (as the third example above illustrates) it
> wouldn't be a problem if it were. You could trivially solve the problem
> by using:
Sorry for the false assertion.
> writeDelta: aDelta
> stream nextPutAll: '!DSBinStReader new!'.
> stream nextPutAll: (DataStream streamedRepresentationOf: aDelta)
> asString zipped.
>
> which is not significantly more complex than your solution and actually
> works - yours doesn't because you either need to #close or #finish the
> compressor to write the last block (remember LZ is block based). Note
> that #flush is *not* enough here since the LZ family of compressors
> marks the last block specifically (#flush will write a block but not
> mark it as the last block and upset the decompressor on reading it).
>
> Cheers,
> - Andreas
>
Thank you very much. I guess the problem was me not finding or
reading any comments about how to use DeflateStreams.
PS: what is the difference between GZipWriteStream,
ZLibWriteStream, and ZipWriteStream? ZipWriteStream has the
concept of files in an archive, but I couldn't figure out the
first two
--
Matthew Fulmer -- http://mtfulmer.wordpress.com/
Help improve Squeak Documentation: http://wiki.squeak.org/squeak/808
More information about the Squeak-dev
mailing list
|