1.0.0 • Published 7 years ago

hashist v1.0.0

Weekly downloads
94
License
ISC
Repository
github
Last release
7 years ago

hashist Build Status

Provides you with a convenient hash function that uses Node's crypto module under the hood.

Install

npm install hashist --save

Usage

var hashist = require('hashist');

// uses sha1 by default
hashist('Hello World!'); # 2ef7bde608ce5404e97d5f042f95f89f1c232871

API

hashist(what: [String | Buffer], algorithm: String): String hashist.stream(what: Readable, algorithm: String): Promise<String>

what

Can be a string or buffer. There is an API for streams that can be used. It is hashist.stream and it returns a Promise that results in the digest.

Examples

Use with strings

const hashist = require('hashist');
console.log(hashist('Hello World!', 'sha1')); // 2ef7bde608ce5404e97d5f042f95f89f1c232871

Use with buffers

const hashist = require('hashist');
const buffer = new Buffer('Hello World!');
console.log(hashist(buffer)); // 2ef7bde608ce5404e97d5f042f95f89f1c232871

Use with streams

const hashist = require('hashist');
const { Readable } = require('stream');

class FakeStream extends Readable {
  constructor(...args) {
    super(...args);
    this._sentText = false;
  }
  _read() {
    if (!this._sentText) {
      this.push(testText);
      this._sentText = true;
    } else {
      this.push(null);
    }
  }
}

hashist(fakeStream).then(digest => {
  console.log(digest); // 2ef7bde608ce5404e97d5f042f95f89f1c232871
})