Maintain local ⭤ remote in sync with automatic AT Protocol parity for Laravel (alpha & unstable)
at dev 833 B view raw
1<?php 2 3namespace SocialDept\AtpParity\Export; 4 5/** 6 * Value object representing an exported repository as CAR data. 7 */ 8readonly class RepoExport 9{ 10 public function __construct( 11 public string $did, 12 public string $carData, 13 public int $size, 14 ) {} 15 16 /** 17 * Save the CAR data to a file. 18 */ 19 public function saveTo(string $path): bool 20 { 21 return file_put_contents($path, $this->carData) !== false; 22 } 23 24 /** 25 * Get the size in human-readable format. 26 */ 27 public function humanSize(): string 28 { 29 $units = ['B', 'KB', 'MB', 'GB']; 30 $size = $this->size; 31 $unit = 0; 32 33 while ($size >= 1024 && $unit < count($units) - 1) { 34 $size /= 1024; 35 $unit++; 36 } 37 38 return round($size, 2).' '.$units[$unit]; 39 } 40}