23 lines
522 B
TypeScript
23 lines
522 B
TypeScript
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)
|
|
|
|
} |