2958a26e4f
Replaces specialized binary and HTML downloaders with a generic, options-driven UnitDownloader and UnitFragmentDownloader pattern. Introduces UnitDownloaderOptions and builder classes for flexible configuration, updates interfaces and method signatures to support progress reporting, and removes redundant binary-specific classes. Updates Playwright and Stealth downloaders to use the new generic base, and adds improved error handling and reporting. Also updates dependency versions and makes minor API consistency improvements across the Fluent and Models layers.
45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using System.Collections.Concurrent;
|
|
using System.Text.Json;
|
|
using Beam.Abstractions;
|
|
using Beam.Models;
|
|
|
|
namespace Beam.Fluent;
|
|
|
|
internal sealed class DownloadStage<RawType, OutType>(DownloadEnumerable<OutType> download) : IDownloadStage<RawType, OutType> where RawType : IDocument {
|
|
private IAsyncEnumerable<Ordered<OutType>> _download = download;
|
|
|
|
public DownloadEnumerable<OutType> AsAsyncEnumerable() {
|
|
return new DownloadEnumerable<OutType>(_download.GetAsyncEnumerator());
|
|
}
|
|
|
|
private async IAsyncEnumerable<Ordered<OutType>> _SaveToDirectory(string dir) {
|
|
Directory.CreateDirectory(dir);
|
|
await foreach (var download in _download) {
|
|
await System.IO.File.WriteAllTextAsync(
|
|
Path.Combine(dir, $"{Path.GetRandomFileName()}.{download.Order}.json"),
|
|
JsonSerializer.Serialize(dir));
|
|
yield return download;
|
|
}
|
|
}
|
|
|
|
public IDownloadStage<RawType, OutType> SaveToDirectory(string dir) {
|
|
_download = _SaveToDirectory(dir);
|
|
return this;
|
|
}
|
|
|
|
public IDownloadStage<RawType, OutType> SaveToFiles(IEnumerable<string> files) {
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public IDownloadStage<RawType, OutType> SaveToMemory(ConcurrentBag<OutType> bag) {
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void WaitForDownload() {
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task WaitForDownloadAsync() {
|
|
throw new NotImplementedException();
|
|
}
|
|
} |