mirror of
				https://github.com/immich-app/immich.git
				synced 2025-10-30 18:22:37 -04:00 
			
		
		
		
	
		
			
				
	
	
		
			18 lines
		
	
	
		
			400 B
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			18 lines
		
	
	
		
			400 B
		
	
	
	
		
			Dart
		
	
	
	
	
	
| String formatBytes(int bytes) {
 | |
|   const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB'];
 | |
| 
 | |
|   int magnitude = 0;
 | |
|   double remainder = bytes.toDouble();
 | |
|   while (remainder >= 1024) {
 | |
|     if (magnitude + 1 < units.length) {
 | |
|       magnitude++;
 | |
|       remainder /= 1024;
 | |
|     }
 | |
|     else {
 | |
|       break;
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   return "${remainder.toStringAsFixed(magnitude == 0 ? 0 : 1)} ${units[magnitude]}";
 | |
| }
 |