Skip to content

Commit

Permalink
refactor Download.cs file
Browse files Browse the repository at this point in the history
  • Loading branch information
bezzad committed Sep 18, 2024
1 parent d821e80 commit 71bef71
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/Downloader/Download.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,26 @@ public async Task<Stream> StartAsync(CancellationToken cancellationToken = defau
{
if (string.IsNullOrWhiteSpace(Package?.Urls?.FirstOrDefault()))
{
if (string.IsNullOrWhiteSpace(Folder) && string.IsNullOrWhiteSpace(Filename))
if (string.IsNullOrWhiteSpace(Filename))
{
return await _downloadService.DownloadFileTaskAsync(Url, cancellationToken).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(Folder))
{
// store on memory stream so return stream
return await _downloadService.DownloadFileTaskAsync(Url, cancellationToken).ConfigureAwait(false);
}

// store on a file with the given path and url fetching name
await _downloadService.DownloadFileTaskAsync(Url,
new DirectoryInfo(Folder), cancellationToken).ConfigureAwait(false);
}

if (string.IsNullOrWhiteSpace(Filename))
else
{
await _downloadService.DownloadFileTaskAsync(Url, new DirectoryInfo(Folder!), cancellationToken)
.ConfigureAwait(false);
return null;
// // store on a file with the given name and folder path
await _downloadService.DownloadFileTaskAsync(Url, Path.Combine(Folder, Filename), cancellationToken)
.ConfigureAwait(false);
}

// with Folder and Filename
await _downloadService.DownloadFileTaskAsync(Url, Path.Combine(Folder!, Filename), cancellationToken)
.ConfigureAwait(false);
return null;

return Stream.Null;
}

if (string.IsNullOrWhiteSpace(Url))
Expand Down

0 comments on commit 71bef71

Please sign in to comment.