有没有NodeJS 'passthrough‘流?
例如,一个对象,我放进去的任何东西都会立即出来,原封不动。
它看起来毫无意义,但作为开发过程中快速变化的代码的“静态中心”,它是很有用的。
发布于 2013-10-18 18:14:58
嗯。实际上,就是这个名字。:)
stream.PassThrough
它在Node0.10和更高版本中可用,作为Streams 2 update的一部分(在最后提到)。
它也是Streams中为数不多的可以直接实例化的类型之一:
var pass = new stream.PassThrough();而且,它目前在API for Stream Implementors (接近Steams ToC的底部)下有简短的文档。
发布于 2016-03-24 20:43:44
当您需要将TCP服务器的输入字节发送到另一个TCP服务器时,它非常方便。
在我的microntoller应用程序的web部件中,我按如下方式使用它
var net = require('net'),
PassThroughStream = require('stream').PassThrough,
stream = new PassThroughStream();
net.createServer({allowHalfOpen: true}, function(socket) {
socket.write("Hello client!");
console.log('Connected:' + socket.remoteAddress + ':' + socket.remotePort);
socket.pipe(stream, {end: false});
}).listen(8080);
net.createServer(function(socket) {
stream.on('data', function (d) {
d+='';
socket.write(Date() + ':' + ' ' + d.toUpperCase());
});
socket.pipe(stream);
}).listen(8081);https://stackoverflow.com/questions/19445217
复制相似问题