MCPcopy Create free account
hub / github.com/6174/comflowyspace / formatBytes

Function formatBytes

apps/node/src/modules/utils/file-size.ts:24–34  ·  view source on GitHub ↗
(bytes: number, decimals = 2)

Source from the content-addressed store, hash-verified

22}
23
24function formatBytes(bytes: number, decimals = 2) {
25 if (bytes === 0) return '0 Bytes';
26
27 const k = 1024;
28 const dm = decimals < 0 ? 0 : decimals;
29 const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
30
31 const i = Math.floor(Math.log(bytes) / Math.log(k));
32
33 return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
34}

Callers 2

getFileSizeFunction · 0.85
getFileSizeSyncFunction · 0.85

Calls 1

logMethod · 0.80

Tested by

no test coverage detected