Skip to content

Instantly share code, notes, and snippets.

@Git-I985
Last active May 20, 2023 21:48
Show Gist options
  • Save Git-I985/12b6b322ba83e6b771165d8358795644 to your computer and use it in GitHub Desktop.
Save Git-I985/12b6b322ba83e6b771165d8358795644 to your computer and use it in GitHub Desktop.
compare-file-sizes-node
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