koajs 对stream处理问题?
发布于 10 年前 作者 petitspois 6965 次浏览 最后一次编辑是 8 年前 来自 问答
var rs = fs.createReadStream(path.join(root, 'log.txt'));

    rs.pipe(this.response);

错误

  dest.on('unpipe', onunpipe);
      ^
TypeError: Cannot read property 'on' of undefined
    at ReadStream.Readable.pipe (_stream_readable.js:494:7)
    at module.exports (/Users/apple/akblog/common/index.js:31:8)
    at Object.<anonymous> (/Users/apple/akblog/app.js:5:34)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:124:16)
    at node.js:842:3

Process finished with exit code 1

非koa

var http = require('http');
var fs = require('fs');

var server = http.createServer(function (req, res) {
    var stream = fs.createReadStream(__dirname + '/data.txt');
    stream.pipe(res);
});
server.listen(8000);
3 回复

this.body = rs 发自 CNodeJs ionic

@fengmk2 这样就是下载了,不是把内容输出到页面

@fengmk2 要设置type…

回到顶部