UNPKG

541 BJavaScriptView Raw
1const fs = require('fs');
2const path = require('path');
3const line_by_line = require('line-by-line');
4
5exports.line_reduce = (file_to_reduce, transform, accum) => new Promise((resolve, reject) => {
6 const log_line_by_line = new line_by_line(file_to_reduce);
7 log_line_by_line.on('line', (line) => {
8 if (line.length > 0) {
9 accum = transform(JSON.parse(line), accum);
10 }
11 })
12 log_line_by_line.on('error', (err) => {
13 console.log(err);
14 reject(err);
15 })
16 log_line_by_line.on('end', () => {
17 resolve(accum);
18 })
19});