使用`through2`模块将`process.stdin`中的数据转换为`process.stdout`上的大写数据。在STREAM ADVENTURE的nodeschool研讨会中

时间:2016-03-01 10:47:08

标签: javascript

var through = require('through2');
var stream = through(write, end);

var tr =function write(buffer,encoding, next) {
    this.push(buffer.toString().toUpperCase()); 
    next();
}
process.stdin.pipe(through(tr)).pipe(process.stdout);

我收到错误

var stream = through(write, end);
                     ^
  

ReferenceError:未定义write       在对象。 (C:\ Users \用户GOTHAMI \流\ transform.js:2:22)       在Module._compile(module.js:409:26)       at Object.Module._extensions..js(module.js:416:10)       在Module.load(module.js:343:32)       在Function.Module._load(module.js:300:12)       在Function.Module.runMain(module.js:441:10)       在启动时(node.js:134:18)       在node.js:962:3

1 个答案:

答案 0 :(得分:0)

只需删除此行;

var stream = through(write, end);