using System.Diagnostics.CodeAnalysis; using System.Security.Cryptography; using System.Text; using Beam.Models; namespace Beam.Downloaders; public record class UnitDownloaderOptions { public HttpClient Client { get; init; } = new(); public DownloadTarget Target { get; init; } = DownloadTarget.URL; public SkipPredicateOptions? SkipPredicateOptions { get; init; } public FailurePredicateOptions? FailurePredicateOptions { get; init; } public FragmentOptions? FragmentOptions { get; init; } public required AsyncTransformer AsyncTransformer { get; init; } /// /// The location where the download is stored. /// /// /// If not defined, UnitDownloader.TryDownload() downloads to memory. /// public string? DownloadFolder { get; init; } = null; public int BufferSize { get; init; } = 80 * 1024; // 80kb public bool FollowRedirects { get; init; } = true; public string GetFileNameForDownload(string url, byte[] additionalData) { byte[] bytes = [..Encoding.UTF8.GetBytes(url), ..additionalData]; var name = Convert.ToBase64String(System.IO.Hashing.XxHash64.Hash(bytes)); return name.Replace('+', '-').Replace('/', '_').Replace('=', ' ').Trim(); } } // ---------- UnitDownloaderOptions Builder ---------- // ---------- FailurePredicateOptions Builder ---------- // ---------- FragmentOptions Builder ----------