sha@1.2.3

This commit is contained in:
isaacs
2013-09-07 14:23:12 -05:00
parent 7ccb44bab0
commit 700826bcd6
10 changed files with 411 additions and 269 deletions

6
node_modules/sha/.npmignore generated vendored
View File

@@ -1,4 +1,4 @@
node_modules
test
.gitignore
node_modules
test
.gitignore
.travis.yml

90
node_modules/sha/LICENSE generated vendored
View File

@@ -1,46 +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
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.

96
node_modules/sha/README.md generated vendored
View File

@@ -1,49 +1,49 @@
# 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)
[![NPM version](https://badge.fury.io/js/sha.png)](http://badge.fury.io/js/sha)
## Installation
$ npm install sha
## API
### 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).
Options:
- algorithm: defaults to `sha1` and can be any of the algorithms supported by `crypto.createHash`
### 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.
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
# 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)
[![NPM version](https://badge.fury.io/js/sha.png)](http://badge.fury.io/js/sha)
## Installation
$ npm install sha
## API
### 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).
Options:
- algorithm: defaults to `sha1` and can be any of the algorithms supported by `crypto.createHash`
### 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.
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
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.

238
node_modules/sha/index.js generated vendored
View File

@@ -1,120 +1,120 @@
'use strict'
var Transform = require('stream').Transform || require('readable-stream').Transform
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.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
}
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 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
}
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)
})
}
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
'use strict'
var Transform = require('stream').Transform || require('readable-stream').Transform
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.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
}
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 checkSync(file, expected, options) {
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
}
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)
})
}
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
}

View File

