blob: 205a42564b5773e0378c066d71b7da34c7b85af7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
var Transform = require('../transform');
var inherits = require('util').inherits;
// subclass
function MyStream () {
Transform.call(this, {
lowWaterMark: 0,
encoding: 'utf8'
});
}
inherits(MyStream, Transform);
MyStream.prototype._transform = function (chunk, outputFn, callback) {
outputFn(new Buffer(String(chunk).toUpperCase()));
callback();
};
// use it!
var s = new MyStream();
process.stdin.resume();
process.stdin.pipe(s).pipe(process.stdout);
if (process.stdin.setRawMode)
process.stdin.setRawMode(true);
process.stdin.on('data', function (c) {
c = c.toString();
if (c === '\u0003' || c === '\u0004') {
process.stdin.pause();
s.end();
}
if (c === '\r')
process.stdout.write('\n');
});
|