How to use read-last-lines - 8 common examples

To help you get started, we’ve selected a few read-last-lines examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github harpagon210 / steemsmartcontracts / plugins / Replay.js View on Github external
fs.stat(filePath, async (err, stats) => {
    if (!err && stats.isFile()) {
      // read last line of the file to determine the number of blocks to replay
      const lastLine = await readLastLines.read(filePath, 1);
      const lastBlock = JSON.parse(lastLine);
      const lastBockNumber = lastBlock.blockNumber;

      // read the file from the start
      lr = new LineByLineReader(filePath);

      lr.on('line', async (line) => {
        lr.pause();
        if (line !== '') {
          const block = JSON.parse(line);
          const {
            blockNumber,
            timestamp,
            transactions,
            refSteemBlockNumber,
            refSteemBlockId,
github nttgin / BGPalerter / tests / 1_config.js View on Github external
it("write pid file", function (done) {
            const file = config.pidFile;
            expect("bgpalerter.pid").to.equal(file);

            if (file) {
                readLastLines
                    .read(file, 1)
                    .then((line) => {
                        expect(parseInt(line)).to.equal(process.pid);
                        done();
                    });
            }
        });
github synfonaut / hummingbird / tape.js View on Github external
return new Promise((resolve, reject) => {
        ReadLastLines.read(file, 10).then(str => {
            const lines = str.split("\n").filter(line => !!line);
            const last = lines.pop();
            const line = last.split(" ");
            if (line.length !== 5) { throw new Error("expected tape to have 4 elements") }
            if (line[0] === "BLOCK") {
                const height = Number(line[1]);
                resolve(height);
            } else {
                resolve(null);
            }
        }).catch(e => {
            resolve(null);
        });
    });
}
github TryGhost / Ghost-CLI / lib / commands / log.js View on Github external
if (argv.follow) {
                    this.ui.log('Log file has not been created yet, `--follow` only works on existing files', 'yellow');
                }

                return Promise.resolve();
            }

            prettyStream.on('error', (error) => {
                if (!(error instanceof SyntaxError)) {
                    throw error;
                }
            });

            prettyStream.pipe(this.ui.stdout);

            return lastLines.read(logFileName, argv.number).then((lines) => {
                lines.trim().split('\n').forEach(line => prettyStream.write(line));

                if (argv.follow) {
                    const Tail = require('tail').Tail;

                    const tail = new Tail(logFileName);
                    tail.on('line', line => prettyStream.write(line, 'utf8'));
                }
            });
        });
    }
github feup-infolab / dendro / src / controllers / admin.js View on Github external
function (cb)
            {
                readLastLines.read(errorLogPath, lines)
                    .then((lines) => cb(null, lines));
            }
        ], function (err, results)
github oznu / homebridge-config-ui-x / routes / log.js View on Github external
router.get("/raw/out", function (req, res, next) {
    reader.read(hb.log, 100).then((data) => res.send(convert(data)));
});
github karabaja4 / vscode-explorer-git-status / gulpfile.js View on Github external
const accessed = (err, workbench) =>
    {
        if (!found)
        {
            if (!err)
            {
                found = true;
                lines.read(workbench, 1).then((line) =>
                {
                    if (line.startsWith("function injectGitFileStatus()"))
                    {
                        callback(new Error("vscode-explorer-git-status is already installed."), null);
                    }
                    else
                    {
                        callback(err, workbench);
                    }
                });
            }
            else
            {
                processing.pop();
                if (processing.length == 0)
                {
github oznu / homebridge-config-ui-x / routes / log.js View on Github external
router.get("/raw/error", function (req, res, next) {
    reader.read(hb.error_log, 100).then((data) => res.send(convert(data)));
});

read-last-lines

Read in the last N lines of a file efficiently using node.js and fs.

MIT
Latest version published 3 years ago

Package Health Score

56 / 100
Full package analysis

Popular read-last-lines functions