-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add span-based Deflate, ZLib and GZip encoder/decoder APIs #123145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e402958
95ac930
88acc57
6f1ab80
8926759
bb2d89c
a21a800
4b87dcd
aabc3a6
cfb3d7e
f031eed
1d18eec
0cf5b04
01fba5a
03fbcbc
665ae10
ee0a437
238aa58
aeebd78
ab9ee4a
cdb1cb4
46c5a8f
e35f082
fb4b1c8
f82ddc4
89ba215
6f05f53
c6384e4
f3dd1c4
91b2890
e52c80e
802d228
8177c6a
46cf8b4
5c226ac
0c5eb13
38202d3
2b5ad84
5bf24f0
e56c631
382b7c2
ba72b26
82038d8
ae7c2a9
a1658e7
d294740
913b797
c4948b8
fdfad6b
3486f09
c5d2412
15f0fd6
d6d47bf
b1fa69c
0ce58db
0ffe1ee
c7fca14
8a31cc5
f2a26ab
93f42ce
2ab5044
9cb4ff5
e5f6990
f2ed2e5
b8cd755
dbf1903
b963848
254cf71
23aab9a
6274e44
274ad66
da347ae
2a0b947
fd5206f
3e2e8bf
4aaaace
4f3946a
cd7cef9
e06c1d0
e66a00b
89510f8
8c07952
7fd0591
b7b29ac
a75b24f
b795f31
f4b24c2
94c95dc
9b39f4d
c415ebd
ba6f28a
9522265
a425e1f
2d6ac86
f36746f
bb27a9c
b976f98
627cb05
125cc24
46c3a18
6e85384
0058b79
13b2aaa
87ed0cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,27 @@ public enum CompressionMode | |
| Decompress = 0, | ||
| Compress = 1, | ||
| } | ||
| public sealed partial class DeflateDecoder : System.IDisposable | ||
| { | ||
| public DeflateDecoder() { } | ||
| public System.Buffers.OperationStatus Decompress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesConsumed, out int bytesWritten) { throw null; } | ||
| public void Dispose() { } | ||
| public static bool TryDecompress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten) { throw null; } | ||
| } | ||
| public sealed partial class DeflateEncoder : System.IDisposable | ||
| { | ||
| public DeflateEncoder() { } | ||
| public DeflateEncoder(int quality) { } | ||
| public DeflateEncoder(int quality, int windowLog) { } | ||
| public DeflateEncoder(System.IO.Compression.ZLibCompressionOptions options) { } | ||
| public System.Buffers.OperationStatus Compress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesConsumed, out int bytesWritten, bool isFinalBlock) { throw null; } | ||
| public void Dispose() { } | ||
| public System.Buffers.OperationStatus Flush(System.Span<byte> destination, out int bytesWritten) { throw null; } | ||
| public static long GetMaxCompressedLength(long inputLength) { throw null; } | ||
|
iremyux marked this conversation as resolved.
|
||
| public static bool TryCompress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten) { throw null; } | ||
| public static bool TryCompress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten, int quality) { throw null; } | ||
| public static bool TryCompress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten, int quality, int windowLog) { throw null; } | ||
| } | ||
| public partial class DeflateStream : System.IO.Stream | ||
| { | ||
| public DeflateStream(System.IO.Stream stream, System.IO.Compression.CompressionLevel compressionLevel) { } | ||
|
|
@@ -54,6 +75,27 @@ public override void Write(System.ReadOnlySpan<byte> buffer) { } | |
| public override System.Threading.Tasks.ValueTask WriteAsync(System.ReadOnlyMemory<byte> buffer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } | ||
| public override void WriteByte(byte value) { } | ||
| } | ||
| public sealed partial class GZipDecoder : System.IDisposable | ||
| { | ||
| public GZipDecoder() { } | ||
| public System.Buffers.OperationStatus Decompress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesConsumed, out int bytesWritten) { throw null; } | ||
| public void Dispose() { } | ||
| public static bool TryDecompress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten) { throw null; } | ||
| } | ||
| public sealed partial class GZipEncoder : System.IDisposable | ||
| { | ||
| public GZipEncoder() { } | ||
| public GZipEncoder(int quality) { } | ||
| public GZipEncoder(int quality, int windowLog) { } | ||
| public GZipEncoder(System.IO.Compression.ZLibCompressionOptions options) { } | ||
| public System.Buffers.OperationStatus Compress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesConsumed, out int bytesWritten, bool isFinalBlock) { throw null; } | ||
| public void Dispose() { } | ||
| public System.Buffers.OperationStatus Flush(System.Span<byte> destination, out int bytesWritten) { throw null; } | ||
| public static long GetMaxCompressedLength(long inputLength) { throw null; } | ||
| public static bool TryCompress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten) { throw null; } | ||
| public static bool TryCompress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten, int quality) { throw null; } | ||
| public static bool TryCompress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten, int quality, int windowLog) { throw null; } | ||
| } | ||
| public partial class GZipStream : System.IO.Stream | ||
| { | ||
| public GZipStream(System.IO.Stream stream, System.IO.Compression.CompressionLevel compressionLevel) { } | ||
|
|
@@ -146,9 +188,13 @@ public enum ZipCompressionMethod | |
| } | ||
| public sealed partial class ZLibCompressionOptions | ||
| { | ||
| public static int DefaultWindowLog { get { throw null; } } | ||
| public static int MaxWindowLog { get { throw null; } } | ||
| public static int MinWindowLog { get { throw null; } } | ||
| public ZLibCompressionOptions() { } | ||
| public int CompressionLevel { get { throw null; } set { } } | ||
| public System.IO.Compression.ZLibCompressionStrategy CompressionStrategy { get { throw null; } set { } } | ||
| public int WindowLog { get { throw null; } set { } } | ||
| } | ||
| public enum ZLibCompressionStrategy | ||
| { | ||
|
|
@@ -158,6 +204,27 @@ public enum ZLibCompressionStrategy | |
| RunLengthEncoding = 3, | ||
| Fixed = 4, | ||
| } | ||
| public sealed partial class ZLibDecoder : System.IDisposable | ||
| { | ||
| public ZLibDecoder() { } | ||
| public System.Buffers.OperationStatus Decompress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesConsumed, out int bytesWritten) { throw null; } | ||
| public void Dispose() { } | ||
| public static bool TryDecompress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten) { throw null; } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No bytes consumed info?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does additional data cause false or is it silently ignored? |
||
| } | ||
| public sealed partial class ZLibEncoder : System.IDisposable | ||
| { | ||
| public ZLibEncoder() { } | ||
| public ZLibEncoder(int quality) { } | ||
| public ZLibEncoder(int quality, int windowLog) { } | ||
| public ZLibEncoder(System.IO.Compression.ZLibCompressionOptions options) { } | ||
| public System.Buffers.OperationStatus Compress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesConsumed, out int bytesWritten, bool isFinalBlock) { throw null; } | ||
| public void Dispose() { } | ||
| public System.Buffers.OperationStatus Flush(System.Span<byte> destination, out int bytesWritten) { throw null; } | ||
| public static long GetMaxCompressedLength(long inputLength) { throw null; } | ||
| public static bool TryCompress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten) { throw null; } | ||
| public static bool TryCompress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten, int quality) { throw null; } | ||
| public static bool TryCompress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten, int quality, int windowLog) { throw null; } | ||
| } | ||
| public sealed partial class ZLibStream : System.IO.Stream | ||
| { | ||
| public ZLibStream(System.IO.Stream stream, System.IO.Compression.CompressionLevel compressionLevel) { } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace System.IO.Compression | ||
| { | ||
| /// <summary> | ||
| /// Specifies the compression format for zlib-based encoders. | ||
| /// </summary> | ||
| internal enum CompressionFormat | ||
| { | ||
| /// <summary>Raw deflate format (no header/trailer).</summary> | ||
| Deflate, | ||
| /// <summary>ZLib format (zlib header/trailer).</summary> | ||
| ZLib, | ||
| /// <summary>GZip format (gzip header/trailer).</summary> | ||
| GZip | ||
| } | ||
|
|
||
| internal static class CompressionFormatHelper | ||
| { | ||
| /// <summary> | ||
| /// Resolves a windowLog value (8-15) to the windowBits parameter expected by zlib, | ||
| /// based on the compression format. A windowLog of -1 is resolved to the default (15). | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// zlib-ng rejects windowBits 8 for raw deflate and gzip; classic zlib silently upgrades to 9. | ||
| /// This method clamps to 9 for Deflate and GZip formats to match classic zlib behavior. | ||
| /// </remarks> | ||
| internal static int ResolveWindowBits(int windowLog, CompressionFormat format) | ||
| { | ||
| if (windowLog == -1) | ||
| { | ||
| windowLog = ZLibNative.DefaultWindowLog; | ||
| } | ||
|
|
||
| if (format != CompressionFormat.ZLib) | ||
| { | ||
| windowLog = Math.Max(windowLog, 9); | ||
| } | ||
|
|
||
| return format switch | ||
| { | ||
| CompressionFormat.Deflate => -windowLog, | ||
| CompressionFormat.ZLib => windowLog, | ||
| CompressionFormat.GZip => windowLog + 16, | ||
| _ => throw new ArgumentOutOfRangeException(nameof(format)) | ||
| }; | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.