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

fwalker

v1.0.3

Published

Fast and rock-solid asynchronous traversing of directories and files for NodeJS

Downloads

12

Readme

Build Status version

fwalker

Fast and rock-solid asynchronous traversing of directories and files for NodeJS

👉 This library started as a fork of node-filewalker, created by Oliver Leics which is not maintained anymore.

Main differences from node-filewalker:

  • New option readStream
  • New option fs
  • Dependency updates (security fixes)

This library is designed to provide maximum reliance paired with maximum throughput/performance. Please feel free to contribute!

Installation

npm install --save fwalker

Usage

Simple directory listing and disk-usage report:

var fwalker = require('fwalker');

fwalker('.')
  .on('dir', function(p) {
    console.log('dir:  %s', p);
  })
  .on('file', function(p, s) {
    console.log('file: %s, %d bytes', p, s.size);
  })
  .on('error', function(err) {
    console.error(err);
  })
  .on('done', function() {
    console.log('%d dirs, %d files, %d bytes', this.dirs, this.files, this.bytes);
  })
.walk();

Calculate md5-hash for every file:

var started = Date.now();

var createHash = require('crypto').createHash,
    fwalker = require('fwalker');

var options = {
  maxPending: 10, // throttle handles
};

fwalker('/', options)
  .on('stream', function(rs, p, s, fullPath) {
    var hash = createHash('md5');
    rs.on('data', function(data) {
      hash.update(data);
    });
    rs.on('end', function(data) {
      console.log(hash.digest('hex'), ('                '+s.size).slice(-16), p);
    });
  })
  .on('error', function(err) {
    console.error(err);
  })
  .on('done', function() {
    var duration = Date.now()-started;
    console.log('%d ms', duration);
    console.log('%d dirs, %d files, %d bytes', this.dirs, this.files, this.bytes);
  })
.walk();

FWalker pseudo-class

Inherits from node-fqueue.

Options

maxPending

  • Default: -1
  • Maximum asynchronous jobs. Useful to throttle the number of simultaneous disk-operations.

maxAttempts

  • Default: 3
  • Maximum reattempts on error.
  • Set to 0 to disable reattempts.
  • Set to -1 for infinite reattempts.

attemptTimeout

  • Default: 5000 ms
  • Minimum time to wait before reattempt, in milliseconds.
  • Useful to let network-drives remount, etc.

matchRegExp

  • Default: null
  • A RegExp-instance the path to a file must match in order to emit a "file" event.
  • Set to null to emit all paths.

recursive

  • Default: true
  • Traverse in a recursive manner.
  • In case you wish to target only the current directory, disable this.

readStream

  • Default: fs.createReadStream()'s default values
  • New in fwalker (it does not exist in node-filewalker)
  • Allow to handle streams better. For example, the following configuration allows to read a text file from a range of bytes:

var options = {
  // will read from byte 90 to 99
  readStream: {
    start: 90,
    end: 99
  },
  // from simple.txt
  matchRegExp: /simple\.txt/
};

fwalker( '.', options )
  ...

fs

  • Default: fs from NodeJS
  • New in fwalker (it does not exist in node-filewalker)
  • Allow to use a filesystem library different from fs, such as memfs.
  • Allow to use in-memory filesystems.
  • Very useful for testing purposes.

Properties

maxPending
maxAttempts
attemptTimeout
matchRegExp

pending
dirs
files
total
bytes
errors
attempts
streamed
open
detectedMaxOpen

Methods

walk()
pause()
resume()

Events

  • file
    • relative path
    • fs.Stats instance
    • absolute path
  • dir
    • relative path
    • fs.Stats instance
    • absolute path
  • stream
    • fs.ReadStream instance
    • relative path
    • fs.Stats instance
    • absolute path
  • pause
  • resume
  • done
  • error
    • instance of Error

Notice: There will be no fs.ReadStream created if no listener listens to the 'stream'-event.

License

MIT (c) Thiago Delgado Pinto and Oliver Leics