|
From: | Paolo Bonzini |
Subject: | Re: [Help-smalltalk] ZLib streams |
Date: | Thu, 23 Aug 2007 15:14:20 +0200 |
User-agent: | Thunderbird 2.0.0.6 (Macintosh/20070728) |
That worked for my small example. But I've tried to implement it in my program now and ran into some other problem: [socket atEnd not] whileTrue: [self handleData: inputStream nextHunk] Seemed to block.
You cannot know if the stream is atEnd unless a) it closes, b) you have one more byte. So yes, #atEnd blocks (by design).
I would do something like [ socket atEnd ifTrue: [ ^self ] self handleData: inputStream nextHunk ] whileFalse. with #handleData: returning true when it finishes reading a packet.
You may also note that the call to ZlibReadStream>>#processInput:size: which will result in a call to RawInflateStream>>#processInput:size: will receive the wrong flag (0 Z_NO_FLUSH or 4 Z_FINISH, and not 2 Z_SYNC_FLUSH) when atEnd finally returns.
As far as I could see from the zlib source code, Z_SYNC_FLUSH only matters for deflating. On inflation, it only looks for Z_NO_FLUSH, Z_FINISH, Z_BLOCK.
Paolo
[Prev in Thread] | Current Thread | [Next in Thread] |