read-all-stream
Advanced tools
Comparing version 2.1.1 to 2.1.2
42
index.js
'use strict'; | ||
var concat = require('concat-stream'); | ||
var Writable = require('readable-stream').Writable; | ||
var inherits = require('util').inherits; | ||
function BufferStream() { | ||
Writable.call(this, { objectMode: true }); | ||
this.buffer = []; | ||
this.length = 0; | ||
} | ||
inherits(BufferStream, Writable); | ||
BufferStream.prototype._write = function(chunk, enc, next) { | ||
if (!Buffer.isBuffer(chunk)) { | ||
chunk = new Buffer(chunk); | ||
} | ||
this.buffer.push(chunk); | ||
this.length += chunk.length; | ||
next(); | ||
}; | ||
module.exports = function read(stream, options, cb) { | ||
@@ -25,11 +43,17 @@ if (!stream) { | ||
stream | ||
.once('error', cb) | ||
.pipe(concat({encoding: 'buffer'}, function (data) { | ||
if (options.encoding) { | ||
data = data.toString(options.encoding); | ||
} | ||
var sink = new BufferStream(); | ||
cb(null, data); | ||
})); | ||
sink.on('finish', function () { | ||
var data = Buffer.concat(this.buffer, this.length); | ||
if (options.encoding) { | ||
data = data.toString(options.encoding); | ||
} | ||
cb(null, data); | ||
}); | ||
stream.once('error', cb); | ||
stream.pipe(sink); | ||
}; |
{ | ||
"name": "read-all-stream", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "Read all stream content and pass it to callback", | ||
@@ -15,4 +15,3 @@ "license": "MIT", | ||
"scripts": { | ||
"test": "mocha", | ||
"coverage": "istanbul cover _mocha -- -R spec" | ||
"test": "mocha" | ||
}, | ||
@@ -29,9 +28,7 @@ "files": [ | ||
"devDependencies": { | ||
"fast-apply": "0.0.3", | ||
"istanbul": "^0.3.2", | ||
"mocha": "*" | ||
}, | ||
"dependencies": { | ||
"concat-stream": "^1.4.8" | ||
"readable-stream": "~1.1.13" | ||
} | ||
} |
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
2897
1
43
+ Addedreadable-stream@~1.1.13
+ Addedisarray@0.0.1(transitive)
+ Addedreadable-stream@1.1.14(transitive)
+ Addedstring_decoder@0.10.31(transitive)
- Removedconcat-stream@^1.4.8
- Removedbuffer-from@1.1.2(transitive)
- Removedconcat-stream@1.6.2(transitive)
- Removedisarray@1.0.0(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedtypedarray@0.0.6(transitive)
- Removedutil-deprecate@1.0.2(transitive)