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


_______________________________________________
help-smalltalk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to