VOOZH about

URL: https://www.nuget.org/packages/BrotliSharpLib/

⇱ NuGet Gallery | BrotliSharpLib 0.3.3




BrotliSharpLib 0.3.3

dotnet add package BrotliSharpLib --version 0.3.3
 
 
NuGet\Install-Package BrotliSharpLib -Version 0.3.3
 
 
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="BrotliSharpLib" Version="0.3.3" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BrotliSharpLib" Version="0.3.3" />
 
Directory.Packages.props
<PackageReference Include="BrotliSharpLib" />
 
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 BrotliSharpLib --version 0.3.3
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: BrotliSharpLib, 0.3.3"
 
 
#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 BrotliSharpLib@0.3.3
 
 
#: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=BrotliSharpLib&version=0.3.3
 
Install as a Cake Addin
#tool nuget:?package=BrotliSharpLib&version=0.3.3
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

BrotliSharpLib

BrotliSharpLib is a full C# port of the brotli library/compression code by Google. It is intended to be a mostly 1:1 conversion of the original C code. All code is correct as of v0.6.0 of the reference implementation.

The projects uses a minimal set of APIs to ensure compatibility with a wide range of frameworks including .NET Standard and .NET Core. It also supports little-endian and big-endian architectures and is optimised for x86, x64 and ARM processors.

BrotliSharpLib is licensed under MIT.

Installation

BrotliSharpLib can be installed via the NuGet package here.

Install-Package BrotliSharpLib

Usage

Generic/basic usage:

/** Decompression **/
byte[] brotliCompressedData = ...; // arbritary data source
byte[] uncompressedData = Brotli.DecompressBuffer(brotliCompressedData, 0, brotliCompressedData.Length /**, customDictionary **/);

/** Compression **/
byte[] uncompressedData = ...; // arbritary data source

// By default, brotli uses a quality value of 11 and window size of 22 if the parameters are omitted.
byte[] compressedData = Brotli.CompressBuffer(uncompressedData, 0, uncompressedData.Length /**, quality, windowSize, customDictionary **/);

Stream usage:

/** Decompression **/
using (var ms = new MemoryStream())
using (var bs = new BrotliStream(compressedStream, CompressionMode.Decompress))
{
 bs.CopyTo(ms);
}

/** Compression **/
using (var fs = File.OpenRead(filePath))
using (var ms = new MemoryStream())
{
 using (var bs = new BrotliStream(ms, CompressionMode.Compress))
 {
 // By default, BrotliSharpLib uses a quality value of 1 and window size of 22 if the methods are not called.
 /** bs.SetQuality(quality); **/
 /** bs.SetWindow(windowSize); **/
 /** bs.SetCustomDictionary(customDict); **/
 fs.CopyTo(bs);
 
 /* IMPORTANT: Only use the destination stream after closing/disposing the BrotliStream
 as the BrotliStream must be closed in order to signal that no more blocks are being written
 for the final block to be flushed out 
 */
 bs.Dispose();
 byte[] compressed = ms.ToArray();
 }
}

Real-life example: The following allows for acceptance and decompression of brotli encoded web content via a HttpClient and falls back to gzip or deflate when required.

static class HttpClientEx
{
 private class BrotliCompressionHandler : DelegatingHandler
 {
 protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
 {
 request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("br"));
 var response = await base.SendAsync(request, cancellationToken);
 IEnumerable<string> ce;
 if (response.Content.Headers.TryGetValues("Content-Encoding", out ce) && ce.First() == "br")
 {
 var buffer = await response.Content.ReadAsByteArrayAsync();
 response.Content = new ByteArrayContent(Brotli.DecompressBuffer(buffer, 0, buffer.Length));
 }
 return response;
 }
 }

 public static HttpClient Create()
 {
 var handler = new HttpClientHandler();
 if (handler.SupportsAutomaticDecompression)
 handler.AutomaticDecompression = System.Net.DecompressionMethods.Deflate | System.Net.DecompressionMethods.GZip;
 return HttpClientFactory.Create(handler, new BrotliCompressionHandler());
 }
}

Performance

Considerations for Build

For optimal performance, ensure to build BrotliSharpLib in Release mode to enable all possible JIT optimisations.

Performance can also be further improved by building BrotliSharpLib using .NET Framework 4.5 or above (or any framework that supports AggressiveInlining). Selecting a specific target platform (instead of AnyCPU) where possible can also further improve performance. All of this however, is completely optional as BrotliSharpLib is designed to run in a wide range of contexts and configurations regardless.

Benchmark

The following are benchmark results using DotNetBenchmark with BrotliSharpLib (v0.2.1) and Google's C# implementation built against .NET Framework 4.6.1. The original C version was compiled in Release mode using Visual Studio 2017 (v141) as a 64-bit Windows executable.

BenchmarkDotNet=v0.10.6, OS=Windows 10 Redstone 2 (10.0.15063)
Processor=Intel Core i5-6600K CPU 3.50GHz (Skylake), ProcessorCount=4
Frequency=3421875 Hz, Resolution=292.2374 ns, Timer=TSC
 [Host] : Clr 4.0.30319.42000, 64bit RyuJIT-v4.7.2046.0
 RyuJitX64 : Clr 4.0.30319.42000, 64bit RyuJIT-v4.7.2046.0
