Skip to content

Commit

Permalink
Format codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mutuduxf committed Nov 26, 2023
1 parent 10f936c commit 5d91bce
Show file tree
Hide file tree
Showing 120 changed files with 593 additions and 716 deletions.
2 changes: 1 addition & 1 deletion perf/Benchmark/Benchmarks/CompressToBytes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ public class CompressToBytes

[Benchmark]
public void ZstdToBytes() => ZstdHelper.Compress(Consts.RawBytes);
}
}
2 changes: 1 addition & 1 deletion perf/Benchmark/Benchmarks/CompressToStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ public class CompressToStream

[Benchmark]
public void ZstdToStream() => ZstdHelper.Compress(Consts.RawStream, new MemoryStream());
}
}
2 changes: 1 addition & 1 deletion perf/Benchmark/Benchmarks/DecompressFromBytes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ public class DecompressFromBytes

[Benchmark]
public void ZstdFromBytes() => ZstdHelper.Decompress(ZstdCompressBytes);
}
}
13 changes: 9 additions & 4 deletions perf/Benchmark/Benchmarks/DecompressFromStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@
[MinColumn, MaxColumn, MeanColumn, MedianColumn]
public class DecompressFromStream
{
private static readonly MemoryStream BrotliCompressStream = BrotliHelper.Compress(Consts.RawStream);
private static readonly MemoryStream BzipCompressStream = Bzip2Helper.Compress(Consts.RawStream);
private static readonly MemoryStream BrotliCompressStream = BrotliHelper.Compress(
Consts.RawStream
);
private static readonly MemoryStream BzipCompressStream = Bzip2Helper.Compress(
Consts.RawStream
);
private static readonly MemoryStream GzipCompressStream = GzipHelper.Compress(Consts.RawStream);
private static readonly MemoryStream Lz4CompressStream = Lz4Helper.Compress(Consts.RawStream);
private static readonly MemoryStream LzmaCompressStream = LzmaHelper.Compress(Consts.RawStream);
private static readonly MemoryStream XzCompressStream = XzHelper.Compress(Consts.RawStream);
private static readonly MemoryStream ZstdCompressStream = ZstdHelper.Compress(Consts.RawStream);

[Benchmark]
public void BrotliFromStream() => BrotliHelper.Decompress(BrotliCompressStream, new MemoryStream());
public void BrotliFromStream() =>
BrotliHelper.Decompress(BrotliCompressStream, new MemoryStream());

[Benchmark]
public void Bzip2FromStream() => Bzip2Helper.Decompress(BzipCompressStream, new MemoryStream());
Expand All @@ -36,4 +41,4 @@ public class DecompressFromStream

[Benchmark]
public void ZstdFromStream() => ZstdHelper.Decompress(ZstdCompressStream, new MemoryStream());
}
}
2 changes: 1 addition & 1 deletion perf/Benchmark/Consts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ public static class Consts
{
public static readonly byte[] RawBytes = new byte[1024 * 10];
public static readonly MemoryStream RawStream = new(RawBytes);
}
}
2 changes: 1 addition & 1 deletion perf/Benchmark/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
global using Zaabee.SharpZipLib;
global using Zaabee.Snappy;
global using Zaabee.XZ;
global using Zaabee.Zstd;
global using Zaabee.Zstd;
2 changes: 1 addition & 1 deletion perf/Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
{
Console.WriteLine(summary.ResultsDirectoryPath);
Console.WriteLine(string.Join("\r\n", summary.Reports));
}
}
6 changes: 3 additions & 3 deletions src/Zaabee.Brotli/Brotli.Extensions.Bytes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ public static partial class BrotliExtensions
public static byte[] ToBrotli(
this byte[] rawBytes,
uint quality = BrotliHelper.Quality,
uint window = BrotliHelper.Window) =>
BrotliHelper.Compress(rawBytes, quality, window);
uint window = BrotliHelper.Window
) => BrotliHelper.Compress(rawBytes, quality, window);

