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 🙏

© 2026 – Pkg Stats / Ryan Hefner

fh-streamer

v0.2.1

Published

A utility for parsing text streams and returning chunks and offsets as an array of lines

Readme

fh-streamer

Utility module for returning lines of text from streams and files as an array of lines.

The newline character \n is used to identify line breaks.

The use case for this module is for "live" rendering of log files. The typical approach would be as follows:

    Get last X number of lines in the log file (lastLinesInFile) - this returns the lines as an array and the total number of line (i.e. offset for future reads) in the (stream) that has been processed

    while true
      get any changes in log file (fromOffsetInFile)
    done

The first call will use lastLinesInFile or lastLinesInStream which returns an array of lines and an offset value indicating what position in the file/stream was read up to (i.e. how many lines in total were in the file/stream). This value can be sent in subsequent requests to fromOffsetInFile/fromOffsetInStream.

fromOffsetInFile/fromOffsetInStream also returns the offset of the last position in the file which has been read to

Usage

Getting the last 100 lines from a file:

    var streamer = require('fh-streamer');
    streamer.lastLinesInFile(100, './res/test.log', function(res) {
      // Returns an array containing the last 100 lines (or as many as exist if less than 100)
      // and the offset that reading finished at - i.e. total number of lines in the file,
      // res = {
      //    'offset': 1200,
      //    'data': [
      //            ...
      //            ]
      //  }
      console.log(res);
    });

Getting the last 200 lines from an existing stream:

    var streamer = require('fh-streamer');
    var myStream = someFunctionThatReturnsAStream;
    streamer.lastLinesInStream(200, myStream, function(res) {
      // Returns an array containing the last 200 lines (or as many as exist if less than 200)
      // and the offset that reading finished at - i.e. total number of lines in the stream,
      // res = {
      //    'offset': 1200,
      //    'data': [
      //            ...
      //            ]
      //  }
      console.log(res);
    });

Getting the contents of a file from line #1200:

    var streamer = require('fh-streamer');
    streamer.fromOffsetInFile(offset':1200, './res/test.log', function(res) {
      // Returns an array containing all lines beyond #1200 onwards, or none if there are no lines
      // and the offset that reading finished at - i.e. total number of lines in the file
      // res = {
      //    'offset': 1350,
      //    'data': [
      //            ...
      //            ]

      //  }
      console.log(res);
    });

Getting the contents of a stream from line #1350:

    var streamer = require('fh-streamer');
    var myStream = someFunctionThatReturnsAStream;
    streamer.fromOffsetInStream(1350, myStream, function(res) {
      // Returns an array containing all lines from 1350  onwards, or none if there are no lines
      // and the offset that reading finished at - i.e. total number of lines in the stream
      // res = {
      //    'offset': 1800,
      //    'data': [
      //            ...
      //            ]
      //  }
      console.log(res);
    });