v1.0.2: Update documentation, add combined-stream2 support, remove stray console.log
This commit is contained in:
parent
7fd2c158a4
commit
49826545e4
10
README.md
10
README.md
|
@ -6,7 +6,7 @@ Supports both Promises and nodebacks.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
[WTFPL](http://www.wtfpl.net/txt/copying/) or [CC0](https://creativecommons.org/publicdomain/zero/1.0/), whichever you prefer.
|
[WTFPL](http://www.wtfpl.net/txt/copying/) or [CC0](https://creativecommons.org/publicdomain/zero/1.0/), whichever you prefer. A donation and/or attribution are appreciated, but not required.
|
||||||
|
|
||||||
## Donate
|
## Donate
|
||||||
|
|
||||||
|
@ -22,6 +22,14 @@ Build tool of choice is `gulp`; simply run `gulp` while developing, and it will
|
||||||
|
|
||||||
Be aware that by making a pull request, you agree to release your modifications under the licenses stated above.
|
Be aware that by making a pull request, you agree to release your modifications under the licenses stated above.
|
||||||
|
|
||||||
|
## Supported stream types
|
||||||
|
|
||||||
|
* Buffers
|
||||||
|
* `fs.createReadStream` streams
|
||||||
|
* `http.request` and `http.get` responses
|
||||||
|
* `request` requests
|
||||||
|
* `combined-stream2` streams
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Using Promises:
|
Using Promises:
|
||||||
|
|
|
@ -9,7 +9,6 @@ createRetrieverPromise = (stream, retriever) ->
|
||||||
retriever stream, (result) ->
|
retriever stream, (result) ->
|
||||||
if result?
|
if result?
|
||||||
if result instanceof Error
|
if result instanceof Error
|
||||||
console.log "REJECTING...", result
|
|
||||||
reject result
|
reject result
|
||||||
else
|
else
|
||||||
resolve result
|
resolve result
|
||||||
|
@ -55,6 +54,14 @@ retrieveRequestHttpStream = (stream, callback) ->
|
||||||
else
|
else
|
||||||
callback null
|
callback null
|
||||||
|
|
||||||
|
retrieveCombinedStream = (stream, callback) ->
|
||||||
|
if stream.getCombinedStreamLength?
|
||||||
|
stream.getCombinedStreamLength()
|
||||||
|
.then (length) -> callback(length)
|
||||||
|
.catch (err) -> callback(err)
|
||||||
|
else
|
||||||
|
callback null
|
||||||
|
|
||||||
|
|
||||||
module.exports = (stream, options = {}, callback) ->
|
module.exports = (stream, options = {}, callback) ->
|
||||||
nodeifyWrapper callback, ->
|
nodeifyWrapper callback, ->
|
||||||
|
@ -66,7 +73,7 @@ module.exports = (stream, options = {}, callback) ->
|
||||||
retrieverPromises.push createRetrieverPromise(stream, retriever)
|
retrieverPromises.push createRetrieverPromise(stream, retriever)
|
||||||
|
|
||||||
# Then, the standard ones.
|
# Then, the standard ones.
|
||||||
for retriever in [retrieveBuffer, retrieveFilesystemStream, retrieveCoreHttpStream, retrieveRequestHttpStream]
|
for retriever in [retrieveBuffer, retrieveFilesystemStream, retrieveCoreHttpStream, retrieveRequestHttpStream, retrieveCombinedStream]
|
||||||
retrieverPromises.push createRetrieverPromise(stream, retriever)
|
retrieverPromises.push createRetrieverPromise(stream, retriever)
|
||||||
|
|
||||||
Promise.any retrieverPromises
|
Promise.any retrieverPromises
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
var Promise, createRetrieverPromise, fs, nodeifyWrapper, retrieveBuffer, retrieveCoreHttpStream, retrieveFilesystemStream, retrieveRequestHttpStream;
|
var Promise, createRetrieverPromise, fs, nodeifyWrapper, retrieveBuffer, retrieveCombinedStream, retrieveCoreHttpStream, retrieveFilesystemStream, retrieveRequestHttpStream;
|
||||||
|
|
||||||
Promise = require("bluebird");
|
Promise = require("bluebird");
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ createRetrieverPromise = function(stream, retriever) {
|
||||||
return retriever(stream, function(result) {
|
return retriever(stream, function(result) {
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
if (result instanceof Error) {
|
if (result instanceof Error) {
|
||||||
console.log("REJECTING...", result);
|
|
||||||
return reject(result);
|
return reject(result);
|
||||||
} else {
|
} else {
|
||||||
return resolve(result);
|
return resolve(result);
|
||||||
|
@ -75,6 +74,18 @@ retrieveRequestHttpStream = function(stream, callback) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
retrieveCombinedStream = function(stream, callback) {
|
||||||
|
if (stream.getCombinedStreamLength != null) {
|
||||||
|
return stream.getCombinedStreamLength().then(function(length) {
|
||||||
|
return callback(length);
|
||||||
|
})["catch"](function(err) {
|
||||||
|
return callback(err);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return callback(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = function(stream, options, callback) {
|
module.exports = function(stream, options, callback) {
|
||||||
if (options == null) {
|
if (options == null) {
|
||||||
options = {};
|
options = {};
|
||||||
|
@ -89,7 +100,7 @@ module.exports = function(stream, options, callback) {
|
||||||
retrieverPromises.push(createRetrieverPromise(stream, retriever));
|
retrieverPromises.push(createRetrieverPromise(stream, retriever));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ref1 = [retrieveBuffer, retrieveFilesystemStream, retrieveCoreHttpStream, retrieveRequestHttpStream];
|
_ref1 = [retrieveBuffer, retrieveFilesystemStream, retrieveCoreHttpStream, retrieveRequestHttpStream, retrieveCombinedStream];
|
||||||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
||||||
retriever = _ref1[_j];
|
retriever = _ref1[_j];
|
||||||
retrieverPromises.push(createRetrieverPromise(stream, retriever));
|
retrieverPromises.push(createRetrieverPromise(stream, retriever));
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "stream-length",
|
"name": "stream-length",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"description": "For a given Buffer or Stream, this module will attempt to determine the total length of the stream contents. It currently supports Buffers, `fs` streams, `http` responses, and `request` objects, and allows for specifying custom stream types.",
|
"description": "For a given Buffer or Stream, this module will attempt to determine the total length of the stream contents. It currently supports Buffers, `fs` streams, `http` responses, and `request` objects, and allows for specifying custom stream types.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Loading…
Reference in a new issue