我看到了所示的示例here http://nodejs.org/api/zlib.html#zlib_examples
response.writeHead(200, { 'content-encoding': 'deflate' });
raw.pipe(zlib.createDeflate()).pipe(response);
我尝试通过创建读取流并发送压缩输出来发送响应。
但我正在寻找一种无需读取流即可完成此操作的方法,因为我的文本来自另一个HTTP
要求。我只是曾经response.write(text);
我尝试了几件事,包括
zlib.deflate(text, function (err, buffer) {
if (err) throw err;
response.write(buffer);
response.end();
});
但浏览器说invalid or unsupported form of compression.
我究竟做错了什么?
connect
的代码说
return stream
? stream.write(new Buffer(chunk, encoding))
: write.call(res, chunk, encoding);
那么是不是只有流会被处理?
您使用的是快递吗?如果是这样,只需使用compress
中间件:
app.use(express.compress());
http://expressjs.com/api.html#compress http://expressjs.com/api.html#compress
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)