Home

Awesome

C# CodeQL CodeFactor codebeat badge NuGet latest version NuGet Downloads

alt tag

A high Performance C# file downloader that asyncrounously downloads files as pieces. Made as a faster, more efficent replacement to Microsoft's WebClient.Want to see the library in action? Check out Octane YouTube Extractor

Installation

dotnet add package OctaneEngineCore

Features

Usage

private const string Url = "https://plugins.jetbrains.com/files/7973/281233/sonarlint-intellij-7.4.0.60471.zip?updateId=281233&pluginId=7973&family=INTELLIJ";
        
private static void Main(){
     #region Logging Configuration
          var seriLog = new LoggerConfiguration()
               .Enrich.FromLogContext()
               .MinimumLevel.Error()
               .WriteTo.Async(a => a.File("./OctaneLog.txt"))
               .WriteTo.Async(a => a.Console(theme: AnsiConsoleTheme.Sixteen))
               .CreateLogger();
            var factory = LoggerFactory.Create(logging =>
            {
                logging.AddSerilog(seriLog);
            });
     #endregion

     #region Configuration Loading
          var builder = new ConfigurationBuilder();
          builder.SetBasePath(Directory.GetCurrentDirectory())
               .AddJsonFile("appsettings.json", true, true);
          var configRoot = builder.Build();
     #endregion

     #region Find and Set optimal number of parts
          //var optimalNumberOfParts = Engine.GetOptimalNumberOfParts(Url).Result;
          //seriLog.Information("Optimal number of parts to download file: {OptimalNumberOfParts}", optimalNumberOfParts);
          //seriLog.Information("Speed: {Result}", NetworkAnalyzer.GetCurrentNetworkSpeed().Result);
          //seriLog.Information("Latency: {Result}", NetworkAnalyzer.GetCurrentNetworkLatency().Result);
     #endregion

     var pauseTokenSource = new PauseTokenSource();
     using var cancelTokenSource = new CancellationTokenSource();
     var containerBuilder = new ContainerBuilder();
     containerBuilder.RegisterInstance(factory).As<ILoggerFactory>();
     containerBuilder.RegisterInstance(configRoot).As<IConfiguration>();
     containerBuilder.AddOctane();
     var engineContainer = containerBuilder.Build();
     var engine = engineContainer.Resolve<IEngine>();
     engine.DownloadFile(Url, null, pauseTokenSource, cancelTokenSource).Wait();
}
        

Benchmark

BenchmarkDotNet v0.13.12, Windows 10 (10.0.19045.3803/22H2/2022Update)
12th Gen Intel Core i7-12700K, 1 CPU, 20 logical and 12 physical cores
.NET SDK 8.0.100
[Host] : .NET 6.0.25 (6.0.2523.51912), X64 RyuJIT AVX2 [AttachedDebugger]
Job-GUGLRW : .NET 6.0.25 (6.0.2523.51912), X64 RyuJIT AVX2
Platform=X64 IterationCount=5 WarmupCount=0
MethodUrlMeanErrorStdDev
BenchmarkOctanehttp:(...)150MB [30]8.773 s1.321 s0.3430 s
BenchmarkOctaneLowMemoryhttp:(...)150MB [30]8.999 s0.5978 s0.0925 s
BenchmarkHttpClienthttp:(...)150MB [30]8.648 s0.7375 s0.1915 s
BenchmarkOctanehttps(...)250MB [31]14.335 s2.095 s0.5440 s
BenchmarkOctaneLowMemoryhttps(...)250MB [31]14.159 s1.7879 s0.4643 s
BenchmarkHttpClienthttps(...)250MB [31]15.775 s2.2267 s0.3446 s
BenchmarkOctanehttps(...)500MB [31]28.262 s1.876 s0.2904 s
BenchmarkOctaneLowMemoryhttps(...)500MB [31]27.303 s1.0371 s0.2693 s
BenchmarkHttpClienthttps(...)500MB [31]31.325 s1.7619 s0.2727 s

License

The MIT License (MIT)

Copyright (c) 2015 Greg James

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Contributors

GitHub Contributors Image