-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Span-based (non-stream) compression APIs #39327
Comments
These should probably use the OperationStatus enum to communicate its result, like the BrotliEncoder/Decoder. The names should also follow suit. So, something like this would make sense for DEFLATE, I believe: class DeflateEncoder : IDisposable
{
public DeflateEncoder(CompressionLevel level);
public OperationStatus Compress(ReadOnlySpan<byte> source, ReadOnlySpan<byte> destination, out int bytesConsumed, out int bytesWritten, bool isFinalBlock);
public static int GetMaxCompressedLength(int inputSize);
// IDisposable implementation
}
class DeflateDecoder : IDisposable
{
public DeflateDecoder(CompressionLevel level);
public OperationStatus Decompress(ReadOnlySpan<byte> source, ReadOnlySpan<byte> destination, out int bytesConsumed, out int bytesWritten, bool isFinalBlock);
// IDisposable implementation
}
// Likewise for GZip Since we're here, could we potentially also add one for ZLib? It would have the same API as above, but instead of producing raw DEFLATE blocks or GZip blocks, it would produce ZLib blocks instead. |
Related #16923 |
I read about ZLib compression level was between 0 and 9, but now may be 19 or even higher. Need a way to specify that too. |
Background and Motivation
Currently to compress/decompress in .NET, you typically would use GZipStream or DeflateStream. However, there are a lot of times where you have an array of bytes and you want to get your output in an array of bytes. It would be simpler/faster to not have to have a bunch of stream redirection to the underlying byte array.
The request is that we add some methods that operate on bytes.
Proposed API
Roughly something like this
Usage Examples
I'm just sort of pseudo-coding this out:
The text was updated successfully, but these errors were encountered: