【发布时间】:2014-11-25 08:03:28
【问题描述】:
在 nodejs 中处理图像时,我遇到了 data 事件不适用于管道响应流的问题。
var http = require('http'),
url = require('url');
var httpServer = http.createServer(function(req,res){
var path = url.parse(req.url).pathname;
var fstream = $.FS.createReadStream('/root/image'+path);
fstream.on('error',function(){
res.writeHead(404);
return res.end();
});
fstream.pipe(res);
});
httpServer.listen(8080);
http.get({
host : '127.0.0.1',
port : 8080,
path : '/image.jpg'
},function(res){
res.on('data',function(){
console.log('data received'); //nothing happened
});
}).on('error',function(er){
throw er;
});
我做错了吗?或者这是一个节点错误?
【问题讨论】: