[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-smalltalk] ZLib Z_SYNC_FLUSH/Z_FULL_FLUSH
From: |
Paolo Bonzini |
Subject: |
Re: [Help-smalltalk] ZLib Z_SYNC_FLUSH/Z_FULL_FLUSH |
Date: |
Wed, 22 Aug 2007 15:58:30 +0200 |
User-agent: |
Thunderbird 2.0.0.6 (Macintosh/20070728) |
Yea, I'm currently writing some kind of network server where I would
like to use Zlib to optimize the overhead a bit. I'm currently trying
to figure out how streams are supposed to work at all and wrote some
code some hours ago to init a compression handshake in the protocol
I've implemented. Now all I need to figure out is how to plug the
compression streams on that already existing TCP Stream :-)
The "testSyncFlush" test I introduced in zlibtests.st can help. The
code would go something like this (just to give an idea):
initialize
yourTCPSocket := blahblah.
deflatedData := RawDeflateWriteStream on: yourTCPSocket
nextPutPacket: uncompressedData compressedData: compressedData
yourTCPSocket nextPutAll: uncompressedData.
"no need to flush yourTCPSocket, in the end deflatedData
just writes there too."
deflatedData nextPutAll: compressedData.
deflatedData syncFlush
nextPacket: uncompressedDataSize compressedData: compressedDataSize
| uncData cmpData |
uncData := yourTCPSocket next: uncompressedDataSize.
cmpData := yourTCPSocket next: compressedDataSize.
cmpData := (RawInflateStream on: cmpData readStream) contents.
^uncData, cmpData
Since the compressedDataSize most likely is somewhere in the
uncompressed data, you could do something like this instead:
nextPacket: uncompressedDataSize compressedData: compressedDataSizeBlock
| uncData cmpData size |
uncData := yourTCPSocket next: uncompressedDataSize.
size := compressedDataSizeBlock value: uncData.
cmpData := yourTCPSocket next: size.
cmpData := (RawInflateStream on: cmpData readStream) contents.
^uncData, cmpData
Paolo