【发布时间】:2013-12-07 10:33:04
【问题描述】:
我试图理解对象流的概念,尤其是两者的结合。我正在寻找的用法是将字节流与对象流一起管道,例如:
// StringifyStream reads Buffers and emits String Objects
// Mapper is really just a classical map
// BytifyStream reads String Objects and emits buffers.
process.stdin.pipe(
StringifyStream()
).pipe(
Mapper(function(s) {
return s.toUpperCase();
}).pipe(
BytifyStream()
).pipe(process.stdout);
// This code should read from stdin, convert all incoming buffers to strings,
// map those strings to upper case and finally convert them back to buffers
// and write them to stdout.
现在,文档说:
“在中途设置 objectMode 是不安全的。”
我真的不明白这是什么意思。混合字节/对象流不安全吗?我真的很想使用这种模式,但如果它不安全,那可能是个坏主意。
【问题讨论】:
标签: node.js asynchronous stream pipe monads