Files
myDrive/backend/services/ChunkService/utils/awaitStream.ts
T
2020-04-19 17:06:16 -04:00

24 lines
658 B
TypeScript

const awaitStream = <T>(inputSteam: any, outputStream: any, allStreamsToErrorCatch: any[]) => {
return new Promise<T>((resolve, reject) => {
allStreamsToErrorCatch.forEach((currentStream: any) => {
currentStream.on("error", (e: Error) => {
reject({
message: "Await Stream Input Error",
code: 500,
error: e
})
})
})
inputSteam.pipe(outputStream).on("finish", (data: T) => {
console.log("await stream finished")
resolve(data);
})
})
}
export default awaitStream;