Socket
Socket
Sign inDemoInstall

get-stream

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-stream - npm Package Compare versions

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)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc