Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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 2.2.0 to 2.2.1

buffer-stream.js

53

index.js
'use strict';
var PassThrough = require('stream').PassThrough;
var Promise = require('pinkie-promise');
var objectAssign = require('object-assign');
var bufferStream = require('./buffer-stream');

@@ -12,48 +12,15 @@ function getStream(inputStream, opts) {

opts = objectAssign({maxBuffer: Infinity}, opts);
var maxBuffer = opts.maxBuffer;
var stream;
var array = opts.array;
var encoding = opts.encoding;
var maxBuffer = opts.maxBuffer;
var buffer = encoding === 'buffer';
var objectMode = false;
if (array) {
objectMode = !(encoding || buffer);
} else {
encoding = encoding || 'utf8';
}
if (buffer) {
encoding = null;
}
var len = 0;
var ret = [];
var clean;
var p = new Promise(function (resolve, reject) {
stream = new PassThrough({objectMode: objectMode});
stream = bufferStream(opts);
inputStream.pipe(stream);
if (encoding) {
stream.setEncoding(encoding);
}
var onData = function (chunk) {
ret.push(chunk);
if (objectMode) {
len = ret.length;
} else {
len += chunk.length;
}
if (len > maxBuffer) {
stream.on('data', function () {
if (stream.getBufferedLength() > maxBuffer) {
reject(new Error('maxBuffer exceeded'));
}
};
stream.on('data', onData);
});
stream.on('error', reject);

@@ -63,3 +30,3 @@ stream.on('end', resolve);

clean = function () {
stream.removeListener('data', onData);
inputStream.unpipe(stream);
};

@@ -71,7 +38,3 @@ });

return p.then(function () {
if (array) {
return ret;
}
return buffer ? Buffer.concat(ret, len) : ret.join('');
return stream.getBufferedValue();
});

@@ -78,0 +41,0 @@ }

{
"name": "get-stream",
"version": "2.2.0",
"version": "2.2.1",
"description": "Get a stream as a string, buffer, or array",

@@ -19,3 +19,4 @@ "license": "MIT",

"files": [
"index.js"
"index.js",
"buffer-stream.js"
],

@@ -25,2 +26,3 @@ "keywords": [

"stream",
"promise",
"concat",

@@ -27,0 +29,0 @@ "string",

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