[英]Node.js Stream - Buffer to String gives [object Object]
我希望能夠過濾輸出。 但是,我遇到從緩沖區轉換為字符串的問題。 console.log(JSON.stringify(obj.toString()));
繼續給我[object Object]
我不能使用。 如何將緩沖區轉換為字符串,以便我可以將內容過濾到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
創建一個對象流(或對象模式下的流)。 通過對象流對象流,而不是緩沖區。 你得到的不是緩沖區,而是對象obj
。 這就是它的toString
方法給出[object Object]
。 也許你正在尋找的是obj.contents
?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.