MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / formatBytes

Function formatBytes

komari/komari.ts:129–142  ·  view source on GitHub ↗
(bytes: number)

Source from the content-addressed store, hash-verified

127
128// 字节转换工具函数
129function formatBytes(bytes: number): string {
130 if (bytes === 0) return "0 B";
131 const k = 1024;
132 const sizes = ["B", "KB", "MB", "GB", "TB", "PB"];
133 const i = Math.floor(Math.log(bytes) / Math.log(k));
134 const value = bytes / Math.pow(k, i);
135
136 // 根据值的大小决定小数位数
137 let decimals = 2;
138 if (value >= 100) decimals = 1;
139 if (value >= 1000) decimals = 0;
140
141 return parseFloat(value.toFixed(decimals)) + " " + sizes[i];
142}
143
144// 格式化网络速度
145function formatSpeed(bytesPerSecond: number): string {

Callers 3

getServerInfoFunction · 0.70
getNodesOverviewFunction · 0.70
getNodeDetailsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected