-
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
24 changed files
with
423 additions
and
7 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 was deleted.
Oops, something went wrong.
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,5 @@ | ||
// Global using directives | ||
|
||
global using System.Text; | ||
global using Zaabee.Compressor.Abstractions; | ||
global using Zaabee.Extensions; |
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,12 @@ | ||
namespace Zaabee.Snappy; | ||
|
||
public static partial class SnappyExtensions | ||
{ | ||
public static byte[] ToSnappy( | ||
this byte[] rawBytes) => | ||
SnappyHelper.Compress(rawBytes); | ||
|
||
public static byte[] UnSnappy( | ||
this byte[] compressedBytes) => | ||
SnappyHelper.Decompress(compressedBytes); | ||
} |
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,26 @@ | ||
namespace Zaabee.Snappy; | ||
|
||
public static partial class SnappyExtensions | ||
{ | ||
public static async Task ToSnappyAsync( | ||
this Stream rawStream, | ||
Stream outputStream, | ||
CancellationToken cancellationToken = default) => | ||
await SnappyHelper.CompressAsync(rawStream, outputStream, cancellationToken); | ||
|
||
public static async Task UnSnappyAsync( | ||
this Stream compressedStream, | ||
Stream outputStream, | ||
CancellationToken cancellationToken = default) => | ||
await SnappyHelper.DecompressAsync(compressedStream, outputStream, cancellationToken); | ||
|
||
public static async Task<MemoryStream> ToSnappyAsync( | ||
this Stream rawStream, | ||
CancellationToken cancellationToken = default) => | ||
await SnappyHelper.CompressAsync(rawStream, cancellationToken); | ||
|
||
public static async Task<MemoryStream> UnSnappyAsync( | ||
this Stream compressedStream, | ||
CancellationToken cancellationToken = default) => | ||
await SnappyHelper.DecompressAsync(compressedStream, cancellationToken); | ||
} |
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,22 @@ | ||
namespace Zaabee.Snappy; | ||
|
||
public static partial class SnappyExtensions | ||
{ | ||
public static void ToSnappy( | ||
this Stream rawStream, | ||
Stream outputStream) => | ||
SnappyHelper.Compress(rawStream, outputStream); | ||
|
||
public static void UnSnappy( | ||
this Stream compressedStream, | ||
Stream outputStream) => | ||
SnappyHelper.Decompress(compressedStream, outputStream); | ||
|
||
public static MemoryStream ToSnappy( | ||
this Stream rawStream) => | ||
SnappyHelper.Compress(rawStream); | ||
|
||
public static MemoryStream UnSnappy( | ||
this Stream compressedStream) => | ||
SnappyHelper.Decompress(compressedStream); | ||
} |
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 @@ | ||
namespace Zaabee.Snappy; | ||
|
||
public static partial class SnappyExtensions | ||
{ | ||
public static byte[] ToSnappy( | ||
this string str, | ||
Encoding? encoding = null) => | ||
SnappyHelper.Compress(str, encoding); | ||
|
||
public static string UnSnappyToString( | ||
this byte[] compressedBytes, | ||
Encoding? encoding = null) => | ||
SnappyHelper.DecompressToString(compressedBytes, encoding); | ||
} |
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,12 @@ | ||
namespace Zaabee.Snappy; | ||
|
||
public static partial class SnappyHelper | ||
{ | ||
public static byte[] Compress( | ||
byte[] rawBytes) => | ||
IronSnappy.Snappy.Encode(rawBytes); | ||
|
||
public static byte[] Decompress( | ||
byte[] compressedBytes) => | ||
IronSnappy.Snappy.Decode(compressedBytes); | ||
} |
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,56 @@ | ||
namespace Zaabee.Snappy; | ||
|
||
public static partial class SnappyHelper | ||
{ | ||
public static async Task<MemoryStream> CompressAsync( | ||
Stream inputStream, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
var rawBytes = await inputStream.ReadToEndAsync(cancellationToken); | ||
var compressedBytes = IronSnappy.Snappy.Encode(rawBytes); | ||
inputStream.TrySeek(0, SeekOrigin.Begin); | ||
return new MemoryStream(compressedBytes); | ||
} | ||
|
||
public static async Task<MemoryStream> DecompressAsync( | ||
Stream inputStream, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
var compressedBytes = await inputStream.ReadToEndAsync(cancellationToken); | ||
var rawBytes = IronSnappy.Snappy.Decode(compressedBytes); | ||
inputStream.TrySeek(0, SeekOrigin.Begin); | ||
return new MemoryStream(rawBytes); | ||
} | ||
|
||
public static async Task CompressAsync( | ||
Stream inputStream, | ||
Stream outputStream, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
var rawBytes = await inputStream.ReadToEndAsync(cancellationToken); | ||
var compressedBytes = IronSnappy.Snappy.Encode(rawBytes); | ||
#if NETSTANDARD2_0 | ||
await outputStream.WriteAsync(compressedBytes, 0, compressedBytes.Length, cancellationToken); | ||
#else | ||
await outputStream.WriteAsync(compressedBytes, cancellationToken); | ||
#endif | ||
inputStream.TrySeek(0, SeekOrigin.Begin); | ||
outputStream.TrySeek(0, SeekOrigin.Begin); | ||
} | ||
|
||
public static async Task DecompressAsync( | ||
Stream inputStream, | ||
Stream outputStream, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
var compressedBytes = await inputStream.ReadToEndAsync(cancellationToken); | ||
var rawBytes = IronSnappy.Snappy.Decode(compressedBytes); | ||
#if NETSTANDARD2_0 | ||
await outputStream.WriteAsync(rawBytes, 0, rawBytes.Length, cancellationToken); | ||
#else | ||
await outputStream.WriteAsync(rawBytes, cancellationToken); | ||
#endif | ||
inputStream.TrySeek(0, SeekOrigin.Begin); | ||
outputStream.TrySeek(0, SeekOrigin.Begin); | ||
} | ||
} |
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,44 @@ | ||
namespace Zaabee.Snappy; | ||
|
||
public static partial class SnappyHelper | ||
{ | ||
public static MemoryStream Compress( | ||
Stream inputStream) | ||
{ | ||
var rawBytes = inputStream.ReadToEnd(); | ||
var compressedBytes = IronSnappy.Snappy.Encode(rawBytes); | ||
inputStream.TrySeek(0, SeekOrigin.Begin); | ||
return new MemoryStream(compressedBytes); | ||
} | ||
|
||
public static MemoryStream Decompress( | ||
Stream inputStream) | ||
{ | ||
var compressedBytes = inputStream.ReadToEnd(); | ||
var rawBytes = IronSnappy.Snappy.Decode(compressedBytes); | ||
inputStream.TrySeek(0, SeekOrigin.Begin); | ||
return new MemoryStream(rawBytes); | ||
} | ||
|
||
public static void Compress( | ||
Stream inputStream, | ||
Stream outputStream) | ||
{ | ||
var rawBytes = inputStream.ReadToEnd(); | ||
var compressedBytes = IronSnappy.Snappy.Encode(rawBytes); | ||
outputStream.Write(compressedBytes, 0, compressedBytes.Length); | ||
inputStream.TrySeek(0, SeekOrigin.Begin); | ||
outputStream.TrySeek(0, SeekOrigin.Begin); | ||
} | ||
|
||
public static void Decompress( | ||
Stream inputStream, | ||
Stream outputStream) | ||
{ | ||
var compressedBytes = inputStream.ReadToEnd(); | ||
var rawBytes = IronSnappy.Snappy.Decode(compressedBytes); | ||
outputStream.Write(rawBytes, 0, rawBytes.Length); | ||
inputStream.TrySeek(0, SeekOrigin.Begin); | ||
outputStream.TrySeek(0, SeekOrigin.Begin); | ||
} | ||
} |
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 @@ | ||
namespace Zaabee.Snappy; | ||
|
||
public static partial class SnappyHelper | ||
{ | ||
public static byte[] Compress( | ||
string str, | ||
Encoding? encoding = null) => | ||
Compress(str.GetBytes(encoding ?? Consts.DefaultEncoding)); | ||
|
||
public static string DecompressToString( | ||
byte[] compressedBytes, | ||
Encoding? encoding = null) => | ||
Decompress(compressedBytes) | ||
.GetString(encoding ?? Consts.DefaultEncoding); | ||
} |
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,48 @@ | ||
namespace Zaabee.Snappy; | ||
|
||
public class SnappyCompressor : ICompressor | ||
{ | ||
public async Task<MemoryStream> CompressAsync( | ||
Stream rawStream, | ||
CancellationToken cancellationToken = default) => | ||
await rawStream.ToSnappyAsync(cancellationToken); | ||
|
||
public async Task<MemoryStream> DecompressAsync( | ||
Stream compressedStream, | ||
CancellationToken cancellationToken = default) => | ||
await compressedStream.UnSnappyAsync(cancellationToken); | ||
|
||
public async Task CompressAsync( | ||
Stream inputStream, | ||
Stream outputStream, | ||
CancellationToken cancellationToken = default) => | ||
await inputStream.ToSnappyAsync(outputStream, cancellationToken); | ||
|
||
public async Task DecompressAsync( | ||
Stream inputStream, | ||
Stream outputStream, | ||
CancellationToken cancellationToken = default) => | ||
await inputStream.UnSnappyAsync(outputStream, cancellationToken); | ||
|
||
public byte[] Compress(byte[] rawBytes) => | ||
rawBytes.ToSnappy(); | ||
|
||
public byte[] Decompress(byte[] compressedBytes) => | ||
compressedBytes.UnSnappy(); | ||
|
||
public MemoryStream Compress(Stream rawStream) => | ||
rawStream.ToSnappy(); | ||
|
||
public MemoryStream Decompress(Stream compressedStream) => | ||
compressedStream.UnSnappy(); | ||
|
||
public void Compress( | ||
Stream inputStream, | ||
Stream outputStream) => | ||
inputStream.ToSnappy(outputStream); | ||
|
||
public void Decompress( | ||
Stream inputStream, | ||
Stream outputStream) => | ||
inputStream.UnSnappy(outputStream); | ||
} |
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,13 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<TargetFrameworks>netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<PackageVersion>2023.8.0</PackageVersion> | ||
<Version>2023.8.0</Version> | ||
<Authors>Mutuduxf</Authors> | ||
<Company>Mutuduxf</Company> | ||
<PackageTags>Zaabee;IronSnappy;Snappy;Compression</PackageTags> | ||
<Description>Helper and Extensions for IronSnappy.</Description> | ||
<PackageProjectUrl>https://github.com/PicoHex/Zaabee.Compression</PackageProjectUrl> | ||
<LicenseExpression>MIT</LicenseExpression> | ||
<LangVersion>latest</LangVersion> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="IronSnappy" Version="1.3.1" /> | ||
<PackageReference Include="IronSnappy" Version="1.3.1" /> | ||
<PackageReference Include="Zaabee.Compressor.Abstractions" Version="2023.12.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
Oops, something went wrong.