import {Request} from "express" import removeChunksFS from "./removeChunksFS"; const awaitUploadStream = (inputSteam: any, outputStream: any, req: Request, path: string, allStreamsToCatchError: any[]) => { return new Promise((resolve, reject) => { allStreamsToCatchError.forEach((currentStream: any) => { currentStream.on("error", (e: Error) => { removeChunksFS(path); reject({ message: "Await Stream Input Error", code: 500, error: e }) }) }) req.on("aborted", () => { console.log("Upload Request Cancelling..."); removeChunksFS(path); }) inputSteam.pipe(outputStream).on("finish", (data: T) => { resolve(data); }) }) } export default awaitUploadStream;