util: streamToArray(Stream, filter?: Predicate) => Promise.

This commit is contained in:
Julien Fontanet 2016-02-18 16:58:17 +01:00
parent 2c719f326b
commit 48dc68c3fe

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