Skip to content

Instantly share code, notes, and snippets.

@neos1803
Last active March 17, 2022 07:37
Show Gist options
  • Save neos1803/4f2a139217aae8eef8ac7f3b78dd9653 to your computer and use it in GitHub Desktop.
Save neos1803/4f2a139217aae8eef8ac7f3b78dd9653 to your computer and use it in GitHub Desktop.
Read file size from readStream javascript
function getFileSize(stream?: any, callback?): Promise<any> {
return new Promise((resolve, reject) => {
let bytes=0;
stream.on("data", (chunk) => {
bytes += chunk.length;
});
stream.on("end", () => {
resolve(bytes)
});
stream.on("error", (e) => {
reject(e);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment