stream-to-promise
Advanced tools
Comparing version 2.2.0 to 3.0.0
31
index.js
'use strict' | ||
var toArray = require('stream-to-array') | ||
var Promise = require('any-promise') | ||
var onEnd = require('end-of-stream') | ||
const toArray = require('stream-to-array') | ||
const Promise = require('any-promise') | ||
const onEnd = require('end-of-stream') | ||
module.exports = streamToPromise | ||
function streamToPromise (stream) { | ||
async 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) | ||
async function fromReadable (stream) { | ||
const promise = toArray(stream) | ||
@@ -21,12 +20,12 @@ // Ensure stream is in flowing mode | ||
return promise | ||
.then(function concat (parts) { | ||
if (stream._readableState && stream._readableState.objectMode) { | ||
return parts | ||
} | ||
return Buffer.concat(parts.map(bufferize)) | ||
}) | ||
const parts = await promise | ||
if (stream._readableState && stream._readableState.objectMode) { | ||
return parts | ||
} | ||
return Buffer.concat(parts.map(bufferize)) | ||
} | ||
function fromWritable (stream) { | ||
async function fromWritable (stream) { | ||
return new Promise(function (resolve, reject) { | ||
@@ -40,3 +39,3 @@ onEnd(stream, function (err) { | ||
function bufferize (chunk) { | ||
return Buffer.isBuffer(chunk) ? chunk : new Buffer(chunk) | ||
return Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk) | ||
} |
{ | ||
"name": "stream-to-promise", | ||
"version": "2.2.0", | ||
"version": "3.0.0", | ||
"description": "Convert streams (readable or writable) to promises", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "standard && mocha test.js" | ||
"test": "standard && tape test*.js" | ||
}, | ||
@@ -25,17 +25,21 @@ "repository": { | ||
"any-promise": "~1.3.0", | ||
"end-of-stream": "~1.1.0", | ||
"end-of-stream": "~1.4.1", | ||
"stream-to-array": "~2.3.0" | ||
}, | ||
"devDependencies": { | ||
"bluebird": "~3.4.1", | ||
"chai": "^3.4.1", | ||
"chai-as-promised": "^5.1.0", | ||
"chai": "^4.2.0", | ||
"chai-as-promised": "^7.1.1", | ||
"delayed-stream": "^1.0.0", | ||
"mocha": "^2.3.4", | ||
"rimraf": "^2.4.4", | ||
"standard": "^7.1.2" | ||
"hard-rejection": "^2.0.0", | ||
"standard": "^14.0.0", | ||
"tape": "^5.0.1", | ||
"tape-promise": "^4.0.0", | ||
"tmp-promise": "^3.0.2" | ||
}, | ||
"files": [ | ||
"index.js" | ||
] | ||
], | ||
"engines": { | ||
"node": ">= 10" | ||
} | ||
} |
@@ -1,3 +0,2 @@ | ||
stream-to-promise [![Build Status](https://travis-ci.org/bendrucker/stream-to-promise.svg)](https://travis-ci.org/bendrucker/stream-to-promise) | ||
================= | ||
# stream-to-promise [![Build Status](https://travis-ci.com/bendrucker/stream-to-promise.svg?branch=master)](https://travis-ci.com/bendrucker/stream-to-promise) | ||
@@ -9,3 +8,3 @@ > Convert streams (readable or writable) to promises | ||
```sh | ||
$ npm install --save[-dev] stream-to-promise | ||
npm install --save stream-to-promise | ||
``` | ||
@@ -40,3 +39,3 @@ | ||
```js | ||
var err = new Error() | ||
const err = new Error() | ||
streamToPromise(stream).catch(function (error) { | ||
@@ -43,0 +42,0 @@ // error === err |
4025
8
29
44
+ Addedend-of-stream@1.4.4(transitive)
+ Addedonce@1.4.0(transitive)
- Removedend-of-stream@1.1.0(transitive)
- Removedonce@1.3.3(transitive)
Updatedend-of-stream@~1.4.1