Skip to content

Instantly share code, notes, and snippets.

@ken107
Created August 26, 2024 03:48
Show Gist options
  • Save ken107/c2ad2cb5e80825d9c4732eef77b58f66 to your computer and use it in GitHub Desktop.
Save ken107/c2ad2cb5e80825d9c4732eef77b58f66 to your computer and use it in GitHub Desktop.
The NPM library is garbage
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