-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
486 additions
and
65 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
6 changes: 3 additions & 3 deletions
6
src/Aoxe.Compressor.Abstractions/Aoxe.Compressor.Abstractions.csproj
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
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,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
30
src/Aoxe.SystemIoCompression/ZLib.Extensions.Stream.Async.cs
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,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 |
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,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 |
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,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 |
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,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 |
Oops, something went wrong.