Runtime=Clr 
Decompression

File: UPX v3.91 (Windows Executable)

Method Mean
GoogleImpl 12.75 ms
BrotliSharpLib 11.63 ms
Original C 11.17 ms

As seen above, BrotliSharpLib performs close to the original C version in terms of decompression.

Compression

File: plrabn12.txt

Method Quality Mean
BrotliSharpLib 1 9.132 ms
Original C 1 9.570 ms
BrotliSharpLib 6 58.720 ms
Original C 6 36.540 ms
BrotliSharpLib 9 116.318 ms
Original C 9 73.080 ms
BrotliSharpLib 11 1822.702 ms
Original C 11 877.58 ms

While BrotliSharpLib performs comparatively at lower quality levels, it performs up to three times worse at level 11. Future versions of the port will hopefully bring this down.

Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 was computed.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp1.0 netcoreapp1.0 was computed.  netcoreapp1.1 netcoreapp1.1 was computed.  netcoreapp2.0 netcoreapp2.0 was computed.  netcoreapp2.1 netcoreapp2.1 was computed.  netcoreapp2.2 netcoreapp2.2 was computed.  netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard1.1 netstandard1.1 is compatible.  netstandard1.2 netstandard1.2 was computed.  netstandard1.3 netstandard1.3 is compatible.  netstandard1.4 netstandard1.4 was computed.  netstandard1.5 netstandard1.5 was computed.  netstandard1.6 netstandard1.6 was computed.  netstandard2.0 netstandard2.0 is compatible.  netstandard2.1 netstandard2.1 was computed. 
.NET Framework net20 net20 is compatible.  net35 net35 is compatible.  net40 net40 is compatible.  net403 net403 was computed.  net45 net45 is compatible.  net451 net451 is compatible.  net452 net452 was computed.  net46 net46 was computed.  net461 net461 was computed.  net462 net462 was computed.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen30 tizen30 was computed.  tizen40 tizen40 was computed.  tizen60 tizen60 was computed. 
Universal Windows Platform uap uap was computed.  uap10.0 uap10.0 was computed. 
Windows Phone wpa81 wpa81 was computed. 
Windows Store netcore netcore was computed.  netcore45 netcore45 was computed.  netcore451 netcore451 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (27)

Showing the top 5 NuGet packages that depend on BrotliSharpLib:

Package Downloads
AvroConvert

Rapid Apache Avro serializer for .NET.

Titanium.Web.Proxy

Package Description

HttpReports

HttpReports is a lightweight APM system developed for .NET Core

Pineapple

Pineapple is a set of core libraries that includes utilities, primitives, helper classes for .NET! The inspiration for Pineapple comes from Google's Guava framework.

WebMarkupMin.AspNet.Brotli

WebMarkupMin.AspNet.Brotli contains one compressor-adapter for compression of text content by using the Brotli algorithm - `BrotliCompressor`. `BrotliCompressor` is based on the BrotliSharpLib.

GitHub repositories (12)

Showing the top 12 popular GitHub repositories that depend on BrotliSharpLib:

Repository Stars
nilaoda/N_m3u8DL-CLI
[.NET] m3u8 downloader 开源的命令行m3u8/HLS/dash下载器,支持普通AES-128-CBC解密,多线程,自定义请求头等. 支持简体中文,繁体中文和英文. English Supported.
BililiveRecorder/BililiveRecorder
录播姬 | mikufans 生放送录制
justcoding121/titanium-web-proxy
A cross-platform asynchronous HTTP(S) proxy server in C#.
ape-byte/DouyinBarrageGrab
基于系统代理的抖音弹幕wss抓取程序,能够获取所有数据来源,包括chrome,抖音直播伴侣等,可进行进程过滤
dotnetcore/HttpReports
HttpReports is an APM (application performance monitor) system for .Net Core.
ProfessorJTJ/HISuite-Proxy
Modifying HiSuite and manipulating it's connection data to install Roms before they officially get released.
vchelaru/Gum
Flexible layout tool for creating UI on any platform
Taritsyn/WebMarkupMin
The Web Markup Minifier (abbreviated WebMarkupMin) - a .NET library that contains a set of markup minifiers. The objective of this project is to improve the performance of web applications by reducing the size of HTML, XHTML and XML code.
pengw0048/NeteaseReverseLadder
Play your favorite songs in Netease Cloud Music that are banned outside Mainland China. 解除网易云音乐海外播放限制。
jamesbrindle/YTMusicUploader
Automatically upload your music library and playlists to YouTube Music .Net Application. Upload songs to YouTube Music and bulk delete music and playlists from YouTube Music. C#.
ChenZ2000/YTPlayer
Accessible Netease Music | 易用的网易云音乐客户端
AdrianStrugala/AvroConvert
Rapid Avro serializer for C# .NET
Version Downloads Last Updated
0.3.3 7,633,269 2/6/2019
0.3.2 31,969 12/9/2018
0.3.1 127,599 10/5/2018
0.3.0 10,109 7/3/2018
0.2.1 70,927 7/16/2017
0.2.0 3,065 6/28/2017