Skip to content

Commit

Permalink
Complete ZLib compressor.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mutuduxf committed Oct 8, 2024
1 parent e563d71 commit a34bfbf
Show file tree
Hide file tree
Showing 37 changed files with 486 additions and 65 deletions.
25 changes: 15 additions & 10 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@

Aoxe.Compression 提供了以下实现:

| Compressor | Package | Reference |
| :--------: | :----------------: | :------------------: |
| Brotli | Aoxe.Brotli | Brotli.NET |
| BZip | Aoxe.SharpZipLib | SharpZipLib |
| GZip | Aoxe.SharpZipLib | SharpZipLib |
| LZ4 | Aoxe.LZ4 | K4os.Compression.LZ4 |
| LZMA | Aoxe.LZMA | LZMA-SDK |
| XZ | Aoxe.XZ | XZ.NET-netstandard |
| Zstd | Aoxe.Zstd | ZstdNet |
| Compressor | Package | Reference |
|:----------:|:-------------------------------------------:|:-----------------------------------:|
| Brotli | Aoxe.Brotli / Aoxe.SystemIoCompression | Brotli.NET / System.IO.Compression |
| LZ4 | Aoxe.LZ4 | K4os.Compression.LZ4 |
| LZMA | Aoxe.LZMA | LZMA-SDK |
| BZip2 | Aoxe.SharpZipLib | SharpZipLib |
| Deflate | Aoxe.SharpZipLib / Aoxe.SystemIoCompression | SharpZipLib / System.IO.Compression |
| GZip | Aoxe.SharpZipLib / Aoxe.SystemIoCompression | SharpZipLib / System.IO.Compression |
| Snappy | Aoxe.Snappy | IronSnappy |
| ZLib | Aoxe.SystemIoCompression | System.IO.Compression |
| XZ | Aoxe.XZ | XZ.NET-netstandard |
| Zstd | Aoxe.Zstd | ZstdNet |

## 2. 如何使用 Aoxe.Compression?

Expand All @@ -30,9 +33,11 @@ Aoxe.Compression 提供了以下实现:

```shell
dotnet add package Aoxe.Brotli
dotnet add package Aoxe.SharpZipLib
dotnet add package Aoxe.LZ4
dotnet add package Aoxe.LZMA
dotnet add package Aoxe.SharpZipLib
dotnet add package Aoxe.Snappy
dotnet add package Aoxe.SystemIoCompression
dotnet add package Aoxe.XZ
dotnet add package Aoxe.Zstd
```
Expand Down
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ There are many compressors in the .NET ecosystem, but they are not easy to use.

The compressors that Aoxe.Compression supports are as follows:

| Compressor | Package | Reference |
| :--------: | :----------------: | :------------------: |
| Brotli | Aoxe.Brotli | Brotli.NET |
| BZip | Aoxe.SharpZipLib | SharpZipLib |
| GZip | Aoxe.SharpZipLib | SharpZipLib |
| LZ4 | Aoxe.LZ4 | K4os.Compression.LZ4 |
| LZMA | Aoxe.LZMA | LZMA-SDK |
| XZ | Aoxe.XZ | XZ.NET-netstandard |
| Zstd | Aoxe.Zstd | ZstdNet |
| Compressor | Package | Reference |
|:----------:|:-------------------------------------------:|:-----------------------------------:|
| Brotli | Aoxe.Brotli / Aoxe.SystemIoCompression | Brotli.NET / System.IO.Compression |
| LZ4 | Aoxe.LZ4 | K4os.Compression.LZ4 |
| LZMA | Aoxe.LZMA | LZMA-SDK |
| BZip2 | Aoxe.SharpZipLib | SharpZipLib |
| Deflate | Aoxe.SharpZipLib / Aoxe.SystemIoCompression | SharpZipLib / System.IO.Compression |
| GZip | Aoxe.SharpZipLib / Aoxe.SystemIoCompression | SharpZipLib / System.IO.Compression |
| Snappy | Aoxe.Snappy | IronSnappy |
| ZLib | Aoxe.SystemIoCompression | System.IO.Compression |
| XZ | Aoxe.XZ | XZ.NET-netstandard |
| Zstd | Aoxe.Zstd | ZstdNet |

## 2. How to use Aoxe.Compression?

Expand All @@ -30,9 +33,11 @@ You can install the package which you want on nuget

```shell
dotnet add package Aoxe.Brotli
dotnet add package Aoxe.SharpZipLib
dotnet add package Aoxe.LZ4
dotnet add package Aoxe.LZMA
dotnet add package Aoxe.SharpZipLib
dotnet add package Aoxe.Snappy
dotnet add package Aoxe.SystemIoCompression
dotnet add package Aoxe.XZ
dotnet add package Aoxe.Zstd
```
Expand Down
8 changes: 4 additions & 4 deletions src/Aoxe.Brotli/Aoxe.Brotli.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageVersion>2024.2.2</PackageVersion>
<Version>2024.2.2</Version>
<TargetFrameworks>netstandard2.0;net6.0;net8.0;net9.0</TargetFrameworks>
<PackageVersion>2024.4.0</PackageVersion>
<Version>2024.4.0</Version>
<Description>Helper and Extensions for BrotliNET.</Description>
<PackageTags>Aoxe;Brotli.NET;Brotli;Compression</PackageTags>
<PackageProjectUrl>https://github.com/AoxeTech</PackageProjectUrl>
Expand All @@ -29,7 +29,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Aoxe.Compressor.Abstractions" Version="2024.2.6" />
<PackageReference Include="Aoxe.Compressor.Abstractions" Version="2024.4.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0;net8.0;net9.0</TargetFrameworks>
<PackageVersion>2024.2.6</PackageVersion>
<Version>2024.2.6</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageVersion>2024.4.2</PackageVersion>
<Version>2024.4.2</Version>
<Description>The abstractions for Aoxe.Compressor</Description>
<PackageTags>Aoxe;Compressor;Abstractions</PackageTags>
<PackageProjectUrl>https://github.com/AoxeTech</PackageProjectUrl>
Expand Down
8 changes: 4 additions & 4 deletions src/Aoxe.LZ4/Aoxe.LZ4.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0</TargetFrameworks>
<PackageVersion>2024.2.2</PackageVersion>
<Version>2024.2.2</Version>
<TargetFrameworks>netstandard2.0;net6.0;net8.0;net9.0</TargetFrameworks>
<PackageVersion>2024.4.0</PackageVersion>
<Version>2024.4.0</Version>
<Description>Helper and Extensions for K4os.Compression.LZ4.</Description>
<PackageTags>Aoxe;K4os.Compression.LZ4;LZ4;Compression</PackageTags>
<PackageProjectUrl>https://github.com/AoxeTech</PackageProjectUrl>
Expand All @@ -30,7 +30,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Aoxe.Compressor.Abstractions" Version="2024.2.6" />
<PackageReference Include="Aoxe.Compressor.Abstractions" Version="2024.4.2" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/Aoxe.LZMA/Aoxe.LZMA.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageVersion>2024.2.2</PackageVersion>
<Version>2024.2.2</Version>
<TargetFrameworks>netstandard2.0;net6.0;net8.0;net9.0</TargetFrameworks>
<PackageVersion>2024.4.0</PackageVersion>
<Version>2024.4.0</Version>
<Description>Helper and Extensions for LZMA-SDK.</Description>
<PackageTags>Aoxe;LZMA-SDK;LZMA;Compression</PackageTags>
<PackageProjectUrl>https://github.com/AoxeTech</PackageProjectUrl>
Expand All @@ -29,7 +29,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Aoxe.Compressor.Abstractions" Version="2024.2.6" />
<PackageReference Include="Aoxe.Compressor.Abstractions" Version="2024.4.2" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/Aoxe.SharpZipLib/Aoxe.SharpZipLib.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6</TargetFrameworks>
<PackageVersion>2024.2.2</PackageVersion>
<Version>2024.2.2</Version>
<TargetFrameworks>netstandard2.0;net6.0;net8.0;net9.0</TargetFrameworks>
<PackageVersion>2024.4.0</PackageVersion>
<Version>2024.4.0</Version>
<Description>Helper and Extensions for SharpZipLib.</Description>
<PackageTags>Aoxe;SharpZipLib;BZip2;GZip;Compression</PackageTags>
<PackageProjectUrl>https://github.com/AoxeTech</PackageProjectUrl>
Expand All @@ -29,7 +29,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="SharpZipLib" Version="1.4.2" />
<PackageReference Include="Aoxe.Compressor.Abstractions" Version="2024.2.6" />
<PackageReference Include="Aoxe.Compressor.Abstractions" Version="2024.4.2" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/Aoxe.Snappy/Aoxe.Snappy.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0</TargetFrameworks>
<PackageVersion>2024.2.2</PackageVersion>
<Version>2024.2.2</Version>
<TargetFrameworks>netstandard2.0;net6.0;net8.0;net9.0</TargetFrameworks>
<PackageVersion>2024.4.0</PackageVersion>
<Version>2024.4.0</Version>
<Description>Helper and Extensions for IronSnappy.</Description>
<PackageTags>Aoxe;IronSnappy;Snappy;Compression</PackageTags>
<PackageProjectUrl>https://github.com/AoxeTech</PackageProjectUrl>
Expand All @@ -29,7 +29,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Aoxe.Compressor.Abstractions" Version="2024.2.6" />
<PackageReference Include="Aoxe.Compressor.Abstractions" Version="2024.4.2" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/Aoxe.SystemIoCompression/Aoxe.SystemIoCompression.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6;net8</TargetFrameworks>
<PackageVersion>2024.2.3</PackageVersion>
<Version>2024.2.3</Version>
<TargetFrameworks>netstandard2.0;net6.0;net8.0;net9.0</TargetFrameworks>
<PackageVersion>2024.4.0</PackageVersion>
<Version>2024.4.0</Version>
<Description>Helper and Extensions for System.IO.Compression.</Description>
<PackageTags>Aoxe;System.IO.Compression;Brotli;Deflate;GZip;Compression</PackageTags>
<PackageProjectUrl>https://github.com/AoxeTech</PackageProjectUrl>
Expand All @@ -28,7 +28,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Aoxe.Compressor.Abstractions" Version="2024.2.6" />
<PackageReference Include="Aoxe.Compressor.Abstractions" Version="2024.4.2" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 14 additions & 0 deletions src/Aoxe.SystemIoCompression/ZLib.Extensions.Bytes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#if NET6_0_OR_GREATER
namespace Aoxe.SystemIoCompression;

public static partial class ZLibExtensions
{
public static byte[] ToZLib(
this byte[] rawBytes,
CompressionLevel compressionLevel = CompressionLevel.Optimal
) => ZLibHelper.Compress(rawBytes, compressionLevel);

public static byte[] UnZLib(this byte[] compressedBytes) =>
ZLibHelper.Decompress(compressedBytes);
}
#endif
30 changes: 30 additions & 0 deletions src/Aoxe.SystemIoCompression/ZLib.Extensions.Stream.Async.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#if NET6_0_OR_GREATER
namespace Aoxe.SystemIoCompression;

public static partial class ZLibExtensions
{
public static ValueTask ToZLibAsync(
this Stream rawStream,
Stream outputStream,
CompressionLevel compressionLevel = CompressionLevel.Optimal,
CancellationToken cancellationToken = default
) => ZLibHelper.CompressAsync(rawStream, outputStream, compressionLevel, cancellationToken);

public static ValueTask UnZLibAsync(
this Stream compressedStream,
Stream outputStream,
CancellationToken cancellationToken = default
) => ZLibHelper.DecompressAsync(compressedStream, outputStream, cancellationToken);

public static ValueTask<MemoryStream> ToZLibAsync(
this Stream rawStream,
CompressionLevel compressionLevel = CompressionLevel.Optimal,
CancellationToken cancellationToken = default
) => ZLibHelper.CompressAsync(rawStream, compressionLevel, cancellationToken);

public static ValueTask<MemoryStream> UnZLibAsync(
this Stream compressedStream,
CancellationToken cancellationToken = default
) => ZLibHelper.DecompressAsync(compressedStream, cancellationToken);
}
#endif
23 changes: 23 additions & 0 deletions src/Aoxe.SystemIoCompression/ZLib.Extensions.Stream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if NET6_0_OR_GREATER
namespace Aoxe.SystemIoCompression;

public static partial class ZLibExtensions
{
public static void ToZLib(
this Stream rawStream,
Stream outputStream,
CompressionLevel compressionLevel = CompressionLevel.Optimal
) => ZLibHelper.Compress(rawStream, outputStream, compressionLevel);

public static void UnZLib(this Stream compressedStream, Stream outputStream) =>
ZLibHelper.Decompress(compressedStream, outputStream);

public static MemoryStream ToZLib(
this Stream rawStream,
CompressionLevel compressionLevel = CompressionLevel.Optimal
) => ZLibHelper.Compress(rawStream, compressionLevel);

public static MemoryStream UnZLib(this Stream compressedStream) =>
ZLibHelper.Decompress(compressedStream);
}
#endif
15 changes: 15 additions & 0 deletions src/Aoxe.SystemIoCompression/ZLib.Extensions.String.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#if NET6_0_OR_GREATER
namespace Aoxe.SystemIoCompression;

public static partial class ZLibExtensions
{
public static byte[] ToZLib(
this string str,
Encoding? encoding = null,
CompressionLevel compressionLevel = CompressionLevel.Optimal
) => ZLibHelper.Compress(str, encoding, compressionLevel);

public static string UnZLibToString(this byte[] compressedBytes, Encoding? encoding = null) =>
ZLibHelper.DecompressToString(compressedBytes, encoding);
}
#endif
31 changes: 31 additions & 0 deletions src/Aoxe.SystemIoCompression/ZLib.Helper.Bytes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#if NET6_0_OR_GREATER
namespace Aoxe.SystemIoCompression;

public static partial class ZLibHelper
{
public static byte[] Compress(
byte[] rawBytes,
CompressionLevel compressionLevel = CompressionLevel.Optimal
)
{
var outputStream = new MemoryStream();
using (var zLibOutputStream = new ZLibStream(outputStream, compressionLevel, true))
rawBytes.WriteTo(zLibOutputStream);
return outputStream.ToArray();
}

public static byte[] Decompress(byte[] compressedBytes)
{
var outputStream = new MemoryStream();
using (
var zLibInputStream = new ZLibStream(
compressedBytes.ToMemoryStream(),
CompressionMode.Decompress,
true
)
)
zLibInputStream.CopyTo(outputStream);
return outputStream.ToArray();
}
}
#endif
Loading

0 comments on commit a34bfbf

Please sign in to comment.