Skip to content

Instantly share code, notes, and snippets.

@baniol
Created May 18, 2014 17:14
Show Gist options
  • Save baniol/f7381e8b8409e2e2e798 to your computer and use it in GitHub Desktop.
Save baniol/f7381e8b8409e2e2e798 to your computer and use it in GitHub Desktop.
nodejs stream transform, uppercase
var Transform = require('stream').Transform;
/// Server:
var server = require('net').createServer();
function onConnection(socket) {
/// Create the transform stream:
var uppercase = new Transform({
decodeStrings: false
});
uppercase._transform = function(chunk, encoding, done) {
done(null, chunk.toUpperCase());
};
/// pipe socket
socket.setEncoding('utf8');
socket.pipe(uppercase).pipe(socket);
}
server.on('connection', onConnection);
server.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment