-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[WIP] 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
base: main
Are you sure you want to change the base?
Conversation
src/libraries/System.IO.Compression/src/System/IO/Compression/ZlibEncoderOptions.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/ZlibEncoderOptions.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/ZlibEncoderOptions.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/ZlibEncoder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/ref/System.IO.Compression.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/ZlibDecoder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/ZlibEncoder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/ZlibEncoder.cs
Outdated
Show resolved
Hide resolved
| /// <returns>One of the enumeration values that describes the status with which the operation finished.</returns> | ||
| public OperationStatus Flush(Span<byte> destination, out int bytesWritten) | ||
| { | ||
| return Compress(ReadOnlySpan<byte>.Empty, destination, out _, out bytesWritten, isFinalBlock: false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this force writing output (if available), I think this should lead to FlushCode.SyncFlush to the native API
| /// <param name="source">A read-only span of bytes containing the source data to compress.</param> | ||
| /// <param name="destination">When this method returns, a span of bytes where the compressed data is stored.</param> | ||
| /// <param name="bytesWritten">When this method returns, the total number of bytes that were written to <paramref name="destination"/>.</param> | ||
| /// <param name="compressionLevel">A number representing compression level. -1 is default, 0 is no compression, 1 is best speed, 9 is best compression.</param> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be more clear which default we mean.
| /// <param name="compressionLevel">A number representing compression level. -1 is default, 0 is no compression, 1 is best speed, 9 is best compression.</param> | |
| /// <param name="compressionLevel">A number representing compression level. -1 means implementation default, 0 is no compression, 1 is best speed, 9 is best compression.</param> |
| CompressionLevel.Fastest => ZLibNative.CompressionLevel.BestSpeed, | ||
| CompressionLevel.NoCompression => ZLibNative.CompressionLevel.NoCompression, | ||
| CompressionLevel.SmallestSize => ZLibNative.CompressionLevel.BestCompression, | ||
| _ => throw new ArgumentOutOfRangeException(nameof(compressionLevel)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would fail on valid native compression levels not covered by the CompressionLevel enum. Instead I think it should check if the value is is < -1 or > 9 to throw out of range instead.
|
|
||
| namespace System.IO.Compression | ||
| { | ||
| public class DeflateEncoderDecoderTests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that Zstandard API is merged, you can rebase to main and make use of
runtime/src/libraries/Common/tests/System/IO/Compression/EncoderDecoderTestBase.cs
Line 16 in c9aa605
| public abstract class EncoderDecoderTestBase |
Look at e.g.
runtime/src/libraries/System.IO.Compression.Brotli/tests/BrotliEncoderDecoderTests.cs
Line 11 in c9aa605
| public class BrotliEncoderDecoderTests : EncoderDecoderTestBase |
src/libraries/System.IO.Compression/src/System/IO/Compression/GZipEncoder.cs
Outdated
Show resolved
Hide resolved
| /// <summary> | ||
| /// Internal constructor to specify windowBits for different compression formats. | ||
| /// </summary> | ||
| internal DeflateEncoder(CompressionLevel compressionLevel, ZLibCompressionStrategy strategy, int windowBits) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to expose windowBits in the public API for all types? we would need to do some processing since for some value it needs to be shifted or negated to get the appropriate value that zlib-ng recognizes, but I think it would be nice to be provide consistent configuration knobs for all Encoder* types we have
This PR introduces new span-based, streamless compression and decompression APIs for Deflate, ZLib, and GZip formats, matching the existing
BrotliEncoder/BrotliDecoderpattern.New APIs
DeflateEncoder/DeflateDecoderZLibEncoder/ZLibDecoderGZipEncoder/GZipDecoderThese classes provide:
Compress(),Decompress(), andFlush()TryCompress() andTryDecompress()for simple scenariosGetMaxCompressedLength()to calculate buffer sizesCloses #62113
Closes #39327