public static byte[] UnBrotli(this byte[] compressedBytes) =>
BrotliHelper.Decompress(compressedBytes);
}
}
18 changes: 9 additions & 9 deletions src/Zaabee.Brotli/Brotli.Extensions.Stream.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ public static ValueTask ToBrotliAsync(
Stream outputStream,
uint quality = BrotliHelper.Quality,
uint window = BrotliHelper.Window,
CancellationToken cancellationToken = default) =>
BrotliHelper.CompressAsync(rawStream, outputStream, quality, window, cancellationToken);
CancellationToken cancellationToken = default
) => BrotliHelper.CompressAsync(rawStream, outputStream, quality, window, cancellationToken);

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

public static ValueTask<MemoryStream> ToBrotliAsync(
this Stream rawStream,
uint quality = BrotliHelper.Quality,
uint window = BrotliHelper.Window,
CancellationToken cancellationToken = default) =>
BrotliHelper.CompressAsync(rawStream, quality, window, cancellationToken);
CancellationToken cancellationToken = default
) => BrotliHelper.CompressAsync(rawStream, quality, window, cancellationToken);

public static ValueTask<MemoryStream> UnBrotliAsync(
this Stream compressedStream,
CancellationToken cancellationToken = default) =>
BrotliHelper.DecompressAsync(compressedStream, cancellationToken);
}
CancellationToken cancellationToken = default
) => BrotliHelper.DecompressAsync(compressedStream, cancellationToken);
}
14 changes: 6 additions & 8 deletions src/Zaabee.Brotli/Brotli.Extensions.Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@ public static void ToBrotli(
this Stream rawStream,
Stream outputStream,
uint quality = BrotliHelper.Quality,
uint window = BrotliHelper.Window) =>
BrotliHelper.Compress(rawStream, outputStream, quality, window);
uint window = BrotliHelper.Window
) => BrotliHelper.Compress(rawStream, outputStream, quality, window);

public static void UnBrotli(
this Stream compressedStream,
Stream outputStream) =>
public static void UnBrotli(this Stream compressedStream, Stream outputStream) =>
BrotliHelper.Decompress(compressedStream, outputStream);

public static MemoryStream ToBrotli(
this Stream rawStream,
uint quality = BrotliHelper.Quality,
uint window = BrotliHelper.Window) =>
BrotliHelper.Compress(rawStream, quality, window);
uint window = BrotliHelper.Window
) => BrotliHelper.Compress(rawStream, quality, window);

public static MemoryStream UnBrotli(this Stream compressedStream) =>
BrotliHelper.Decompress(compressedStream);
}
}
10 changes: 4 additions & 6 deletions src/Zaabee.Brotli/Brotli.Extensions.String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ public static byte[] ToBrotli(
this string str,
uint quality = BrotliHelper.Quality,
uint window = BrotliHelper.Window,
Encoding? encoding = null) =>
BrotliHelper.Compress(str, quality, window, encoding);
Encoding? encoding = null
) => BrotliHelper.Compress(str, quality, window, encoding);

public static string UnBrotliToString(
this byte[] compressedBytes,
Encoding? encoding = null) =>
public static string UnBrotliToString(this byte[] compressedBytes, Encoding? encoding = null) =>
BrotliHelper.DecompressToString(compressedBytes);
}
}
7 changes: 2 additions & 5 deletions src/Zaabee.Brotli/Brotli.Helper.Bytes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

public static partial class BrotliHelper
{
public static byte[] Compress(
byte[] rawBytes,
uint quality = Quality,
uint window = Window) =>
public static byte[] Compress(byte[] rawBytes, uint quality = Quality, uint window = Window) =>
rawBytes.CompressToBrotli(quality, window);

public static byte[] Decompress(byte[] compressedBytes) =>
compressedBytes.DecompressFromBrotli();
}
}
22 changes: 15 additions & 7 deletions src/Zaabee.Brotli/Brotli.Helper.Stream.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ public static async ValueTask<MemoryStream> CompressAsync(
Stream inputStream,
uint quality = Quality,
uint window = Window,
CancellationToken cancellationToken = default)
CancellationToken cancellationToken = default
)
{
var outputStream = new MemoryStream();
await CompressAsync(inputStream, outputStream, quality, window, cancellationToken);
Expand All @@ -15,7 +16,8 @@ public static async ValueTask<MemoryStream> CompressAsync(

public static async ValueTask<MemoryStream> DecompressAsync(
Stream inputStream,
CancellationToken cancellationToken = default)
CancellationToken cancellationToken = default
)
{
var outputStream = new MemoryStream();
await DecompressAsync(inputStream, outputStream, cancellationToken);
Expand All @@ -27,7 +29,8 @@ public static async ValueTask CompressAsync(
Stream outputStream,
uint quality = Quality,
uint window = Window,
CancellationToken cancellationToken = default)
CancellationToken cancellationToken = default
)
{
#if NETSTANDARD2_0
using (var brotliStream = new BrotliStream(outputStream, CompressionMode.Compress, true))
Expand All @@ -36,7 +39,9 @@ public static async ValueTask CompressAsync(
brotliStream.SetWindow(window);
await inputStream.CopyToAsync(brotliStream);
#else
await using (var brotliStream = new BrotliStream(outputStream, CompressionMode.Compress, true))
await using (
var brotliStream = new BrotliStream(outputStream, CompressionMode.Compress, true)
)
{
brotliStream.SetQuality(quality);
brotliStream.SetWindow(window);
Expand All @@ -50,16 +55,19 @@ public static async ValueTask CompressAsync(
public static async ValueTask DecompressAsync(
Stream inputStream,
Stream outputStream,
CancellationToken cancellationToken = default)
CancellationToken cancellationToken = default
)
{
#if NETSTANDARD2_0
using (var brotliStream = new BrotliStream(inputStream, CompressionMode.Decompress, true))
await brotliStream.CopyToAsync(outputStream);
#else
await using (var brotliStream = new BrotliStream(inputStream, CompressionMode.Decompress, true))
await using (
var brotliStream = new BrotliStream(inputStream, CompressionMode.Decompress, true)
)
await brotliStream.CopyToAsync(outputStream, cancellationToken);
#endif
inputStream.TrySeek(0, SeekOrigin.Begin);
outputStream.TrySeek(0, SeekOrigin.Begin);
}
}
}
15 changes: 7 additions & 8 deletions src/Zaabee.Brotli/Brotli.Helper.Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ public static partial class BrotliHelper
public static MemoryStream Compress(
Stream inputStream,
uint quality = Quality,
uint window = Window)
uint window = Window
)
{
var outputStream = new MemoryStream();
Compress(inputStream, outputStream, quality, window);
return outputStream;
}

public static MemoryStream Decompress(
Stream inputStream)
public static MemoryStream Decompress(Stream inputStream)
{
var outputStream = new MemoryStream();
Decompress(inputStream, outputStream);
Expand All @@ -24,7 +24,8 @@ public static void Compress(
Stream inputStream,
Stream outputStream,
uint quality = Quality,
uint window = Window)
uint window = Window
)
{
using (var brotliStream = new BrotliStream(outputStream, CompressionMode.Compress, true))
{
Expand All @@ -36,13 +37,11 @@ public static void Compress(
outputStream.TrySeek(0, SeekOrigin.Begin);
}

public static void Decompress(
Stream inputStream,
Stream outputStream)
public static void Decompress(Stream inputStream, Stream outputStream)
{
using (var brotliStream = new BrotliStream(inputStream, CompressionMode.Decompress, true))
brotliStream.CopyTo(outputStream);
inputStream.TrySeek(0, SeekOrigin.Begin);
outputStream.TrySeek(0, SeekOrigin.Begin);
}
}
}
13 changes: 5 additions & 8 deletions src/Zaabee.Brotli/Brotli.Helper.String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ public static byte[] Compress(
string str,
uint quality = Quality,
uint window = Window,
Encoding? encoding = null) =>
Compress(str.GetBytes(encoding ?? Consts.DefaultEncoding), quality, window);
Encoding? encoding = null
) => Compress(str.GetBytes(encoding ?? Consts.DefaultEncoding), quality, window);

public static string DecompressToString(
byte[] compressedBytes,
Encoding? encoding = null) =>
Decompress(compressedBytes)
.GetString(encoding ?? Consts.DefaultEncoding);
}
public static string DecompressToString(byte[] compressedBytes, Encoding? encoding = null) =>
Decompress(compressedBytes).GetString(encoding ?? Consts.DefaultEncoding);
}
2 changes: 1 addition & 1 deletion src/Zaabee.Brotli/Brotli.Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ public static partial class BrotliHelper
{
internal const uint Quality = 5;
internal const uint Window = 22;
}
}
42 changes: 16 additions & 26 deletions src/Zaabee.Brotli/BrotliCompressor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,45 @@ public sealed class BrotliCompressor : ICompressor
private readonly uint _quality;
private readonly uint _window;

public BrotliCompressor(
uint quality = BrotliHelper.Quality,
uint window = BrotliHelper.Window)
public BrotliCompressor(uint quality = BrotliHelper.Quality, uint window = BrotliHelper.Window)
{
_quality = quality;
_window = window;
}

public ValueTask<MemoryStream> CompressAsync(
Stream rawStream,
CancellationToken cancellationToken = default) =>
rawStream.ToBrotliAsync(_quality, _window, cancellationToken);
CancellationToken cancellationToken = default
) => rawStream.ToBrotliAsync(_quality, _window, cancellationToken);

public ValueTask<MemoryStream> DecompressAsync(
Stream compressedStream,
CancellationToken cancellationToken = default) =>
compressedStream.UnBrotliAsync(cancellationToken);
CancellationToken cancellationToken = default
) => compressedStream.UnBrotliAsync(cancellationToken);

public ValueTask CompressAsync(
Stream inputStream,
Stream outputStream,
CancellationToken cancellationToken = default) =>
inputStream.ToBrotliAsync(outputStream, _quality, _window, cancellationToken);
CancellationToken cancellationToken = default
) => inputStream.ToBrotliAsync(outputStream, _quality, _window, cancellationToken);

public ValueTask DecompressAsync(
Stream inputStream,
Stream outputStream,
CancellationToken cancellationToken = default) =>
inputStream.UnBrotliAsync(outputStream, cancellationToken);
CancellationToken cancellationToken = default
) => inputStream.UnBrotliAsync(outputStream, cancellationToken);

public byte[] Compress(byte[] rawBytes) =>
rawBytes.ToBrotli(_quality, _window);
public byte[] Compress(byte[] rawBytes) => rawBytes.ToBrotli(_quality, _window);

public byte[] Decompress(byte[] compressedBytes) =>
compressedBytes.UnBrotli();
public byte[] Decompress(byte[] compressedBytes) => compressedBytes.UnBrotli();

public MemoryStream Compress(Stream rawStream) =>
rawStream.ToBrotli(_quality, _window);
public MemoryStream Compress(Stream rawStream) => rawStream.ToBrotli(_quality, _window);

public MemoryStream Decompress(Stream compressedStream) =>
compressedStream.UnBrotli();
public MemoryStream Decompress(Stream compressedStream) => compressedStream.UnBrotli();

public void Compress(
Stream inputStream,
Stream outputStream) =>
public void Compress(Stream inputStream, Stream outputStream) =>
inputStream.ToBrotli(outputStream, _quality, _window);

public void Decompress(
Stream inputStream,
Stream outputStream) =>
public void Decompress(Stream inputStream, Stream outputStream) =>
inputStream.UnBrotli(outputStream);
}
}
Loading

0 comments on commit 5d91bce

Please sign in to comment.