bloomtom.HttpProgress
2.1.0
See the version list below for details.
dotnet add package bloomtom.HttpProgress --version 2.1.0
NuGet\Install-Package bloomtom.HttpProgress -Version 2.1.0
<PackageReference Include="bloomtom.HttpProgress" Version="2.1.0" />
paket add bloomtom.HttpProgress --version 2.1.0
#r "nuget: bloomtom.HttpProgress, 2.1.0"
// Install bloomtom.HttpProgress as a Cake Addin #addin nuget:?package=bloomtom.HttpProgress&version=2.1.0 // Install bloomtom.HttpProgress as a Cake Tool #tool nuget:?package=bloomtom.HttpProgress&version=2.1.0
HttpProgress
A set of extension methods for
HttpClient
which adds progress reporting.
HttpClient doesn't natively support progress reporting? Yes, it's true. You're expected to make your own HttpContent
which overrides SerializeToStreamAsync
for PutAsync
and PostAsync
, and you're expected to extend GetAsync
with progress reporting in the stream copy logic. Well guess what? I've done that for you.
Nuget Packages
Package Name | Target Framework | Version |
---|---|---|
HttpProgress | .NET Standard 2.0 |
Usage
Add HttpProgress to your usings.
using HttpProgress;
Use the HttpClient
extensions.
// Make your progress event.
var progress = new Action<ICopyProgress>(x =>
{
// This is your progress event!
// It will fire on every buffer fill so don't do anything expensive.
// Writing to the console is expensive, so don't do the following in practice...
Console.WriteLine(x.PercentComplete.ToString("P"));
});
// Post
using (var fileStream = System.IO.File.OpenRead("MyFile.txt"))
{
var result = await client.PostAsync("https://mysite.com/something", fileStream, progress);
}
// Get
using (var downloadStream = new MemoryStream())
{
var response = await client.GetAsync("https://mysite.com/something", downloadStream, progress);
}
Woah, that was easy. But what if you want more than just percent complete? Well the progress event actually gives you all of the following in ICopyProgress
:
public interface ICopyProgress
{
/// <summary>
/// The instantaneous data transfer rate.
/// </summary>
int BytesPerSecond { get; }
/// <summary>
/// The total number of bytes transfered so far.
/// </summary>
long BytesTransfered { get; }
/// <summary>
/// The total number of bytes expected to be copied.
/// </summary>
long ExpectedBytes { get; }
/// <summary>
/// The percentage complete as a value 0-1.
/// </summary>
double PercentComplete { get; }
/// <summary>
/// The total time elapsed so far.
/// </summary>
TimeSpan TransferTime { get; }
}
Performance Considerations
The action you give for progress reporting will fire on every buffer cycle. This can happen many times! With a 16kB buffer transfering a 10MB file will cause 640 events to be fired. Since the event blocks the data transfer while it's running, you can seriously slow down your transfer rate by doing expensive operations in it.
If you need to do time consuming operations, consider rate limiting them. A simple way to do this is to only fire your expensive operation when TransferTime
or PercentComplete
crosses specific thresholds. A more complex but "prettier" solution is to buffer ICopyProgress
and have a threaded reader to refresh your UI on a timer.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on bloomtom.HttpProgress:
Package | Downloads |
---|---|
bloomtom.BunAPI
A simple API for file management on BunnyCDN's file storage. https://bunnycdn.com |
|
bloomtom.MStorage
Bridges multiple storage backends into a simple object store layer. |
GitHub repositories (3)
Showing the top 3 popular GitHub repositories that depend on bloomtom.HttpProgress:
Repository | Stars |
---|---|
t1m0thyj/WinDynamicDesktop
Port of macOS Mojave Dynamic Desktop feature to Windows
|
|
CircumSpector/DS4Windows
A reimagination of DS4Windows.
|
|
Mongo2Go/Mongo2Go
Mongo2Go - MongoDB for .NET integration tests
|
Version | Downloads | Last updated |
---|---|---|
2.3.2 | 18,217 | 1/29/2020 |
2.3.1 | 24,527 | 1/26/2019 |
2.3.0 | 1,619 | 12/31/2018 |
2.2.2 | 1,190 | 12/30/2018 |
2.2.1 | 1,101 | 12/30/2018 |
2.2.0 | 1,108 | 12/30/2018 |
2.1.0 | 1,496 | 12/28/2018 |
2.0.2 | 1,897 | 12/20/2018 |
2.0.1 | 1,200 | 12/20/2018 |
2.0.0 | 1,303 | 12/19/2018 |
1.0.5 | 1,553 | 11/25/2018 |
1.0.4 | 1,312 | 11/25/2018 |
1.0.3 | 1,302 | 11/25/2018 |
1.0.2 | 1,326 | 11/25/2018 |
1.0.1 | 1,362 | 11/25/2018 |
1.0.0 | 1,122 | 11/25/2018 |