• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var fs = require ('fs');
2var net = require('net');
3var join = require('path').join;
4var file = join(__dirname, 'fixtures','all_npm.json');
5var it = require('it-is');
6var JSONStream = require('../');
7
8var str = fs.readFileSync(file);
9
10var datas = {}
11
12var server = net.createServer(function(client) {
13    var data_calls = 0;
14    var parser = JSONStream.parse(['rows', true, 'key']);
15    parser.on('data', function(data) {
16        ++ data_calls;
17        datas[data] = (datas[data] || 0) + 1
18        it(data).typeof('string')
19    });
20
21    parser.on('end', function() {
22        console.log('END')
23        var min = Infinity
24        for (var d in datas)
25          min = min > datas[d] ? datas[d] : min
26        it(min).equal(3);
27        server.close();
28    });
29    client.pipe(parser);
30});
31server.listen(9999);
32
33var client = net.connect({ port : 9999 }, function() {
34    var msgs = str + ' ' + str + '\n\n' + str
35    client.end(msgs);
36});
37