Last active
May 20, 2023 21:48
-
-
Save Git-I985/12b6b322ba83e6b771165d8358795644 to your computer and use it in GitHub Desktop.
compare-file-sizes-node
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
const getFileSize = async (file) => (await fs.stat(file)).size | |
const compareFileSizes = async (filepath1, filepath2, cb) => { | |
try { | |
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#promise_concurrency | |
const [fsize1, fsize2] = await Promise.all([ | |
getFileSize(filepath1), | |
getFileSize(filepath2) | |
]) | |
cb(null, Math.sign(fsize1 - fsize2)) | |
} catch(e) { | |
cb(e, null) | |
} | |
} | |
export { compareFileSizes }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment