MCPcopy Index your code
hub / github.com/cameri/nostream / formatBytes

Function formatBytes

src/scripts/export-events.ts:31–50  ·  view source on GitHub ↗
(bytes: number)

Source from the content-addressed store, hash-verified

29const MIN_ELAPSED_SECONDS = 0.001
30
31export const formatBytes = (bytes: number): string => {
32 const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB']
33
34 if (!Number.isFinite(bytes) || bytes <= 0) {
35 return '0 B'
36 }
37
38 let unitIndex = 0
39 let value = bytes
40
41 while (value >= 1024 && unitIndex < units.length - 1) {
42 value /= 1024
43 unitIndex += 1
44 }
45
46 const rounded = Math.round(value * 100) / 100
47 const formatted = String(rounded)
48
49 return `${formatted} ${units[unitIndex]}`
50}
51
52export const formatCompressionDelta = (rawBytes: number, outputBytes: number): string | undefined => {
53 if (rawBytes <= 0) {

Callers 2

runExportEventsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected