管道输出出通2



这是我第一次尝试使用2,我遇到了一点麻烦。我正在通过一系列流处理我的数据,我想从我的转换函数中管道出来。

文档说我应该使用this.push从我的转换函数中获取数据,然后在我完成时调用回调,所以我尝试使用管道(因为应该做同样的事情,对吧?),但我得到一个writeAfterEnd错误。我的代码和堆栈跟踪如下,但我不知道该怎么做。有人能给我指个正确的方向吗?

代码-

function run(chunk, encoding, callback) {
    this.on("finish", function(){
        console.log("this finished")
        callback()
    })
    dataStream = new stream.Readable({objectMode: true});
    dataStream._read = function noop(){};
    dataStream.push(chunk);
    dataStream.pipe(sass()).pipe(this)
}
gulp.src("./web-src/scss/add_post.scss").pipe(through.obj(run)).on('data', function(chunk){console.log(chunk)})

Stacktrace -

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: write after end
    at writeAfterEnd (/Volumes/BackRoom/Dropbox/Timpani/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:198:12)
    at DestroyableTransform.Writable.write (/Volumes/BackRoom/Dropbox/Timpani/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:243:5)
    at write (/Volumes/BackRoom/Dropbox/Timpani/node_modules/gulp-sass/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623:24)
    at flow (/Volumes/BackRoom/Dropbox/Timpani/node_modules/gulp-sass/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:632:7)
    at DestroyableTransform.pipeOnReadable (/Volumes/BackRoom/Dropbox/Timpani/node_modules/gulp-sass/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:664:5)
    at DestroyableTransform.emit (events.js:104:17)
    at emitReadable_ (/Volumes/BackRoom/Dropbox/Timpani/node_modules/gulp-sass/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:448:10)
    at emitReadable (/Volumes/BackRoom/Dropbox/Timpani/node_modules/gulp-sass/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:444:5)
    at readableAddChunk (/Volumes/BackRoom/Dropbox/Timpani/node_modules/gulp-sass/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:187:9)
    at DestroyableTransform.Readable.push (/Volumes/BackRoom/Dropbox/Timpani/node_modules/gulp-sass/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:149:10)

您是在实现流还是仅仅使用through2?

API文档警告使用.push()的流消费者。

Error: write after end可能发生如果chunk === null, "API for Stream implementers "将其解释为EOF

相关内容

  • 没有找到相关文章

最新更新