diff options
author | isaacs <i@izs.me> | 2013-07-22 23:14:47 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-07-22 23:15:03 +0400 |
commit | 786e06ef81265351c73f2395b0f6dbdb5a5f01c8 (patch) | |
tree | 7d0c15aa644a07b874d3a22ceb09407af1803e2a /node_modules/sha | |
parent | 349b6983bdefdbc634efbca0b54bdb8c9ff71965 (diff) |
Bump many deps for graceful-fs@2 upgrade
Diffstat (limited to 'node_modules/sha')
-rw-r--r-- | node_modules/sha/LICENSE | 46 | ||||
-rw-r--r-- | node_modules/sha/README.md | 23 | ||||
-rw-r--r-- | node_modules/sha/index.js | 75 | ||||
-rw-r--r-- | node_modules/sha/package.json | 19 |
4 files changed, 144 insertions, 19 deletions
diff --git a/node_modules/sha/LICENSE b/node_modules/sha/LICENSE new file mode 100644 index 000000000..048a6f99d --- /dev/null +++ b/node_modules/sha/LICENSE @@ -0,0 +1,46 @@ +Copyright (c) 2013 Forbes Lindesay + +The BSD License + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS +BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE.
\ No newline at end of file diff --git a/node_modules/sha/README.md b/node_modules/sha/README.md index 9ac740731..1743236b2 100644 --- a/node_modules/sha/README.md +++ b/node_modules/sha/README.md @@ -4,6 +4,7 @@ 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) +[![NPM version](https://badge.fury.io/js/sha.png)](http://badge.fury.io/js/sha) ## Installation @@ -11,7 +12,7 @@ Check and get file hashes (using any algorithm) ## API -### check(fileName, expected, [options,] cb) +### check(fileName, expected, [options,] cb) / checkSync(filename, expected, [options]) 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). @@ -19,7 +20,7 @@ Options: - algorithm: defaults to `sha1` and can be any of the algorithms supported by `crypto.createHash` -### get(fileName, [options,] cb) +### get(fileName, [options,] cb) / getSync(filename, [options]) 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. @@ -27,6 +28,22 @@ Options: - algorithm: defaults to `sha1` and can be any of the algorithms supported by `crypto.createHash` +### stream(expected, [options]) + +Check the hash of a stream without ever buffering it. This is a pass through stream so you can do things like: + +```js +fs.createReadStream('src') + .pipe(sha.stream('expected')) + .pipe(fs.createWriteStream('dest')) +``` + +`dest` will be a complete copy of `src` and an error will be emitted if the hash did not match `'expected'`. + +Options: + +- algorithm: defaults to `sha1` and can be any of the algorithms supported by `crypto.createHash` + ## License -BSD +You may use this software under the BSD or MIT. Take your pick. If you want me to release it under another license, open a pull request.
\ No newline at end of file diff --git a/node_modules/sha/index.js b/node_modules/sha/index.js index 8e4e13683..4d05a1888 100644 --- a/node_modules/sha/index.js +++ b/node_modules/sha/index.js @@ -1,3 +1,6 @@ +'use strict' + +var Transform = require('stream').Transform || require('readable-stream').Transform var crypto = require('crypto') var fs try { @@ -15,34 +18,55 @@ try { } exports.check = check +exports.checkSync = checkSync exports.get = get +exports.getSync = getSync +exports.stream = stream function check(file, expected, options, cb) { if (typeof options === 'function') { - cb = options; - options = undefined; + cb = options + options = undefined } - expected = expected.toLowerCase().trim(); + expected = expected.toLowerCase().trim() get(file, options, function (er, actual) { if (er) { - if (er.message) er.message += ' while getting shasum for ' + file; + if (er.message) er.message += ' while getting shasum for ' + file return cb(er) } - if (actual === expected) return cb(null); + if (actual === expected) return cb(null) cb(new Error( 'shasum check failed for ' + file + '\n' + 'Expected: ' + expected + '\n' + 'Actual: ' + actual)) }) } +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) { if (typeof options === 'function') { - cb = options; - options = undefined; + cb = options + options = undefined } - options = options || {}; - var algorithm = options.algorithm || 'sha1'; + options = options || {} + var algorithm = options.algorithm || 'sha1' var hash = crypto.createHash(algorithm) var source = fs.createReadStream(file) var errState = null @@ -61,3 +85,36 @@ function get(file, options, cb) { cb(null, actual) }) } + +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) { + expected = expected.toLowerCase().trim() + options = options || {} + var algorithm = options.algorithm || 'sha1' + var hash = crypto.createHash(algorithm) + + var stream = new Transform() + stream._transform = function (chunk, encoding, callback) { + hash.update(chunk) + stream.push(chunk) + callback() + } + stream._flush = function (cb) { + var actual = hash.digest("hex").toLowerCase().trim() + if (actual === expected) return cb(null) + cb(new Error( + 'shasum check failed for:\n' + + ' Expected: ' + expected + '\n' + + ' Actual: ' + actual)) + this.push(null) + } + return stream +}
\ No newline at end of file diff --git a/node_modules/sha/package.json b/node_modules/sha/package.json index 3b0e5822e..c2c7dc6b6 100644 --- a/node_modules/sha/package.json +++ b/node_modules/sha/package.json @@ -1,9 +1,9 @@ { "name": "sha", - "version": "1.0.1", + "version": "1.2.1", "description": "Check and get file hashes", "scripts": { - "test": "mocha -R list" + "test": "mocha -R spec" }, "repository": { "type": "git", @@ -11,16 +11,21 @@ }, "license": "BSD", "optionalDependencies": { - "graceful-fs": "1.2" + "graceful-fs": "2", + "readable-stream": "1.0" }, "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", + "readme": "# sha\n\nCheck and get file hashes (using any algorithm)\n\n[![Build Status](https://travis-ci.org/ForbesLindesay/sha.png?branch=master)](https://travis-ci.org/ForbesLindesay/sha)\n[![Dependency Status](https://gemnasium.com/ForbesLindesay/sha.png)](https://gemnasium.com/ForbesLindesay/sha)\n[![NPM version](https://badge.fury.io/js/sha.png)](http://badge.fury.io/js/sha)\n\n## Installation\n\n $ npm install sha\n\n## API\n\n### check(fileName, expected, [options,] cb) / checkSync(filename, expected, [options])\n\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).\n\nOptions:\n\n- algorithm: defaults to `sha1` and can be any of the algorithms supported by `crypto.createHash`\n\n### get(fileName, [options,] cb) / getSync(filename, [options])\n\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.\n\nOptions:\n\n- algorithm: defaults to `sha1` and can be any of the algorithms supported by `crypto.createHash`\n\n### stream(expected, [options])\n\nCheck the hash of a stream without ever buffering it. This is a pass through stream so you can do things like:\n\n```js\nfs.createReadStream('src')\n .pipe(sha.stream('expected'))\n .pipe(fs.createWriteStream('dest'))\n```\n\n`dest` will be a complete copy of `src` and an error will be emitted if the hash did not match `'expected'`.\n\nOptions:\n\n- algorithm: defaults to `sha1` and can be any of the algorithms supported by `crypto.createHash`\n\n## License\n\nYou may use this software under the BSD or MIT. Take your pick. If you want me to release it under another license, open a pull request.", "readmeFilename": "README.md", - "_id": "sha@1.0.1", + "bugs": { + "url": "https://github.com/ForbesLindesay/sha/issues" + }, "dependencies": { - "graceful-fs": "1.2" + "graceful-fs": "2", + "readable-stream": "1.0" }, - "_from": "sha@~1.0.1" + "_id": "sha@1.2.1", + "_from": "sha@latest" } |