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

slice-file-ml

v1.0.0

Published

stream file slices by line number indexes

Downloads

2

Readme

slice-file

stream file slices by line number indexes

build status

example

positive slice

var sf = require('slice-file');
var words = sf('/usr/share/dict/words');
words.slice(22398,22408).pipe(process.stdout);
beep
beep's
beeped
beeper
beeper's
beepers
beeping
beeps
beer
beer's

tail

var sf = require('slice-file');
var xs = sf('/usr/share/dict/words');
xs.slice(-10).pipe(process.stdout);
élan's
émigré
émigré's
émigrés
épée
épée's
épées
étude
étude's
études

follow

Like tail -f, slice-file can stream updates after the initial slice.

var sf = require('slice-file');
var xs = sf('/var/mail/' + process.env.USER);
xs.follow(-10).pipe(process.stdout);

at first the previous 10 lines will render:

$ node example/mail.js 
    id A2181740063; Fri, 12 Apr 2013 03:08:30 -0700 (PDT)
Subject: beep boop
To: <substack@beep>
X-Mailer: mail (GNU Mailutils 2.2)
Message-Id: <20130412100830.A2181740063@beep>
Date: Fri, 12 Apr 2013 03:08:30 -0700 (PDT)
From: substack@beep

oh hello

then if a message is sent:

$ echo ahoy thar | mail -s 'oy' substack

we see more data from the file:

From substack@beep  Fri Apr 12 03:09:13 2013
Return-Path: <substack@beep>
X-Original-To: substack@beep
Delivered-To: substack@beep
Received: by beep (Postfix, from userid 1000)
    id 5E0C7740063; Fri, 12 Apr 2013 03:09:13 -0700 (PDT)
Subject: oy
To: <substack@beep>
X-Mailer: mail (GNU Mailutils 2.2)
Message-Id: <20130412100913.5E0C7740063@beep>
Date: Fri, 12 Apr 2013 03:09:13 -0700 (PDT)
From: substack@beep

ahoy thar

reverse

You can also slice in reverse order, which is more efficient for negative-indexed slices because the lines don't need to be buffered:

var sf = require('slice-file');
var xs = sf('/usr/share/dict/words');
xs.sliceReverse(-10).pipe(process.stdout);
événements
événement
évolués
évolué
étuis
étui's
étui
études
étude's
étude

methods

var sf = require('slice-file')

var xs = sf(filename, opts={})

Create a slice-file instance xs from a filename and some options opts.

These opts are passed to fs.open():

  • opts.flags - string flags to open the file with, default "r"
  • opts.mode - mask to open the file with, default 0666

If you already have a file descriptor open you can pass opts.fd to skip calling fs.open().

Use opts.bufsize to set how much data to read in each chunk. Default 4096.

var stream = xs.slice(i, j, cb)

Return a readable stream that emits each line between line numbers [i,j) exactly like Array.prototype.slice(). Each line data buffer includes a trailing "\n" except for the last line if there is no trailing newline before the EOF.

Just like Array.prototype.slice(), i and j may be negative.

If cb(err, lines) is given, the lines will be buffered into lines.

var stream = xs.sliceReverse(i, j, cb)

Return a readable stream that emits each line between line numbers [i,j) just like .slice() but in reverse order. This is more efficient for negative-indexed slices because the lines don't need to be buffered.

If cb(err, lines) is given, the lines will be buffered into lines.

var stream = xs.follow(i, j)

Return a readable stream of lines like xs.slice(), but instead of ending when the end of the file is reached, watch the file and stream new lines appended to the end of the file.

This feature takes its name from tail -f.

xs.close()

Close the underlying file descriptor, stop any streams, and stop any file watchers.

install

With npm do:

npm install slice-file

license

MIT