bloomtom.HttpProgress 2.2.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package bloomtom.HttpProgress --version 2.2.1
                    
NuGet\Install-Package bloomtom.HttpProgress -Version 2.2.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="bloomtom.HttpProgress" Version="2.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="bloomtom.HttpProgress" Version="2.2.1" />
                    
Directory.Packages.props
<PackageReference Include="bloomtom.HttpProgress" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add bloomtom.HttpProgress --version 2.2.1
                    
#r "nuget: bloomtom.HttpProgress, 2.2.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package bloomtom.HttpProgress@2.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=bloomtom.HttpProgress&version=2.2.1
                    
Install as a Cake Addin
#tool nuget:?package=bloomtom.HttpProgress&version=2.2.1
                    
Install as a Cake Tool

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 NuGet

Usage

Add HttpProgress to your usings.

using HttpProgress;

Use the HttpClient extensions.

// Make your progress event.
var progress = new Progress<ICopyProgress>(x => // Please see "Notes on IProgress<T>"
{
    // 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; }
}

Notes on IProgress<T>

Concrete Implementation

The type Progress<T> is provided by the framework for use cases where the progress changed event should be processed through your application's synchronization context. This is useful for desktop UI applications where modifying controls from the progress event needs to be done on the event loop thread. For console applications, which have no intelligent synchronization context, the event will end up on the thread pool and will likely be executed out of order. If this is undesirable, you can use your own implementation of IProgress. Doing this is very easy, and an example is provided in the unit test project class NaiveProgress<T>.

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.

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 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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 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.

LNITek.Appwrite

A SDK to comunicate between your app and Appwrite server. This SDK does support Server & Client opterations. Account - Unsupported Users - Supported Teams - Unsupported Database - Realtime - Unsupported Read / Write - Supported POCO / DAO - Supported Structure - WIP Auto structure - Unsupported Relationships - Semi-Support Storage - Supported Functions - Client - Supported Server - Semi-Support Runtime - WIP Messaging - Unsupported Sites - Unsupported

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 27,310 1/29/2020
2.3.1 26,245 1/26/2019
2.3.0 1,706 12/31/2018
2.2.2 1,283 12/30/2018
2.2.1 1,188 12/30/2018
2.2.0 1,196 12/30/2018
2.1.0 1,580 12/28/2018
2.0.2 1,983 12/20/2018
2.0.1 1,290 12/20/2018
2.0.0 1,395 12/19/2018
1.0.5 1,641 11/25/2018
1.0.4 1,420 11/25/2018
1.0.3 1,395 11/25/2018
1.0.2 1,412 11/25/2018
1.0.1 1,451 11/25/2018
1.0.0 1,222 11/25/2018