@@ -0,0 +1,68 @@
diff --git a/lib/_stream_duplex.js b/lib/_stream_duplex.js
index c5a741c..a2e0d8e 100644
--- a/lib/_stream_duplex.js
+++ b/lib/_stream_duplex.js
@@ -26,8 +26,8 @@
module.exports = Duplex;
var util = require('util');
-var Readable = require('_stream_readable');
-var Writable = require('_stream_writable');
+var Readable = require('./_stream_readable');
+var Writable = require('./_stream_writable');
util.inherits(Duplex, Readable);
diff --git a/lib/_stream_passthrough.js b/lib/_stream_passthrough.js
index a5e9864..330c247 100644
--- a/lib/_stream_passthrough.js
+++ b/lib/_stream_passthrough.js
@@ -25,7 +25,7 @@
module.exports = PassThrough;
-var Transform = require('_stream_transform');
+var Transform = require('./_stream_transform');
var util = require('util');
util.inherits(PassThrough, Transform);
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index 2259d2e..e6681ee 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -23,6 +23,9 @@ module.exports = Readable;
Readable.ReadableState = ReadableState;
var EE = require('events').EventEmitter;
+if (!EE.listenerCount) EE.listenerCount = function(emitter, type) {
+ return emitter.listeners(type).length;
+};
var Stream = require('stream');
var util = require('util');
var StringDecoder;
diff --git a/lib/_stream_transform.js b/lib/_stream_transform.js
index e925b4b..f08b05e 100644
--- a/lib/_stream_transform.js
+++ b/lib/_stream_transform.js
@@ -64,7 +64,7 @@
module.exports = Transform;
-var Duplex = require('_stream_duplex');
+var Duplex = require('./_stream_duplex');
var util = require('util');
util.inherits(Transform, Duplex);
diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js
index a26f711..56ca47d 100644
--- a/lib/_stream_writable.js
+++ b/lib/_stream_writable.js
@@ -109,7 +109,7 @@ function WritableState(options, stream) {
function Writable(options) {
// Writable ctor is applied to Duplexes, though they're not
// instanceof Writable, they're instanceof Readable.
- if (!(this instanceof Writable) && !(this instanceof Stream.Duplex))
+ if (!(this instanceof Writable) && !(this instanceof require('./_stream_duplex')))
return new Writable(options);
this._writableState = new WritableState(options, this);

View File

@@ -68,12 +68,18 @@ function ReadableState(options, stream) {
// that we're awaiting a 'readable' event emission.
this.needReadable = false;
this.emittedReadable = false;
this.readableListening = false;
// object stream flag. Used to make read(n) ignore n and to
// make all the buffer merging and length checks go away
this.objectMode = !!options.objectMode;
// Crypto is kind of old and crusty. Historically, its default string
// encoding is 'binary' so we have to make this configurable.
// Everything else in the universe uses 'utf8', though.
this.defaultEncoding = options.defaultEncoding || 'utf8';
// when piping, we only care about 'readable' events that happen
// after read()ing all the bytes and not getting any pushback.
this.ranOut = false;
@@ -85,10 +91,12 @@ function ReadableState(options, stream) {
this.readingMore = false;
this.decoder = null;
this.encoding = null;
if (options.encoding) {
if (!StringDecoder)
StringDecoder = require('string_decoder').StringDecoder;
this.decoder = new StringDecoder(options.encoding);
this.encoding = options.encoding;
}
}
@@ -108,43 +116,61 @@ function Readable(options) {
// This returns true if the highWaterMark has not been hit yet,
// similar to how Writable.write() returns true if you should
// write() some more.
Readable.prototype.push = function(chunk) {
Readable.prototype.push = function(chunk, encoding) {
var state = this._readableState;
if (typeof chunk === 'string' && !state.objectMode)
chunk = new Buffer(chunk, arguments[1]);
return readableAddChunk(this, state, chunk, false);
if (typeof chunk === 'string' && !state.objectMode) {
encoding = encoding || state.defaultEncoding;
if (encoding !== state.encoding) {
chunk = new Buffer(chunk, encoding);
encoding = '';
}
}
return readableAddChunk(this, state, chunk, encoding, false);
};
// Unshift should *always* be something directly out of read()
Readable.prototype.unshift = function(chunk) {
var state = this._readableState;
if (typeof chunk === 'string' && !state.objectMode)
chunk = new Buffer(chunk, arguments[1]);
return readableAddChunk(this, state, chunk, true);
return readableAddChunk(this, state, chunk, '', true);
};
function readableAddChunk(stream, state, chunk, addToFront) {
state.reading = false;
function readableAddChunk(stream, state, chunk, encoding, addToFront) {
var er = chunkInvalid(state, chunk);
if (er) {
stream.emit('error', er);
} else if (chunk === null || chunk === undefined) {
onEofChunk(stream, state);
state.reading = false;
if (!state.ended)
onEofChunk(stream, state);
} else if (state.objectMode || chunk && chunk.length > 0) {
if (state.decoder)
chunk = state.decoder.write(chunk);
if (state.ended && !addToFront) {
var e = new Error('stream.push() after EOF');
stream.emit('error', e);
} else if (state.endEmitted && addToFront) {
var e = new Error('stream.unshift() after end event');
stream.emit('error', e);
} else {
if (state.decoder && !addToFront && !encoding)
chunk = state.decoder.write(chunk);
// update the buffer info.
state.length += state.objectMode ? 1 : chunk.length;
if (addToFront)
state.buffer.unshift(chunk);
else
state.buffer.push(chunk);
// update the buffer info.
state.length += state.objectMode ? 1 : chunk.length;
if (addToFront) {
state.buffer.unshift(chunk);
} else {
state.reading = false;
state.buffer.push(chunk);
}
if (state.needReadable)
emitReadable(stream);
if (state.needReadable)
emitReadable(stream);
maybeReadMore(stream, state);
maybeReadMore(stream, state);
}
} else if (!addToFront) {
state.reading = false;
}
return needMoreData(state);
@@ -171,6 +197,7 @@ Readable.prototype.setEncoding = function(enc) {
if (!StringDecoder)
StringDecoder = require('string_decoder').StringDecoder;
this._readableState.decoder = new StringDecoder(enc);
this._readableState.encoding = enc;
};
// Don't raise the hwm > 128MB
@@ -238,7 +265,7 @@ Readable.prototype.read = function(n) {
// the 'readable' event and move on.
if (n === 0 &&
state.needReadable &&
state.length >= state.highWaterMark) {
(state.length >= state.highWaterMark || state.ended)) {
emitReadable(this);
return null;
}
@@ -345,14 +372,14 @@ function chunkInvalid(state, chunk) {
function onEofChunk(stream, state) {
state.ended = true;
if (state.decoder && state.decoder.end) {
if (state.decoder && !state.ended) {
var chunk = state.decoder.end();
if (chunk && chunk.length) {
state.buffer.push(chunk);
state.length += state.objectMode ? 1 : chunk.length;
}
}
state.ended = true;
// if we've ended and we have some data left, then emit
// 'readable' now to make sure it gets picked up.
@@ -381,7 +408,6 @@ function emitReadable(stream) {
}
function emitReadable_(stream) {
var state = stream._readableState;
stream.emit('readable');
}
@@ -490,10 +516,20 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
// however, don't suppress the throwing behavior for this.
function onerror(er) {
unpipe();
dest.removeListener('error', onerror);
if (EE.listenerCount(dest, 'error') === 0)
dest.emit('error', er);
}
dest.once('error', onerror);
// This is a brutally ugly hack to make sure that our error handler
// is attached before any userland ones. NEVER DO THIS.
if (!dest._events.error)
dest.on('error', onerror);
else if (Array.isArray(dest._events.error))
dest._events.error.unshift(onerror);
else
dest._events.error = [onerror, dest._events.error];
// Both close and finish should trigger unpipe, but only once.
function onclose() {
@@ -658,8 +694,19 @@ Readable.prototype.on = function(ev, fn) {
if (ev === 'data' && !this._readableState.flowing)
emitDataEvents(this);
if (ev === 'readable' && !this._readableState.reading)
this.read(0);
if (ev === 'readable' && this.readable) {
var state = this._readableState;
if (!state.readableListening) {
state.readableListening = true;
state.emittedReadable = false;
state.needReadable = true;
if (!state.reading) {
this.read(0);
} else if (state.length) {
emitReadable(this, state);
}
}
}
return res;
};
@@ -736,8 +783,7 @@ Readable.prototype.wrap = function(stream) {
var self = this;
stream.on('end', function() {
state.ended = true;
if (state.decoder && state.decoder.end) {
if (state.decoder && !state.ended) {
var chunk = state.decoder.end();
if (chunk && chunk.length)
self.push(chunk);
@@ -749,7 +795,7 @@ Readable.prototype.wrap = function(stream) {
stream.on('data', function(chunk) {
if (state.decoder)
chunk = state.decoder.write(chunk);
if (!chunk || !chunk.length)
if (!chunk || !state.objectMode && !chunk.length)
return;
var ret = self.push(chunk);
@@ -780,10 +826,12 @@ Readable.prototype.wrap = function(stream) {
// underlying stream.
self._read = function(n) {
if (paused) {
stream.resume();
paused = false;
stream.resume();
}
};
return self;
};
@@ -867,10 +915,13 @@ function endReadable(stream) {
if (!state.endEmitted && state.calledRead) {
state.ended = true;
state.endEmitted = true;
process.nextTick(function() {
stream.readable = false;
stream.emit('end');
// Check that we didn't get one last unshift.
if (!state.endEmitted && state.length === 0) {
state.endEmitted = true;
stream.readable = false;
stream.emit('end');
}
});
}
}

View File

@@ -70,8 +70,6 @@ util.inherits(Transform, Duplex);
function TransformState(options, stream) {
var ts = this;
this.afterTransform = function(er, data) {
return afterTransform(stream, er, data);
};
@@ -101,6 +99,7 @@ function afterTransform(stream, er, data) {
cb(er);
var rs = stream._readableState;
rs.reading = false;
if (rs.needReadable || rs.length < rs.highWaterMark) {
stream._read(rs.highWaterMark);
}
@@ -136,9 +135,9 @@ function Transform(options) {
});
}
Transform.prototype.push = function(chunk) {
Transform.prototype.push = function(chunk, encoding) {
this._transformState.needTransform = false;
return Duplex.prototype.push.call(this, chunk);
return Duplex.prototype.push.call(this, chunk, encoding);
};
// This is the part where you do stuff!
@@ -151,7 +150,7 @@ Transform.prototype.push = function(chunk) {
// Call `cb(err)` when you are done with this chunk. If you pass
// an error, then that'll put the hurt on the whole operation. If you
// never call cb(), then you'll never get another chunk.
Transform.prototype._transform = function(chunk, output, cb) {
Transform.prototype._transform = function(chunk, encoding, cb) {
throw new Error('not implemented');
};
@@ -170,7 +169,7 @@ Transform.prototype._write = function(chunk, encoding, cb) {
};
// Doesn't matter what the args are here.
// the output and callback functions passed to _transform do all the work.
// _transform does all the work.
// That we got here means that the readable side wants more data.
Transform.prototype._read = function(n) {
var ts = this._transformState;

View File

@@ -68,6 +68,11 @@ function WritableState(options, stream) {
var noDecode = options.decodeStrings === false;
this.decodeStrings = !noDecode;
// Crypto is kind of old and crusty. Historically, its default string
// encoding is 'binary' so we have to make this configurable.
// Everything else in the universe uses 'utf8', though.
this.defaultEncoding = options.defaultEncoding || 'utf8';
// not an actual buffer we keep track of, but a measurement
// of how much we're waiting to get pushed to some underlying
// socket or file.
@@ -160,8 +165,11 @@ Writable.prototype.write = function(chunk, encoding, cb) {
cb = encoding;
encoding = null;
}
if (!encoding)
encoding = 'utf8';
if (Buffer.isBuffer(chunk))
encoding = 'buffer';
else if (!encoding)
encoding = state.defaultEncoding;
if (typeof cb !== 'function')
cb = function() {};
@@ -240,7 +248,8 @@ function onwrite(stream, er) {
if (er)
onwriteError(stream, state, sync, er, cb);
else {
var finished = finishMaybe(stream, state);
// Check if we're actually ready to finish, but don't emit yet
var finished = needFinish(stream, state);
if (!finished && !state.bufferProcessing && state.buffer.length)
clearBuffer(stream, state);
@@ -259,6 +268,8 @@ function afterWrite(stream, state, finished, cb) {
if (!finished)
onwriteDrain(stream, state);
cb();
if (finished)
finishMaybe(stream, state);
}
// Must force callback to be called on nextTick, so that we don't
@@ -326,12 +337,21 @@ Writable.prototype.end = function(chunk, encoding, cb) {
endWritable(this, state, cb);
};
function needFinish(stream, state) {
return (state.ending &&
state.length === 0 &&
!state.finished &&
!state.writing);
}
function finishMaybe(stream, state) {
if (state.ending && state.length === 0 && !state.finished) {
var need = needFinish(stream, state);
if (need) {
state.finished = true;
stream.emit('finish');
}
return state.finished;
return need;
}
function endWritable(stream, state, cb) {

View File

@@ -1,6 +1,6 @@
{
"name": "readable-stream",
"version": "1.0.2",
"version": "1.0.17",
"description": "An exploration of a new kind of readable streams for Node.js",
"main": "readable.js",
"dependencies": {},
@@ -30,6 +30,10 @@
"bugs": {
"url": "https://github.com/isaacs/readable-stream/issues"
},
"_id": "readable-stream@1.0.2",
"_from": "readable-stream@1.0"
"_id": "readable-stream@1.0.17",
"dist": {
"shasum": "cbc295fdf394dfa1225d225d02e6b6d0f409fd4b"
},
"_from": "readable-stream@1.0",
"_resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.17.tgz"
}

8
node_modules/sha/package.json generated vendored
View File

@@ -1,6 +1,6 @@
{
"name": "sha",
"version": "1.2.1",
"version": "1.2.3",
"description": "Check and get file hashes",
"scripts": {
"test": "mocha -R spec"
@@ -17,7 +17,7 @@
"devDependencies": {
"mocha": "~1.9.0"
},
"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.",
"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[![NPM version](https://badge.fury.io/js/sha.png)](http://badge.fury.io/js/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) / checkSync(filename, expected, [options])\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) / getSync(filename, [options])\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### stream(expected, [options])\r\n\r\nCheck the hash of a stream without ever buffering it. This is a pass through stream so you can do things like:\r\n\r\n```js\r\nfs.createReadStream('src')\r\n .pipe(sha.stream('expected'))\r\n .pipe(fs.createWriteStream('dest'))\r\n```\r\n\r\n`dest` will be a complete copy of `src` and an error will be emitted if the hash did not match `'expected'`.\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\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",
"bugs": {
"url": "https://github.com/ForbesLindesay/sha/issues"
@@ -26,6 +26,6 @@
"graceful-fs": "2",
"readable-stream": "1.0"
},
"_id": "sha@1.2.1",
"_from": "sha@~1.2.1"
"_id": "sha@1.2.3",
"_from": "sha@latest"
}