Socket
Socket
Sign inDemoInstall

stream-to-promise

Package Overview
Dependencies
3
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.4 to 1.1.0

60

index.js

@@ -1,43 +0,35 @@

'use strict';
'use strict'
var toArray = require('stream-to-array');
var Promise = require('bluebird');
var internals = {};
var toArray = require('stream-to-array')
var Promise = require('bluebird')
internals.readable = function (stream) {
var promise = toArray(stream);
module.exports = streamToPromise
function streamToPromise (stream) {
if (stream.readable) return fromReadable(stream)
if (stream.writable) return fromWritable(stream)
return Promise.resolve()
}
function fromReadable (stream) {
var promise = toArray(stream)
// Ensure stream is in flowing mode
stream.resume();
stream.resume()
return promise
.then(function (parts) {
var buffers = [];
for (var i = 0, l = parts.length; i < l ; ++i) {
var part = parts[i];
buffers.push((part instanceof Buffer) ? part : new Buffer(part));
}
return Buffer.concat(buffers);
});
};
.then(function concat (parts) {
return Buffer.concat(parts.map(bufferize))
})
}
internals.writable = function (stream) {
function fromWritable (stream) {
return new Promise(function (resolve, reject) {
stream.once('finish', resolve);
stream.once('error', reject);
});
};
stream.once('finish', resolve)
stream.once('error', reject)
})
}
module.exports = function (stream) {
var promise;
if (stream.readable) {
promise = internals.readable(stream);
}
else if (stream.writable) {
promise = internals.writable(stream);
}
else {
promise = Promise.resolve();
}
return promise;
};
function bufferize (chunk) {
return Buffer.isBuffer(chunk) ? chunk : new Buffer(chunk)
}
{
"name": "stream-to-promise",
"version": "1.0.4",
"version": "1.1.0",
"description": "Convert streams (readable or writable) to promises",
"main": "index.js",
"scripts": {
"test": "mocha test"
"test": "standard && mocha test.js"
},

@@ -24,12 +24,16 @@ "repository": {

"dependencies": {
"stream-to-array": "2",
"bluebird": "2"
"bluebird": "~3.0.6",
"stream-to-array": "~2.2.0"
},
"devDependencies": {
"chai": "1",
"chai-as-promised": "4",
"delayed-stream": "0.0.5",
"mocha": "1",
"rimraf": "2"
}
"chai": "^3.4.1",
"chai-as-promised": "^5.1.0",
"delayed-stream": "^1.0.0",
"mocha": "^2.3.4",
"rimraf": "^2.4.4",
"standard": "^5.4.1"
},
"files": [
"index.js"
]
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc