index.js
async function readLogStream(file, instance) {
    return new Promise(resolve => {
        var stream = fs.createReadStream(file, { encoding: 'utf8', highWaterMark: instance.chunkSize });
        var hasStarted = false;
        // Split data into chunks so we dont stall the client
        stream.on('data', chunk => {
            if (!hasStarted) instance.emit("parsingStarted");
            hasStarted = true;
            var lines = chunk.toString().split("\n");
            // Pause stream until this chunk is completed to avoid spamming the thread
            stream.pause();
            async.each(lines, function (line, callback) {
                instance.registerMatch(line);
                callback();
            }, function (err) {
                setTimeout(() => {
                    stream.resume();
                }, instance.chunkInterval);
            });
        });
        stream.on('end', () => {
            instance.emit("parsingComplete");
            resolve();
            stream.close();
        });
    });
}
async function readLogStream(file, instance) {
    return new Promise(resolve => {
        var stream = fs.createReadStream(file, { encoding: 'utf8', highWaterMark: instance.chunkSize });
        var hasStarted = false;
        // Split data into chunks so we dont stall the client
        stream.on('data', chunk => {
            if (!hasStarted) instance.emit("parsingStarted");
            hasStarted = true;
            var lines = chunk.toString().split("\n");
            // Pause stream until this chunk is completed to avoid spamming the thread
            stream.pause();
            async.each(lines, function (line, callback) {
                instance.registerMatch(line);
                callback();
            }, function (err) {
                setTimeout(() => {
                    stream.resume();
                }, instance.chunkInterval);
            });
        });
        stream.on('end', () => {
            instance.emit("parsingComplete");
            resolve();
            stream.close();
        });
    });
}
async function readLogStream ( file , instance ) { return new Promise ( resolve => { var stream = fs . createReadStream ( file , { encoding : 'utf8' , highWaterMark : instance . chunkSize } ) ; var hasStarted = false ; // Split data into chunks so we dont stall the client stream . on ( 'data' , chunk => { if ( ! hasStarted ) instance . emit ( "parsingStarted" ) ; hasStarted = true ; var lines = chunk . toString ( ) . split ( "\n" ) ; // Pause stream until this chunk is completed to avoid spamming the thread stream . pause ( ) ; async . each ( lines , function ( line , callback ) { instance . registerMatch ( line ) ; callback ( ) ; } , function ( err ) { setTimeout ( ( ) => { stream . resume ( ) ; } , instance . chunkInterval ) ; } ) ; } ) ; stream . on ( 'end' , ( ) => { instance . emit ( "parsingComplete" ) ; resolve ( ) ; stream . close ( ) ; } ) ; } ) ; }
Reads the file and emits events for each included event
Reads the file and emits events for each included event