@@ -316,6 +316,46 @@ class ConfigManager {
316316 return null ;
317317 }
318318
319+ /**
320+ * Format file size from bytes to human-readable string (GB or TB)
321+ * @param {number } totalBytes - Total size in bytes
322+ * @returns {string } Formatted size string (e.g., "1.5GB" or "0.3TB")
323+ */
324+ static formatFileSize ( totalBytes ) {
325+ const TB = 1e12 ;
326+ const GB = 1e9 ;
327+ const useTB = totalBytes >= TB ;
328+ const value = useTB ? ( totalBytes / TB ) : ( totalBytes / GB ) ;
329+ const formatted = ( Math . round ( value * 10 ) / 10 ) . toFixed ( 1 ) ;
330+ const unit = useTB ? 'TB' : 'GB' ;
331+ return `${ formatted } ${ unit } ` ;
332+ }
333+
334+ /**
335+ * Calculate total size in bytes from an array of datasets
336+ * @param {Dataset[] } datasets - Array of datasets
337+ * @returns {number|null } Total size in bytes, or null if no valid sizes found
338+ */
339+ static calculateTotalSizeFromDatasets ( datasets ) {
340+ if ( ! datasets || datasets . length === 0 ) {
341+ return null ;
342+ }
343+
344+ let totalBytes = 0 ;
345+ let hasValidSize = false ;
346+
347+ for ( const ds of datasets ) {
348+ const size = ds ?. datasetSize ?? ds ?. raw ?. dataset_size ;
349+ const bytes = this . parseDatasetSizeToBytes ( size ) ;
350+ if ( bytes !== null ) {
351+ totalBytes += bytes ;
352+ hasValidSize = true ;
353+ }
354+ }
355+
356+ return hasValidSize ? totalBytes : null ;
357+ }
358+
319359 /**
320360 * Build the required storage comment for a list of datasets.
321361 * Rules:
@@ -335,24 +375,16 @@ class ConfigManager {
335375 return '# Required storage: ---GB/TB.\n# Disk usage may be larger.' ;
336376 }
337377
338- let totalBytes = 0 ;
339- for ( const path of datasetPaths ) {
340- const ds = datasetMap . get ( path ) ;
341- const size = ds ?. datasetSize ?? ds ?. raw ?. dataset_size ;
342- const bytes = this . parseDatasetSizeToBytes ( size ) ;
343- if ( bytes === null ) {
344- return '# Required storage: ---GB/TB.\n# Disk usage may be larger.' ;
345- }
346- totalBytes += bytes ;
378+ // Build datasets array from paths
379+ const datasets = datasetPaths . map ( path => datasetMap . get ( path ) ) . filter ( ds => ds !== undefined ) ;
380+ const totalBytes = this . calculateTotalSizeFromDatasets ( datasets ) ;
381+
382+ if ( totalBytes === null ) {
383+ return '# Required storage: ---GB/TB.\n# Disk usage may be larger.' ;
347384 }
348-
349- const TB = 1e12 ;
350- const GB = 1e9 ;
351- const useTB = totalBytes >= TB ;
352- const value = useTB ? ( totalBytes / TB ) : ( totalBytes / GB ) ;
353- const formatted = ( Math . round ( value * 10 ) / 10 ) . toFixed ( 1 ) ;
354- const unit = useTB ? 'TB' : 'GB' ;
355- return `# Required storage: ${ formatted } ${ unit } .\n# Disk usage may be larger.` ;
385+
386+ const formattedSize = this . formatFileSize ( totalBytes ) ;
387+ return `# Required storage: ${ formattedSize } .\n# Disk usage may be larger.` ;
356388 }
357389
358390 /**
0 commit comments