get-stream
Advanced tools
Comparing version 1.1.0 to 2.0.0
56
index.js
'use strict'; | ||
var Promise = require('pinkie-promise'); | ||
@@ -12,18 +13,21 @@ module.exports = function (stream, opts) { | ||
return new Promise(function (resolve, reject) { | ||
function onData(chunk) { | ||
ret += chunk; | ||
} | ||
var p = new Promise(function (resolve, reject) { | ||
stream.setEncoding(opts.encoding || 'utf8'); | ||
stream.on('data', onData); | ||
stream.on('error', reject); | ||
stream.on('end', resolve); | ||
}); | ||
stream.on('readable', function () { | ||
var chunk; | ||
var clean = function () { | ||
stream.removeListener('data', onData); | ||
}; | ||
while ((chunk = stream.read())) { | ||
ret += chunk; | ||
} | ||
}); | ||
p.then(clean, clean); | ||
stream.on('error', reject); | ||
stream.on('end', function () { | ||
resolve(ret); | ||
}); | ||
return p.then(function () { | ||
return ret; | ||
}); | ||
@@ -40,18 +44,22 @@ }; | ||
return new Promise(function (resolve, reject) { | ||
stream.on('readable', function () { | ||
var chunk; | ||
function onData(chunk) { | ||
ret.push(chunk); | ||
len += chunk.length; | ||
} | ||
while ((chunk = stream.read())) { | ||
ret.push(chunk); | ||
len += chunk.length; | ||
} | ||
}); | ||
var p = new Promise(function (resolve, reject) { | ||
stream.on('data', onData); | ||
stream.on('error', reject); | ||
stream.on('end', resolve); | ||
}); | ||
stream.on('end', function () { | ||
resolve(Buffer.concat(ret, len)); | ||
}); | ||
var clean = function () { | ||
stream.removeListener('data', onData); | ||
}; | ||
p.then(clean, clean); | ||
return p.then(function () { | ||
return Buffer.concat(ret, len); | ||
}); | ||
}; |
{ | ||
"name": "get-stream", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "Get a stream as a string or buffer", | ||
@@ -13,3 +13,3 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=0.12.0" | ||
"node": ">=0.10.0" | ||
}, | ||
@@ -35,2 +35,5 @@ "scripts": { | ||
], | ||
"dependencies": { | ||
"pinkie-promise": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
@@ -40,8 +43,3 @@ "ava": "*", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"ignores": [ | ||
"test.js" | ||
] | ||
} | ||
} |
@@ -49,3 +49,3 @@ # get-stream [![Build Status](https://travis-ci.org/sindresorhus/get-stream.svg?branch=master)](https://travis-ci.org/sindresorhus/get-stream) | ||
Both methods returns a promise that is resolved when the `end` event fires on the stream, indicating that there is no more data to be read. | ||
Both methods returns a promise that is resolved when the `end` event fires on the stream, indicating that there is no more data to be read. The stream is switched to flowing mode. | ||
@@ -60,3 +60,3 @@ ### getStream(stream, [options]) | ||
Type: `string` | ||
Type: `string`<br> | ||
Default: `utf8` | ||
@@ -75,3 +75,3 @@ | ||
This one accepts a stream instead of being one and returns a promise instead of using a callback. The API is simpler and it only supports returning a string or buffer. It doesn't have a fragile type inference. You explicitly choose what you want. It supports back-pressure and it doesn't depend on the huge `readable-stream` package. | ||
This one accepts a stream instead of being one and returns a promise instead of using a callback. The API is simpler and it only supports returning a string or buffer. It doesn't have a fragile type inference. You explicitly choose what you want. And it doesn't depend on the huge `readable-stream` package. | ||
@@ -86,2 +86,2 @@ | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
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
5440
48
1
+ Addedpinkie-promise@^2.0.0
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)