Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-sha1

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-sha1

Exports a SHA1 function that uses node's crpyto module under the hood

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

node-sha1 Build Status

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

Install

npm install node-sha1 --save

Usage

var sha1 = require('node-sha1');
sha1('Hello World!'); # 2ef7bde608ce5404e97d5f042f95f89f1c232871

API

sha1(what, callback)

what

Can be a string, buffer, or even a stream (stream requires a callback).

If what is a string, or a buffer the hash will be returned, if a callback is registered it will also be called with the resulting hash.

If what is a stream, it will throw if a callback is not registered. Otherwise it will call the callback with the resulting hash.

callback(err, hash)

err any errors that occurred, or undefined if no errors occurred. hash is the resulting hash. If a callback is registered it will be called with the resulting hash regardless if a stream, string, or buffer is used.

Examples

Use with strings

var sha1 = require('node-sha1');
sha1('Hello World!'); # 2ef7bde608ce5404e97d5f042f95f89f1c232871

Use with buffers

var sha1 = require('node-sha1');
var buffer = new Buffer('Hello World!');
sha1(buffer); # 2ef7bde608ce5404e97d5f042f95f89f1c232871

Use with streams

var sha1 = require('node-sha1');

util.inherits(FakeStream, stream.Readable);

function FakeStream() {
  this._finished = false;
  stream.Readable.call(this);
}

FakeStream.prototype._read = function() {
  if (this._finished) {
    this.push(null);
    return;
  }
  this._finished = true;
  this.push('Hello World!');
};

var fakeStream = new FakeStream();
sha1(fakeStream, function(err, hash) {
  # hash = 2ef7bde608ce5404e97d5f042f95f89f1c232871
})

Keywords

FAQs

Package last updated on 11 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc