read-all-stream
Advanced tools
Comparing version 2.2.0 to 3.0.0
31
index.js
@@ -5,2 +5,3 @@ 'use strict'; | ||
var inherits = require('util').inherits; | ||
var Promise = require('pinkie-promise'); | ||
@@ -40,21 +41,27 @@ function BufferStream() { | ||
if (!cb) { | ||
throw new Error('callback argument is required'); | ||
} | ||
var promise = new Promise(function (resolve, reject) { | ||
var sink = new BufferStream(); | ||
var sink = new BufferStream(); | ||
sink.on('finish', function () { | ||
var data = Buffer.concat(this.buffer, this.length); | ||
sink.on('finish', function () { | ||
var data = Buffer.concat(this.buffer, this.length); | ||
if (options.encoding) { | ||
data = data.toString(options.encoding); | ||
} | ||
if (options.encoding) { | ||
data = data.toString(options.encoding); | ||
} | ||
resolve(data); | ||
}); | ||
cb(null, data); | ||
stream.once('error', reject); | ||
stream.pipe(sink); | ||
}); | ||
stream.once('error', cb); | ||
if (!cb) { | ||
return promise; | ||
} | ||
stream.pipe(sink); | ||
promise.then(function (data) { | ||
cb(null, data); | ||
}, cb); | ||
}; |
{ | ||
"name": "read-all-stream", | ||
"version": "2.2.0", | ||
"version": "3.0.0", | ||
"description": "Read all stream content and pass it to callback", | ||
@@ -30,4 +30,5 @@ "license": "MIT", | ||
"dependencies": { | ||
"pinkie-promise": "^1.0.0", | ||
"readable-stream": "^2.0.0" | ||
} | ||
} |
@@ -17,2 +17,6 @@ # read-all-stream [![Build Status][travis-image]][travis-url] | ||
read(stream).then(function (data) { | ||
console.log(data.length); | ||
}); | ||
read(stream, 'utf8', function (err, data) { | ||
@@ -27,4 +31,6 @@ console.log(data.length); | ||
#### read(stream, [options], callback) | ||
#### read(stream, [options], [callback]) | ||
If callback is omitted, Promise will be returned. | ||
##### stream | ||
@@ -53,2 +59,4 @@ | ||
Will be called after stream is read. | ||
###### err | ||
@@ -55,0 +63,0 @@ |
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
4333
49
73
2
+ Addedpinkie-promise@^1.0.0
+ Addedpinkie@1.0.0(transitive)
+ Addedpinkie-promise@1.0.0(transitive)