Created
August 26, 2024 03:48
-
-
Save ken107/c2ad2cb5e80825d9c4732eef77b58f66 to your computer and use it in GitHub Desktop.
The NPM library is garbage
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
function getStream(stream: Readable): Promise<Buffer> { | |
return new Promise((fulfill, reject) => { | |
const chunks: Buffer[] = [] | |
let totalLength = 0 | |
stream.on("data", chunk => { | |
chunks.push(chunk) | |
totalLength += chunk.length | |
}) | |
stream.once("end", () => fulfill(Buffer.concat(chunks, totalLength))) | |
stream.once("error", reject) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment