projeto-hit/backend/src/helpers/ConvertBytes.ts

23 lines
522 B
TypeScript
Raw Normal View History

2022-06-29 00:34:43 +00:00
const fsPromises = require("fs/promises");
const fs = require('fs-extra')
// Delete a directory and its children
export const convertBytes = (bytes: number,) => {
const sizes = ["Bytes", "KB", "MB", "GB", "TB"]
if (bytes == 0) {
return "n/a"
}
const i = +(Math.floor(Math.log(bytes) / Math.log(1024)))
if (i == 0) {
return bytes + " " + sizes[i]
}
// return (bytes / Math.pow(1024, i)).toFixed(1) + " " + sizes[i]
return (bytes / Math.pow(1024, i)).toFixed(1)
}