npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fire-read

v1.0.3

Published

Line by Line reader for multiple files automatically continuing to the next file on EOF.

Downloads

10

Readme

Fire-Read

Read multiple files line by line (to avoid chocking your RAM) and one after the other till all files are read!

This module automates the process of reading each line and automatically skipping to the next file using just one convenient method; read().

Example Use


// require
const fireRead = require('fire-read');

// initialize
let resp = new FireRead({

    // we want to read these three log files
	files: [
		'/logs/info-2022-08-25.log',
		'/logs/info-2022-08-24.log',
		'/logs/info-2022-01-24.log',
	],

    // We also want to read one line at a time
	lines: 1, 

    // we want all line buffers decoded into ascii
    encoding : 'ascii',

    // optionally parse lines of each file read
    // parser: JSON.parse

});

// loop through all lines and files
while ((resp = resp.read())) {
	console.log(resp);
}

console.log('Finished Reading');

This produces the following logs:

{
  files: {
    current: '/logs/info-2022-01-24.log',
    selected: [
      '/logs/info-2022-08-25.log',
      '/logs/info-2022-08-24.log',
      '/logs/info-2022-01-24.log'
    ]
  },
  fileNum: 2,
  lineNum: 959,
  lines: [
    `{"level":"info","message":"hello world","timestamp":"2022-08-24 08:26:58.035 PM"}`
  ],
  read: [Function: bound read]
}

Finished Reading

What is Going on?

new FireRead(options}) returns an instance of the fire-read with the convenient read() method that you can use to read each line in every file given.

Every time you call read() it also wraps in an instance of itself so you can iterate through all reads till there are none to do.

So while ((resp = resp.read())) {} simply iterates through all line reads and files till there is nothing more to read, at which point it returns null.

Options

The following options are needed and expected by the module.

  • files : an Array of files to read. Required.

  • lines : the number (batch) of lines to read every time read() is called. Defaults to 20;

  • encoding : the type encoding to use while converting the line Buffer to string. See Buffer.toString Documentation. Defaults to "ascii".

  • parser : a function used to parse each line in your logs. Many file loggers like bunyan write each log line as JSON strings. Defaults to no parsing.

    So in the example above we could have enabled the JSON parser by passing JSON.parse to ensure lines are parsed as shown below.

    {
        level: 'info',
        message: 'hello world',
        timestamp: '2022-08-24 09:53:53.373 PM'
    }