Node.js/stream:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第210行: 第210行:
kangkk
kangkk
kangkk
kangkk
</pre>}}}}
背压。
{{leftrightflex|<syntaxhighlight lang="javascript">
const Readable = require('stream').Readable;
const stream = require('stream');
const rs = new Readable();
rs.push('kangkk\n');
rs.push(null);
const foo = rs.pipe(new stream.PassThrough());
const bar = rs.pipe(new stream.PassThrough());
foo.on('data', function (data) { console.log('foo data:', data) })
foo.on('end', function () {
  bar.on('data', function (data) { console.log('bar data:', data) })
})</syntaxhighlight>|{{consoleout|<pre>
foo data: <Buffer 6b 61 6e 67 6b 6b 0a>
bar data: <Buffer 6b 61 6e 67 6b 6b 0a>
</pre>}}}}
</pre>}}}}