Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorForbesLindesay <forbes@lindesay.co.uk>2013-04-28 05:04:33 +0400
committerisaacs <i@izs.me>2013-04-29 08:20:09 +0400
commitf44b1fd0935a94e253ed650504d5720fefb72a9b (patch)
treefeb43aaa0c0383efd7d00e6790f77b3c45ef8a70 /node_modules/sha
parent1ef9748c81882a90e61bbff6770c4ade23df7f37 (diff)
replace `./lib/utils/sha.js` with `sha`
closes #3381
Diffstat (limited to 'node_modules/sha')
-rw-r--r--node_modules/sha/.npmignore4
-rw-r--r--node_modules/sha/README.md32
-rw-r--r--node_modules/sha/index.js63
-rw-r--r--node_modules/sha/package.json26
4 files changed, 125 insertions, 0 deletions
diff --git a/node_modules/sha/.npmignore b/node_modules/sha/.npmignore
new file mode 100644
index 000000000..fcfd94494
--- /dev/null
+++ b/node_modules/sha/.npmignore
@@ -0,0 +1,4 @@
+node_modules
+test
+.gitignore
+.travis.yml \ No newline at end of file
diff --git a/node_modules/sha/README.md b/node_modules/sha/README.md
new file mode 100644
index 000000000..9ac740731
--- /dev/null
+++ b/node_modules/sha/README.md
@@ -0,0 +1,32 @@
+# sha
+
+Check and get file hashes (using any algorithm)
+
+[![Build Status](https://travis-ci.org/ForbesLindesay/sha.png?branch=master)](https://travis-ci.org/ForbesLindesay/sha)
+[![Dependency Status](https://gemnasium.com/ForbesLindesay/sha.png)](https://gemnasium.com/ForbesLindesay/sha)
+
+## Installation
+
+ $ npm install sha
+
+## API
+
+### check(fileName, expected, [options,] cb)
+
+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).
+
+Options:
+
+- algorithm: defaults to `sha1` and can be any of the algorithms supported by `crypto.createHash`
+
+### get(fileName, [options,] cb)
+
+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.
+
+Options:
+
+- algorithm: defaults to `sha1` and can be any of the algorithms supported by `crypto.createHash`
+
+## License
+
+BSD
diff --git a/node_modules/sha/index.js b/node_modules/sha/index.js
new file mode 100644
index 000000000..8e4e13683
--- /dev/null
+++ b/node_modules/sha/index.js
@@ -0,0 +1,63 @@
+var crypto = require('crypto')
+var fs
+try {
+ fs = require('graceful-fs')
+} catch (ex) {
+ fs = require('fs')
+}
+try {
+ process.binding('crypto')
+} catch (e) {
+ var er = new Error( 'crypto binding not found.\n'
+ + 'Please build node with openssl.\n'
+ + e.message )
+ throw er
+}
+
+exports.check = check
+exports.get = get
+
+function check(file, expected, options, cb) {
+ if (typeof options === 'function') {
+ cb = options;
+ options = undefined;
+ }
+ expected = expected.toLowerCase().trim();
+ get(file, options, function (er, actual) {
+ if (er) {
+ if (er.message) er.message += ' while getting shasum for ' + file;
+ return cb(er)
+ }
+ if (actual === expected) return cb(null);
+ cb(new Error(
+ 'shasum check failed for ' + file + '\n'
+ + 'Expected: ' + expected + '\n'
+ + 'Actual: ' + actual))
+ })
+}
+
+function get(file, options, cb) {
+ if (typeof options === 'function') {
+ cb = options;
+ options = undefined;
+ }
+ options = options || {};
+ var algorithm = options.algorithm || 'sha1';
+ var hash = crypto.createHash(algorithm)
+ var source = fs.createReadStream(file)
+ var errState = null
+ source
+ .on('error', function (er) {
+ if (errState) return
+ return cb(errState = er)
+ })
+ .on('data', function (chunk) {
+ if (errState) return
+ hash.update(chunk)
+ })
+ .on('end', function () {
+ if (errState) return
+ var actual = hash.digest("hex").toLowerCase().trim()
+ cb(null, actual)
+ })
+}
diff --git a/node_modules/sha/package.json b/node_modules/sha/package.json
new file mode 100644
index 000000000..3b0e5822e
--- /dev/null
+++ b/node_modules/sha/package.json
@@ -0,0 +1,26 @@
+{
+ "name": "sha",
+ "version": "1.0.1",
+ "description": "Check and get file hashes",
+ "scripts": {
+ "test": "mocha -R list"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/ForbesLindesay/sha.git"
+ },
+ "license": "BSD",
+ "optionalDependencies": {
+ "graceful-fs": "1.2"
+ },
+ "devDependencies": {
+ "mocha": "~1.9.0"
+ },
+ "readme": "# sha\r\n\r\nCheck and get file hashes (using any algorithm)\r\n\r\n[![Build Status](https://travis-ci.org/ForbesLindesay/sha.png?branch=master)](https://travis-ci.org/ForbesLindesay/sha)\r\n[![Dependency Status](https://gemnasium.com/ForbesLindesay/sha.png)](https://gemnasium.com/ForbesLindesay/sha)\r\n\r\n## Installation\r\n\r\n $ npm install sha\r\n\r\n## API\r\n\r\n### check(fileName, expected, [options,] cb)\r\n\r\nAsynchronously 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).\r\n\r\nOptions:\r\n\r\n- algorithm: defaults to `sha1` and can be any of the algorithms supported by `crypto.createHash`\r\n\r\n### get(fileName, [options,] cb)\r\n\r\nAsynchronously get the \"hash\" of `fileName`. The callback will be called with an optional `error` object and the (lower cased) hex digest of the hash.\r\n\r\nOptions:\r\n\r\n- algorithm: defaults to `sha1` and can be any of the algorithms supported by `crypto.createHash`\r\n\r\n## License\r\n\r\nBSD\r\n",
+ "readmeFilename": "README.md",
+ "_id": "sha@1.0.1",
+ "dependencies": {
+ "graceful-fs": "1.2"
+ },
+ "_from": "sha@~1.0.1"
+}