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() |
{ | ||
"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. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7765
111