Created
August 7, 2023 22:44
-
-
Save afreeorange/91bcb42c404d8d3980605c9647f704c8 to your computer and use it in GitHub Desktop.
Convert a Node Stream to a Buffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const convertStreamToBuffer = async ( | |
stream: NodeJS.ReadableStream | |
): Promise<Buffer> => { | |
return new Promise((resolve, reject) => { | |
let buffers: Uint8Array[] = []; | |
stream.on("data", (data) => { | |
buffers.push(data); | |
}); | |
stream.on("end", () => { | |
resolve(Buffer.concat(buffers)); | |
}); | |
stream.on("error", reject); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment