Merge pull request #240 from vatesfr/stream-to-array

util: streamToArray(Stream, filter?: Predicate) => Promise.
This commit is contained in:
Julien Fontanet 2016-02-18 17:02:25 +01:00
commit 867a1e960e

View File

@ -2,6 +2,7 @@ import base64url from 'base64url'
import eventToPromise from 'event-to-promise'
import forEach from 'lodash.foreach'
import has from 'lodash.has'
import highland from 'highland'
import humanFormat from 'human-format'
import invert from 'lodash.invert'
import isArray from 'lodash.isarray'
@ -456,5 +457,15 @@ export const multiKeyHash = (...args) => new Promise(resolve => {
// -------------------------------------------------------------------
export const streamToArray = (stream, filter = undefined) => new Promise((resolve, reject) => {
stream = highland(stream).stopOnError(reject)
if (filter) {
stream = stream.filter(filter)
}
stream.toArray(resolve)
})
// -------------------------------------------------------------------
// Wrap a value in a function.
export const wrap = value => () => value