util: streamToArray(Stream, filter?: Predicate) => Promise.
This commit is contained in:
parent
2c719f326b
commit
48dc68c3fe
11
src/utils.js
11
src/utils.js
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user