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

stream-hasher

v1.4.2

Published

A through-stream that calculates hash-digests on the fly

Downloads

29

Readme

stream-hasher

npm version

A transform-stream that emits hash-digests of streams or vinyl-file-streams

Features

Works with vinyl-streams in buffer- and stream-mode, optionally renames files.

Usage

Single Data Stream

import fs from 'fs';
import streamHasher from 'stream-hasher';

const hasher = streamHasher({single: true});
hasher.on('digest', function(digest) {
  console.log('digest=%s', digest)
});

fs.createReadStream('package.json')
  .pipe(hasher)
  .resume();
  // it's a stream2, so pipe it along or dump it, otherwise it will stuck.

Vinyl File Stream

import vinylFs from 'vinyl-fs';
import streamHasher from 'stream-hasher';

const hasher = streamHasher();
hasher.on('digest', function(digest, tag) {
  console.log('digest=%s tag=%s', digest, tag)
});

vinylFs.src(['src/**/*.js'], {buffer: false}) // works with 'buffer: true', too 
  .pipe(hasher)
  .pipe(vinylFs.dest('dist'));

API

const hasher = streamHasher(options);

Creates a new hasher. Recognized options are:

  • algorithm (string, default: 'sha1'): the hash-algorithm to be used. See crypto.createHash for available algorithms.
  • digestEncoding (string, default: 'hex'): how the resulting digest is encoded. See Buffer#toString for available encodings. Use 'buffer' to get a bare buffer.
  • digestLength (number): if supplied, the digest length is limited to this length.
  • single (boolean, default: false): If true, create a hasher that transforms a single data-stream. If false, create a hasher to transform a vinyl-file-stream. In latter case, the following additional options are recognized:
    • tagger (function(file)): a function that generates the tag from the processed vinyl-file. Defaults to a function that returns file.path.
    • optioner (function(file)): a function that generates an object to overwrite options per vinyl-file.
    • rename: (function(basename, digest) or string): a function that takes the original file name (without extension) and the calculated digest and should return a replacement file name. The strings 'postfix' and 'prefix' can be used, too. They expose some standard replacers.
    • renameFile (function (file)): to obtain even finer control of renaming supply a function that takes a vinyl-file and the digest to directly manipulate the file's path.
    • maxSingleSize (number): In the special case of an stream-file to be renamed, the digest must me emitted before the file can be passed forward. Then is value is used to set the highWaterMark for processing that file to prevent deadlocking. Default is 16MB.

Event 'digest'

is emitted for every calculated hash-digest

  • digest: the calculated digest
  • tag: the file's tag
  • newTag: if renaming was specified, this is the file's tag after renaming