Created
May 18, 2014 17:14
-
-
Save baniol/f7381e8b8409e2e2e798 to your computer and use it in GitHub Desktop.
nodejs stream transform, uppercase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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