using System; using System.IO; using PSMinIO.Utils; namespace PSMinIO.Models { /// /// Represents the result of a MinIO download operation with timing and speed information /// public class MinIODownloadResult { /// /// The downloaded file information /// public FileInfo File { get; set; } /// /// Name of the bucket the object was downloaded from /// public string BucketName { get; set; } /// /// Name of the object that was downloaded /// public string ObjectName { get; set; } /// /// Size of the downloaded file in bytes /// public long Size => File?.Length ?? 0; /// /// Transfer start time /// public DateTime? StartTime { get; set; } /// /// Transfer completion time /// public DateTime? CompletionTime { get; set; } /// /// Transfer duration /// public TimeSpan? Duration => StartTime.HasValue && CompletionTime.HasValue ? CompletionTime.Value - StartTime.Value : null; /// /// Average transfer speed in bytes per second /// public double? AverageSpeed => Duration.HasValue && Duration.Value.TotalSeconds > 0 ? Size / Duration.Value.TotalSeconds : null; /// /// Average transfer speed formatted as string (e.g., "15.2 MB/s") /// public string? AverageSpeedFormatted => AverageSpeed.HasValue ? $"{SizeFormatter.FormatBytes((long)AverageSpeed.Value)}/s" : null; /// /// Full path to the downloaded file /// public string FullName => File?.FullName ?? string.Empty; /// /// Name of the downloaded file /// public string Name => File?.Name ?? string.Empty; /// /// Directory containing the downloaded file /// public string? DirectoryName => File?.DirectoryName; /// /// Creates a new MinIODownloadResult /// /// Downloaded file information /// Source bucket name /// Source object name /// Transfer start time /// Transfer completion time public MinIODownloadResult(FileInfo file, string bucketName, string objectName, DateTime? startTime = null, DateTime? completionTime = null) { File = file ?? throw new ArgumentNullException(nameof(file)); BucketName = bucketName ?? throw new ArgumentNullException(nameof(bucketName)); ObjectName = objectName ?? throw new ArgumentNullException(nameof(objectName)); StartTime = startTime; CompletionTime = completionTime; } /// /// Returns a string representation of the download result /// public override string ToString() { var duration = Duration?.ToString(@"hh\:mm\:ss\.fff") ?? "Unknown"; var speed = AverageSpeedFormatted ?? "Unknown"; return $"{BucketName}/{ObjectName} -> {FullName} ({SizeFormatter.FormatBytes(Size)}, {duration}, {speed})"; } } }