Gravy.MultiHttp 0.7.0

dotnet add package Gravy.MultiHttp --version 0.7.0                
NuGet\Install-Package Gravy.MultiHttp -Version 0.7.0                
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="Gravy.MultiHttp" Version="0.7.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Gravy.MultiHttp --version 0.7.0                
#r "nuget: Gravy.MultiHttp, 0.7.0"                
#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.
// Install Gravy.MultiHttp as a Cake Addin
#addin nuget:?package=Gravy.MultiHttp&version=0.7.0

// Install Gravy.MultiHttp as a Cake Tool
#tool nuget:?package=Gravy.MultiHttp&version=0.7.0                

Gravy.MultiHttp

Gravy.MultiHttp is a C# library designed for efficient and reliable multi-threaded HTTP downloading. It provides a robust framework for downloading large files by splitting them into chunks and downloading them concurrently.

Features

  • Multi-threaded Downloads: Split files into chunks and download them concurrently.
  • Resumable Downloads: Resume downloads from where they left off in case of interruptions.
  • Progress Tracking: Track the progress of each chunk and the overall download.
  • Error Handling: Handle errors gracefully and retry failed chunks.
  • Customizable: Define custom download strategies and chunk sizes.

Installation

To install Gravy.MultiHttp, add the following package to your project:

dotnet add package Gravy.MultiHttp

Usage

Basic Example

This example demonstrates how to create a simple download using DownloadBuilder.

using Gravy.MultiHttp;
using Gravy.MultiHttp.Interfaces;

var downloader = DownloadBuilder.Create()
    .AddDownload("http://example.com/file.zip", "/some/path/file.zip")
    .Build();

await downloader.StartAsync();

Customizing Chunk Size, Concurrency, and File Writing

This example shows how to customize the chunk size, the maximum number of concurrent downloads, and the file writing strategy.

using Gravy.MultiHttp;
using Gravy.MultiHttp.Interfaces;

var downloader = DownloadBuilder.Create()
    .AddDownload("http://example.com/file.zip", overwrite: true)
    .WithMaxChunkSize(1024 * 1024) // Set chunk size to 1 MB
    .WithMaxConcurrency(8) // Set maximum concurrency to 8
    .WithFileDestinationType(FileWriterType.InMemory) // Store download in memory before writing to disk
    .Build();

await downloader.StartAsync();

Adding Event Handlers

This example demonstrates how to add event handlers for tracking progress and handling errors.

using Gravy.MultiHttp;
using Gravy.MultiHttp.Interfaces;

var downloader = DownloadBuilder.Create()
    .AddDownload("http://example.com/file.zip", overwrite: true)
    .OnStarted(() => Console.WriteLine("Download started"))
    .OnProgress(progress => Console.WriteLine($"Downloaded {progress.BytesDownloaded} of {progress.TotalBytes} bytes"))
    .OnEnded(success => Console.WriteLine(success ? "Download completed" : "Download failed"))
    .OnError(ex => Console.WriteLine($"Error: {ex.Message}"))
    .Build();

await downloader.StartAsync();

Downloading Multiple Files

This example shows how to add multiple downloads to the DownloadBuilder.

using Gravy.MultiHttp;
using Gravy.MultiHttp.Interfaces;

var downloader = DownloadBuilder.Create()
    .AddDownload("http://example.com/file1.zip", overwrite: true)
    .AddDownload("http://example.com/file2.zip", overwrite: true)
    .Build();

await downloader.StartAsync();

Using a Custom HttpClient Configuration

This example demonstrates how to configure the HttpClient used by the downloader.

using Gravy.MultiHttp;
using Gravy.MultiHttp.Interfaces;

var downloader = DownloadBuilder.Create()
    .AddDownload("http://example.com/file.zip", overwrite: true)
    .ConfigureHttpClient(client => client.Timeout = TimeSpan.FromMinutes(10))
    .Build();

await downloader.StartAsync();

Setting a Destination Path

This example shows how to set a destination path for the downloads.

using Gravy.MultiHttp;
using Gravy.MultiHttp.Interfaces;

var downloader = DownloadBuilder.Create("C:\\Downloads")
    .AddDownload("http://example.com/file.zip", overwrite: true)
    .Build();

await downloader.StartAsync();

Handling File-Specific Events

This example demonstrates how to handle events specific to individual files.

using Gravy.MultiHttp;
using Gravy.MultiHttp.Interfaces;

var downloader = DownloadBuilder.Create()
    .AddDownload("http://example.com/file.zip", overwrite: true)
    .OnFileStarted(file => Console.WriteLine($"File download started: {file.FileName}"))
    .OnFileProgress(progress => Console.WriteLine($"File progress: {progress.BytesDownloaded} of {progress.TotalBytes} bytes"))
    .OnFileEnded(file => Console.WriteLine($"File download completed: {file.FileName}"))
    .OnFileError(fe => Console.WriteLine($"Error downloading file {fe.File.FileName}: {fe.Exception.Message}"))
    .Build();

await downloader.StartAsync();

License

This package is licensed under the MIT License. See the LICENSE file for more details.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 is compatible.  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 is compatible.  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 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.7.0 76 12/29/2024
0.6.0 81 12/26/2024