Last active
March 17, 2022 07:37
-
-
Save neos1803/4f2a139217aae8eef8ac7f3b78dd9653 to your computer and use it in GitHub Desktop.
Read file size from readStream javascript
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 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