Node.js - 压缩服务器上的数据,通过Engine.IO Web Sockets发送,并在客户端解压缩

时间:2013-12-18 18:03:09

标签: node.js zlib engine.io

我在服务器上GZip一些JSON数据,通过Web套接字的Engine.IO实现发送它

function sendResourceDataToObserver(socket, data) {
  zlib.gzip(data, function (_, result) {
    socket.send(result);
  });
}

并使用我使用Browserify(http://browserify.org/

导入的ZLIB模块对其进行解压缩
socket.on('message', function (data) {
        zlib.gunzip(data, function(err, decoded) {
          if (err) {
            console.error(err);
          }
          console.log(decoded);
        });
});

但是我得到了这个错误(“解码”显然是未定义的):

Error: invalid file signature:,�
    at Error (<anonymous>)
    at nb.i (http://localhost:5000/bundle.js:1994:184)
    at Bb (http://localhost:5000/bundle.js:2000:424)
    at http://localhost:5000/bundle.js:2000:338
    at http://localhost:5000/bundle.js:1869:21 

有什么想法吗?

0 个答案:

没有答案