Merge pull request #240 from vatesfr/stream-to-array
util: streamToArray(Stream, filter?: Predicate) => Promise.
This commit is contained in:
commit
867a1e960e
11
src/utils.js
11
src/utils.js
@ -2,6 +2,7 @@ import base64url from 'base64url'
|
|||||||
import eventToPromise from 'event-to-promise'
|
import eventToPromise from 'event-to-promise'
|
||||||
import forEach from 'lodash.foreach'
|
import forEach from 'lodash.foreach'
|
||||||
import has from 'lodash.has'
|
import has from 'lodash.has'
|
||||||
|
import highland from 'highland'
|
||||||
import humanFormat from 'human-format'
|
import humanFormat from 'human-format'
|
||||||
import invert from 'lodash.invert'
|
import invert from 'lodash.invert'
|
||||||
import isArray from 'lodash.isarray'
|
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.
|
// Wrap a value in a function.
|
||||||
export const wrap = value => () => value
|
export const wrap = value => () => value
|
||||||
|
Loading…
Reference in New Issue
Block a user