-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcat.js
33 lines (25 loc) · 1010 Bytes
/
concat.js
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
33
/**
You will be given text on process.stdin. Buffer the text and reverse it using
the `concat-stream` module before writing it to stdout.
`concat-stream` is a write stream that you can pass a callback to to get the
complete contents of a stream as a single buffer. Here's an example that uses
concat to buffer POST content in order to JSON.parse() the submitted data:
var concat = require('concat-stream');
var http = require('http');
var server = http.createServer(function (req, res) {
if (req.method === 'POST') {
req.pipe(concat(function (body) {
var obj = JSON.parse(body);
res.end(Object.keys(obj).join('\n'));
}));
}
else res.end();
});
server.listen(5000);
In your adventure you'll only need to buffer input with `concat()` from
process.stdin.
*/
var concat = require('concat-stream');
process.stdin.pipe(concat(function(data) {
console.log( data.toString().split("").reverse().join(""));
}));