Socket
Socket
Sign inDemoInstall

get-stream

Package Overview
Dependencies
Maintainers
2
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 2.3.1 to 3.0.0

33

buffer-stream.js

@@ -1,13 +0,12 @@

var PassThrough = require('stream').PassThrough;
var objectAssign = require('object-assign');
'use strict';
const PassThrough = require('stream').PassThrough;
module.exports = function (opts) {
opts = objectAssign({}, opts);
module.exports = opts => {
opts = Object.assign({}, opts);
var array = opts.array;
var encoding = opts.encoding;
const array = opts.array;
let encoding = opts.encoding;
const buffer = encoding === 'buffer';
let objectMode = false;
var buffer = encoding === 'buffer';
var objectMode = false;
if (array) {

@@ -23,7 +22,6 @@ objectMode = !(encoding || buffer);

var len = 0;
var ret = [];
let len = 0;
const ret = [];
const stream = new PassThrough({objectMode});
var stream = new PassThrough({objectMode: objectMode});
if (encoding) {

@@ -33,3 +31,3 @@ stream.setEncoding(encoding);

stream.on('data', function (chunk) {
stream.on('data', chunk => {
ret.push(chunk);

@@ -44,14 +42,13 @@

stream.getBufferedValue = function () {
stream.getBufferedValue = () => {
if (array) {
return ret;
}
return buffer ? Buffer.concat(ret, len) : ret.join('');
};
stream.getBufferedLength = function () {
return len;
};
stream.getBufferedLength = () => len;
return stream;
};
'use strict';
var Promise = require('pinkie-promise');
var objectAssign = require('object-assign');
var bufferStream = require('./buffer-stream');
const bufferStream = require('./buffer-stream');

@@ -11,8 +9,17 @@ function getStream(inputStream, opts) {

opts = objectAssign({maxBuffer: Infinity}, opts);
var maxBuffer = opts.maxBuffer;
var stream;
var clean;
opts = Object.assign({maxBuffer: Infinity}, opts);
var p = new Promise(function (resolve, reject) {
const maxBuffer = opts.maxBuffer;
let stream;
let clean;
const p = new Promise((resolve, reject) => {
const error = err => {
if (err) { // null check
err.bufferedData = stream.getBufferedValue();
}
reject(err);
};
stream = bufferStream(opts);

@@ -22,3 +29,3 @@ inputStream.once('error', error);

stream.on('data', function () {
stream.on('data', () => {
if (stream.getBufferedLength() > maxBuffer) {

@@ -31,4 +38,4 @@ reject(new Error('maxBuffer exceeded'));

clean = function () {
// some streams doesn't implement the stream.Readable interface correctly
clean = () => {
// some streams doesn't implement the `stream.Readable` interface correctly
if (inputStream.unpipe) {

@@ -38,9 +45,2 @@ inputStream.unpipe(stream);

};
function error(err) {
if (err) { // null check
err.bufferedData = stream.getBufferedValue();
}
reject(err);
}
});

@@ -50,15 +50,7 @@

return p.then(function () {
return stream.getBufferedValue();
});
return p.then(() => stream.getBufferedValue());
}
module.exports = getStream;
module.exports.buffer = function (stream, opts) {
return getStream(stream, objectAssign({}, opts, {encoding: 'buffer'}));
};
module.exports.array = function (stream, opts) {
return getStream(stream, objectAssign({}, opts, {array: true}));
};
module.exports.buffer = (stream, opts) => getStream(stream, Object.assign({}, opts, {encoding: 'buffer'}));
module.exports.array = (stream, opts) => getStream(stream, Object.assign({}, opts, {array: true}));
{
"name": "get-stream",
"version": "2.3.1",
"version": "3.0.0",
"description": "Get a stream as a string, buffer, or array",

@@ -13,3 +13,3 @@ "license": "MIT",

"engines": {
"node": ">=0.10.0"
"node": ">=4"
},

@@ -34,2 +34,3 @@ "scripts": {

"data",
"consume",
"readable",

@@ -41,12 +42,10 @@ "readablestream",

],
"dependencies": {
"object-assign": "^4.0.1",
"pinkie-promise": "^2.0.0"
},
"devDependencies": {
"ava": "*",
"buffer-equals": "^1.0.3",
"into-stream": "^2.0.1",
"into-stream": "^3.0.0",
"xo": "*"
},
"xo": {
"esnext": true
}
}

@@ -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)

The 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.
The methods returns a promise that resolves 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.

@@ -97,4 +97,6 @@ ### getStream(stream, [options])

getStream(streamThatErrorsAtTheEnd('unicorn'))
.catch(err => console.log(err.bufferedData));
// unicorn
.catch(err => {
console.log(err.bufferedData);
//=> 'unicorn'
});
```

@@ -101,0 +103,0 @@

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