11cb0ef41Sopenharmony_ci// Convert bytes to printable output, for file reporting in tarballs 21cb0ef41Sopenharmony_ci// Only supports up to GB because that's way larger than anything the registry 31cb0ef41Sopenharmony_ci// supports anyways. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst formatBytes = (bytes, space = true) => { 61cb0ef41Sopenharmony_ci let spacer = '' 71cb0ef41Sopenharmony_ci if (space) { 81cb0ef41Sopenharmony_ci spacer = ' ' 91cb0ef41Sopenharmony_ci } 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci if (bytes < 1000) { 121cb0ef41Sopenharmony_ci // B 131cb0ef41Sopenharmony_ci return `${bytes}${spacer}B` 141cb0ef41Sopenharmony_ci } 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci if (bytes < 1000000) { 171cb0ef41Sopenharmony_ci // kB 181cb0ef41Sopenharmony_ci return `${(bytes / 1000).toFixed(1)}${spacer}kB` 191cb0ef41Sopenharmony_ci } 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci if (bytes < 1000000000) { 221cb0ef41Sopenharmony_ci // MB 231cb0ef41Sopenharmony_ci return `${(bytes / 1000000).toFixed(1)}${spacer}MB` 241cb0ef41Sopenharmony_ci } 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci // GB 271cb0ef41Sopenharmony_ci return `${(bytes / 1000000000).toFixed(1)}${spacer}GB` 281cb0ef41Sopenharmony_ci} 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_cimodule.exports = formatBytes 31