On Tue, Jun 19, 2012 at 9:50 AM, killerhunk <[email protected]> wrote:
> I am new to node.js and currently working on a tcp server. I want all the
> messages to be sent to client in a compressed format.I am using zlib for
> this purpose.
>
> The following sample is a code on server side:
>
>     zlib.deflate(response.toString(), function(err, buffer) {
>               if (!err) {
>                 session.xmlSocket.writeString(buffer);
>                 }
>               });
>
> This function basically compresses the data and writes it to the socket.The
> code on client side that decompress that data is:
>
>     this.socket.on("data", function(chunk){
>          zlib.unzip(chunk, function(err, buffer) {
>          if (!err) {
>                 self.parser.write(buffer.toString());
>             console.log(buffer.toString());
>           }
>         });
>
> Now this code works fine when I run both client and server on the same
> pc.But is it correct to directly write the Buffer object returned by the
> zlib.deflate function and write it on the socket and then use it on the
> client side?

Yes. Ownership of the buffer is transferred to your callback.

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to