1// Convert bytes to printable output, for file reporting in tarballs 2// Only supports up to GB because that's way larger than anything the registry 3// supports anyways. 4 5const formatBytes = (bytes, space = true) => { 6 let spacer = '' 7 if (space) { 8 spacer = ' ' 9 } 10 11 if (bytes < 1000) { 12 // B 13 return `${bytes}${spacer}B` 14 } 15 16 if (bytes < 1000000) { 17 // kB 18 return `${(bytes / 1000).toFixed(1)}${spacer}kB` 19 } 20 21 if (bytes < 1000000000) { 22 // MB 23 return `${(bytes / 1000000).toFixed(1)}${spacer}MB` 24 } 25 26 // GB 27 return `${(bytes / 1000000000).toFixed(1)}${spacer}GB` 28} 29 30module.exports = formatBytes 31