MCPcopy
hub / github.com/dqzboy/Docker-Proxy / formatBytes

Function formatBytes

hubcmdui/server-utils.js:297–304  ·  view source on GitHub ↗

* 将字节格式化为可读大小 * @param {number} bytes - 字节数 * @returns {string} 格式化后的字符串

(bytes)

Source from the content-addressed store, hash-verified

295 * @returns {string} 格式化后的字符串
296 */
297function formatBytes(bytes) {
298 if (bytes === 0) return '0 B';
299
300 const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
301 const i = Math.floor(Math.log(bytes) / Math.log(1024));
302
303 return parseFloat((bytes / Math.pow(1024, i)).toFixed(2)) + ' ' + sizes[i];
304}
305
306/**
307 * 格式化运行时间

Callers 2

getSystemInfoFunction · 0.70
getDiskInfoFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected