MCPcopy
hub / github.com/electerm/electerm / formatBytes

Function formatBytes

npm/utils.js:37–43  ·  view source on GitHub ↗

* Format bytes to human readable

(bytes)

Source from the content-addressed store, hash-verified

35 * Format bytes to human readable
36 */
37function formatBytes (bytes) {
38 if (bytes === 0) return '0 B'
39 const k = 1024
40 const sizes = ['B', 'KB', 'MB', 'GB']
41 const i = Math.floor(Math.log(bytes) / Math.log(k))
42 return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]
43}
44
45/**
46 * Make an HTTP GET request and download to a file with progress

Callers 2

downloadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected