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

sha

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sha - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

31

index.js

@@ -0,1 +1,3 @@

'use strict'
var Transform = require('stream').Transform || require('readable-stream').Transform

@@ -19,3 +21,5 @@ var crypto = require('crypto')

exports.check = check
exports.checkSync = checkSync
exports.get = get
exports.getSync = getSync
exports.stream = stream

@@ -41,3 +45,21 @@

}
function checkSync(file, expected, options, cb) {
expected = expected.toLowerCase().trim()
var actual
try {
actual = getSync(file, options)
} catch (er) {
if (er.message) er.message += ' while getting shasum for ' + file
throw er
}
if (actual !== expected) {
var ex = new Error(
'shasum check failed for ' + file + '\n'
+ 'Expected: ' + expected + '\n'
+ 'Actual: ' + actual)
throw ex
}
}
function get(file, options, cb) {

@@ -69,2 +91,11 @@ if (typeof options === 'function') {

function getSync(file, options) {
options = options || {}
var algorithm = options.algorithm || 'sha1'
var hash = crypto.createHash(algorithm)
var source = fs.readFileSync(file)
hash.update(source)
return hash.digest("hex").toLowerCase().trim()
}
function stream(expected, options) {

@@ -71,0 +102,0 @@ expected = expected.toLowerCase().trim()

4

package.json
{
"name": "sha",
"version": "1.1.0",
"version": "1.2.0",
"description": "Check and get file hashes",
"scripts": {
"test": "mocha -R list"
"test": "mocha -R spec"
},

@@ -8,0 +8,0 @@ "repository": {

@@ -15,3 +15,3 @@ # sha

### check(fileName, expected, [options,] cb)
### check(fileName, expected, [options,] cb) / checkSync(filename, expected, [options])

@@ -24,3 +24,3 @@ Asynchronously check that `fileName` has a "hash" of `expected`. The callback will be called with either `null` or an error (indicating that they did not match).

### get(fileName, [options,] cb)
### get(fileName, [options,] cb) / getSync(filename, [options])

@@ -27,0 +27,0 @@ Asynchronously get the "hash" of `fileName`. The callback will be called with an optional `error` object and the (lower cased) hex digest of the hash.

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