Symfony2: отправить HTTP-запрос

У меня было подобное требование, мне нужно прочитать большой json-файл в узле js и обработать данные в кусках и вызвать api и сохранить в mongodb. inputFile.json похож:

{
 "customers":[
       { /*customer data*/},
       { /*customer data*/},
       { /*customer data*/}....
      ]
}

Теперь я использовал JsonStream и EventStream для достижения этого синхронно.

 var JSONStream = require('JSONStream');
    var  es = require('event-stream');

    fileStream = fs.createReadStream(filePath, {encoding: 'utf8'});
        fileStream.pipe(JSONStream.parse('customers.*')).pipe(es.through(function (data) {
            console.log('printing one customer object read from file ::');
            console.log(data);
            this.pause();
            processOneCustomer(data, this);
            return data;
        },function end () {
            console.log('stream reading ended');
            this.emit('end');
          });

    function processOneCustomer(data,es){
     DataModel.save(function(err,dataModel){
     es.resume();
    });
}
13
задан Gabriel Theron 16 May 2012 в 13:51
поделиться