node.js - Node JS Emit method - set output headers to Zlib -


i trying compress output node js application. able compress text string on server side. header sent says html/plain text

so browser not able decompress

i using node v0.6.18

my code follows:

    var http  = require('http'), url   = require('url'), fs    = require('fs'), amqp  = require('amqp'), redis = require('redis'), zlib  = require('zlib'),     sys   = require(process.binding('natives').util ? 'util' : 'sys');  var exchangename= 'conferencetest';  send404 = function(res) {     res.writehead(404);     res.write('404');     res.end(); };  server = http.createserver(function(req, res) {     var path = url.parse(req.url).pathname;     switch (path) {          case '/':              fs.readfile(__dirname + "/index.html", function(err, data) {                  if (err) {                     return send404(res);                 } else {                     res.writehead(200, {'content-type': 'application/zip','connection':'close', 'content-encoding': 'gzip'});                     res.write(data, 'utf8');                     res.end();                 }              });         break;     }  });  // listen http server socket connections var io = require('socket.io').listen(server);   var connection = amqp.createconnection({host: 'localhost'});  connection.on('ready', function() {      var exchange = connection.exchange(exchangename, { // create exchange         type: 'direct',         durable: true     });      io.set('close timeout',500);     io.set('browser client gzip',true);      io.sockets.on('connection', function(client) {         console.log("client connected");          client.on('setqueue', function(data) {              var queue = connection.queue(data.queuename, {                  durable: true,                 autodelete: false             });         });              /************************** change view event handler starts **************************/                     client.on('changeview', function(data) {                             var queue = connection.queue(data.queuename, { //create queue                                     durable: true,                                     autodelete: false                             });                              var plaintext = "put kind of meat on stick , roast on flame , becomes food fit gods. no country understands sacred rule of seared meat turkey.turkish kebabs incarnation of meat lovers exotic fantasies, grilled lamb, beef , chicken skewer mvps.most kebab restaurants have long list of turkish starters called meze delicious main dishes.turkeys best alcoholic complement meat raki -- aniseed-flavored drink s diluted water , chilled ice. frothy, yogurt-based ayran great non-alcoholic complement heavy dishes. kidding -- want meat. heres in turkey.";                              zlib.deflate(plaintext, function(err, buffer) {                              if (!err) {                                 console.log("original   length: " + plaintext.length);                                 console.log("compressed length: " + buffer.tostring('base64').length);                                 io.sockets.emit('changeview', buffer.tostring('base64'));                               }                             });                     });        });  });      process.on( 'uncaughtexception', function ( err ) {    console.log( 'uncaught exception: ' + err.message );    });      server.listen(18080); 

any ideas or appreciated

socket.io take compressed string , pass client using transport socket.io client has established socket.io server.

this long polling or websockets example. websocket transport there no content-type header binary.

i can think of 2 options:

  • use zip library in browser inflate base64 encoded string.

or

  • emit link client client on. can serve content regular http request can compress using connect module discussed here

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -