Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 545 Bytes
e4e0e54 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
export const streamToBuffer = (
stream: NodeJS.ReadWriteStream
): Promise<Buffer> => {
return new Promise((resolve, reject) => {
const chunks: Buffer[] = []
stream.on("data", (chunk: Buffer) => {
// console.log("Received chunk with length:"", chunk.length)
chunks.push(chunk)
})
stream.on("error", reject)
stream.on("end", () => {
/*
console.log(
"Stream ended, total buffer length:",
Buffer.concat(chunks).length
)
*/
resolve(Buffer.concat(chunks))
})
})
} |