[英]Node.js Stream - Buffer to String gives [object Object]
I am would like to be able to filter the output. 我希望能够过滤输出。 However, I am having a issue converting from buffer to string.
但是,我遇到从缓冲区转换为字符串的问题。
console.log(JSON.stringify(obj.toString()));
keeps giving me [object Object]
which I can not use. 继续给我
[object Object]
我不能使用。 How can I convert the buffer to string so I can filter out the contents to stdout? 如何将缓冲区转换为字符串,以便我可以将内容过滤到stdout?
//inject 'bower and javascript' files or just 'javascript' files
function injectStream(sourceStream, filesStream) {
sourceStream
.pipe(injector(filesStream, { ignorePath: 'app', addRootSlash: false }))
.pipe(gulp.dest(INDEX_PATH_PARENT))
.pipe(through2.obj(function(obj, enc, next) {
console.log(JSON.stringify(obj.toString()));
this.push(obj.contents);
next();
})).pipe(process.stdout)
}
through2.obj
makes an object stream (or a stream in object mode). through2.obj
创建一个对象流(或对象模式下的流)。 Through an object stream objects flow, not buffers. 通过对象流对象流,而不是缓冲区。 What you get is not a buffer, but an object
obj
. 你得到的不是缓冲区,而是对象
obj
。 That is why its toString
method gives [object Object]
. 这就是它的
toString
方法给出[object Object]
。 Perhaps what you are looking for is in obj.contents
? 也许你正在寻找的是
obj.contents
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.