1
0
mirror of https://github.com/thangisme/notes.git synced 2024-11-04 20:57:15 -05:00
notes/node_modules/JSONStream/test/multiple_objects.js

43 lines
1.0 KiB
JavaScript
Raw Normal View History

2017-03-09 13:16:08 -05:00
var fs = require ('fs');
var net = require('net');
var join = require('path').join;
var file = join(__dirname, 'fixtures','all_npm.json');
var it = require('it-is');
var JSONStream = require('../');
var str = fs.readFileSync(file);
var datas = {}
var server = net.createServer(function(client) {
var root_calls = 0;
var data_calls = 0;
var parser = JSONStream.parse(['rows', true, 'key']);
parser.on('root', function(root, count) {
++ root_calls;
});
parser.on('data', function(data) {
++ data_calls;
datas[data] = (datas[data] || 0) + 1
it(data).typeof('string')
});
parser.on('end', function() {
console.log('END')
var min = Infinity
for (var d in datas)
min = min > datas[d] ? datas[d] : min
it(root_calls).equal(3);
it(min).equal(3);
server.close();
});
client.pipe(parser);
});
server.listen(9999);
var client = net.connect({ port : 9999 }, function() {
var msgs = str + ' ' + str + '\n\n' + str
client.end(msgs);
});