@naturalcycles/nodejs-lib
Version:
Standard library for Node.js
16 lines (12 loc) • 344 B
text/typescript
import { ReadableTyped } from '../stream.model'
/**
* Convenience function to read the whole Readable stream into Array (in-memory)
* and return that array.
*/
export async function readableToArray<T>(readable: ReadableTyped<T>): Promise<T[]> {
const a: T[] = []
for await (const item of readable) {
a.push(item)
}
return a
}