Files
myDrive/backend/services/ChunkService/utils/awaitStream.ts
T
2024-07-02 15:10:03 -04:00

24 lines
525 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) => {
resolve(data);
});
});
};
export default awaitStream;