-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Zstd compression (#518)
- Loading branch information
1 parent
5b35a47
commit 2547873
Showing
8 changed files
with
102 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.IO.Compression; | ||
|
||
using GenHTTP.Api.Content.IO; | ||
using GenHTTP.Api.Infrastructure; | ||
using GenHTTP.Api.Protocol; | ||
|
||
using ZstdSharp; | ||
|
||
namespace GenHTTP.Modules.Compression.Providers; | ||
|
||
public sealed class ZstdCompression : ICompressionAlgorithm | ||
{ | ||
|
||
public string Name => "zstd"; | ||
|
||
public Priority Priority => Priority.High; | ||
|
||
public IResponseContent Compress(IResponseContent content, CompressionLevel level) | ||
{ | ||
return new CompressedResponseContent(content, (target) => new CompressionStream(target, level: MapLevel(level), leaveOpen: false)); | ||
} | ||
|
||
private static int MapLevel(CompressionLevel level) | ||
{ | ||
return level switch | ||
{ | ||
CompressionLevel.Fastest => 1, | ||
CompressionLevel.SmallestSize => 22, | ||
CompressionLevel.Optimal => 3, | ||
_ => throw new InvalidOperationException($"Unable to map compression level {level}") | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd"> | ||
|
||
<metadata> | ||
|
||
<id>GenHTTP.Core</id> | ||
<version>9.0.0</version> | ||
|
||
<description>Basic dependencies for projects using the GenHTTP framework, including the engine itself</description> | ||
<copyright></copyright> | ||
|
||
<projectUrl>https://genhttp.org/</projectUrl> | ||
|
||
<authors>Andreas Nägeli</authors> | ||
<tags>HTTP Webserver Library C# Server Embeddable Embedded Host</tags> | ||
<tags>HTTP Webserver Library C# Server REST API Embeddable Embedded Host</tags> | ||
|
||
<icon>images\icon.png</icon> | ||
|
||
<license type="file">LICENSE</license> | ||
<requireLicenseAcceptance>false</requireLicenseAcceptance> | ||
|
||
<dependencies> | ||
|
||
<group> | ||
|
||
<dependency id="GenHTTP.Api" version="9.0.0" /> | ||
|
||
<dependency id="GenHTTP.Engine" version="9.0.0" /> | ||
<dependency id="GenHTTP.Modules.Practices" version="9.0.0" /> | ||
|
||
<dependency id="GenHTTP.Modules.Practices" version="9.0.0" /> | ||
<dependency id="GenHTTP.Modules.Basics" version="9.0.0" /> | ||
<dependency id="GenHTTP.Modules.Layouting" version="9.0.0" /> | ||
|
||
</group> | ||
|
||
</dependencies> | ||
|
||
</metadata> | ||
|
||
<files> | ||
<file src="..\Resources\icon.png" target="images\" /> | ||
<file src="..\LICENSE" target="LICENSE" /> | ||
</files> | ||
</package> | ||
|
||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters