Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Downloader/ChunkHub.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;

namespace Downloader;

Expand Down Expand Up @@ -69,6 +70,16 @@ private void Validate(DownloadPackage package)
_chunkCount = 1;
}

if (_config.MinimumChunkSize > 0)
{
int maxChunksByMinSize = (int)(package.TotalFileSize / _config.MinimumChunkSize);
if (maxChunksByMinSize < 1)
maxChunksByMinSize = 1;

// Respect both ChunkCount and MinChunkSize constraints
_chunkCount = Math.Min(_config.ChunkCount, maxChunksByMinSize);
}

_chunkSize = package.TotalFileSize / _chunkCount;
}

Expand Down
15 changes: 15 additions & 0 deletions src/Downloader/DownloadConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class DownloadConfiguration : ICloneable, INotifyPropertyChanged
// minimum size of chunking to download a file in multiple parts
private long _minimumSizeOfChunking = 512;

// minimum size of a single chunk
private long _minimumChunkSize = 0;

// Before starting the download, reserve the storage space of the file as file size.
private bool _reserveStorageSpaceBeforeStartingDownload;

Expand Down Expand Up @@ -218,6 +221,18 @@ public long MinimumSizeOfChunking
set => OnPropertyChanged(ref _minimumSizeOfChunking, value);
}

/// <summary>
/// Gets or sets the minimum size of a single chunk
/// If it is not 0 it dynamically reduces the chunk count to keep the chunk size above this value
/// Keeps ChunkCount as a Maximum
/// Default value is 0
/// </summary>
public long MinimumChunkSize
{
get => _minimumChunkSize;
set => OnPropertyChanged(ref _minimumChunkSize, value);
}

/// <summary>
/// Gets or sets a value indicating whether to reserve the storage space of the file as file size before starting the download.
/// Default value is false.
Expand Down
1 change: 1 addition & 0 deletions src/Samples/Downloader.Sample/Program.Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private static DownloadConfiguration GetDownloadConfiguration()
RangeHigh = 0, // ceiling offset of download range of a large file
ClearPackageOnCompletionWithFailure = true, // Clear package and downloaded data when download completed with failure, default value is false
MinimumSizeOfChunking = 1024, // minimum size of chunking to download a file in multiple parts, default value is 512
MinimumChunkSize = 0, // minimum size of a single chunk, 0 disables this, default is 0
ReserveStorageSpaceBeforeStartingDownload = false, // Before starting the download, reserve the storage space of the file as file size, default value is false
EnableLiveStreaming = false, // Get on demand downloaded data with ReceivedBytes on downloadProgressChanged event
RequestConfiguration =
Expand Down