Is there a NodeJS 'passthrough' stream?
i.e. an object where whatever I put in to it comes out immediately, unchanged.
It seems pointless, but it would be useful as a 'static centre' for rapidly changing code during development.
PassThrough. This Stream is a trivial implementation of a Transform stream that simply passes the input bytes across to the output.
There are four fundamental stream types in Node. js: Readable, Writable, Duplex, and Transform streams.
Nodejs is very good to streaming audio and video, but nodejs is a new technology, so it's don't have a lot of softwares yet.
Writable : streams to which data can be written (for example, fs. createWriteStream() ). Readable : streams from which data can be read (for example, fs. createReadStream() ). Duplex : streams that are both Readable and Writable (for example, net.
Yeah. Actually, by that very name. :)
stream.PassThrough
It's available with Node 0.10 and later as part of the Streams 2 update (mentioned at the end).
It's also one of the few types from Streams that can be directly instantiated:
var pass = new stream.PassThrough();
And, it's currently documented briefly under API for Stream Implementors (towards the bottom of the Steams ToC).
it's really handy when you need to send input bytes of a TCP Server to another TCP Server.
In my microntoller application's web part i am using this as follows
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With