read-all-stream
Advanced tools
Comparing version 3.0.0 to 3.0.1
43
index.js
@@ -40,27 +40,34 @@ 'use strict'; | ||
var promise = new Promise(function (resolve, reject) { | ||
var sink = new BufferStream(); | ||
var promise; | ||
sink.on('finish', function () { | ||
var data = Buffer.concat(this.buffer, this.length); | ||
if (!cb) { | ||
var resolve, reject; | ||
promise = new Promise(function(_res, _rej) { | ||
resolve = _res; | ||
reject = _rej; | ||
}); | ||
if (options.encoding) { | ||
data = data.toString(options.encoding); | ||
} | ||
cb = function (err, data) { | ||
if (err) { return reject(err); } | ||
resolve(data); | ||
}); | ||
}; | ||
} | ||
stream.once('error', reject); | ||
var sink = new BufferStream(); | ||
stream.pipe(sink); | ||
sink.on('finish', function () { | ||
var data = Buffer.concat(this.buffer, this.length); | ||
if (options.encoding) { | ||
data = data.toString(options.encoding); | ||
} | ||
cb(null, data); | ||
}); | ||
if (!cb) { | ||
return promise; | ||
} | ||
stream.once('error', cb); | ||
promise.then(function (data) { | ||
cb(null, data); | ||
}, cb); | ||
}; | ||
stream.pipe(sink); | ||
return promise; | ||
} |
{ | ||
"name": "read-all-stream", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Read all stream content and pass it to callback", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
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
4416
54