Skip to content

Commit

Permalink
added EnableLiveStreaming option to config to remove ReceiveBytes arr…
Browse files Browse the repository at this point in the history
…ay by default to reduce consume memory issue.
  • Loading branch information
bezzad committed Sep 18, 2024
1 parent 38f29bc commit f6a9e86
Showing 1 changed file with 31 additions and 34 deletions.
65 changes: 31 additions & 34 deletions src/Downloader/DownloadConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,25 @@ namespace Downloader;

public class DownloadConfiguration : ICloneable, INotifyPropertyChanged
{
private int _bufferBlockSize;
private int _chunkCount;
private long _maximumBytesPerSecond;
private int _maximumTryAgainOnFailover;
private int _bufferBlockSize = 1024; // usually, hosts support max to 8000 bytes
private int _chunkCount = 1; // file parts to download
private long _maximumBytesPerSecond = ThrottledStream.Infinite; // No-limitation in download speed
private int _maximumTryAgainOnFailover = int.MaxValue; // the maximum number of times to fail.
private long _maximumMemoryBufferBytes;
private bool _checkDiskSizeBeforeDownload;
private bool _parallelDownload;
private int _parallelCount;
private int _timeout;
private bool _rangeDownload;
private long _rangeLow;
private long _rangeHigh;
private bool _clearPackageOnCompletionWithFailure;
private long _minimumSizeOfChunking;
private bool _reserveStorageSpaceBeforeStartingDownload;
private bool _checkDiskSizeBeforeDownload = true; // check disk size for temp and file path
private bool _parallelDownload = false; // download parts of file as parallel or not
private int _parallelCount = 0; // number of parallel downloads
private int _timeout = 1000; // timeout (millisecond) per stream block reader
private bool _rangeDownload = false; // enable ranged download
private long _rangeLow = 0; // starting byte offset
private long _rangeHigh = 0; // ending byte offset
private bool _clearPackageOnCompletionWithFailure = false; // Clear package and downloaded data when download completed with failure
private long _minimumSizeOfChunking = 512; // minimum size of chunking to download a file in multiple parts
private bool _reserveStorageSpaceBeforeStartingDownload = false; // Before starting the download, reserve the storage space of the file as file size.
private bool _enableLiveStreaming = false; // Get on demand downloaded data with ReceivedBytes on downloadProgressChanged event

public event PropertyChangedEventHandler PropertyChanged = delegate { };

public DownloadConfiguration()
{
RequestConfiguration = new RequestConfiguration(); // default requests configuration
_maximumTryAgainOnFailover = int.MaxValue; // the maximum number of times to fail.
_parallelDownload = false; // download parts of file as parallel or not
_parallelCount = 0; // number of parallel downloads
_chunkCount = 1; // file parts to download
_timeout = 1000; // timeout (millisecond) per stream block reader
_bufferBlockSize = 1024; // usually, hosts support max to 8000 bytes
_maximumBytesPerSecond = ThrottledStream.Infinite; // No-limitation in download speed
_checkDiskSizeBeforeDownload = true; // check disk size for temp and file path
_rangeDownload = false; // enable ranged download
_rangeLow = 0; // starting byte offset
_rangeHigh = 0; // ending byte offset
_clearPackageOnCompletionWithFailure = false; // Clear package and downloaded data when download completed with failure
_minimumSizeOfChunking = 512; // minimum size of chunking to download a file in multiple parts
_reserveStorageSpaceBeforeStartingDownload = false; // Before starting the download, reserve the storage space of the file as file size.
}

/// <summary>
/// Create the OnPropertyChanged method to raise the event
/// The calling member's name will be used as the parameter.
Expand Down Expand Up @@ -195,7 +177,7 @@ public long RangeHigh
/// <summary>
/// Custom body of your requests
/// </summary>
public RequestConfiguration RequestConfiguration { get; set; }
public RequestConfiguration RequestConfiguration { get; set; } = new(); // default requests configuration

/// <summary>
/// Download timeout per stream file blocks
Expand Down Expand Up @@ -272,6 +254,21 @@ public long MaximumMemoryBufferBytes
OnPropertyChanged();
}
}

/// <summary>
/// Set live streaming is enable or not. If it's enable get the on demand downloaded data
/// with ReceivedBytes on downloadProgressChanged event
/// Note: This option may consume more memory because copied each block of downloaded data in to ReceivedBytes
/// </summary>
public bool EnableLiveStreaming
{
get => _enableLiveStreaming;
set
{
_enableLiveStreaming = value;
OnPropertyChanged();
}
}

public object Clone()
{
Expand Down

0 comments on commit f6a9e86

Please sign in to comment.