Closed
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.IO.Compression
Milestone
Description
System.IO.Compression contains the DeflateStream class, that can decompress data from a stream. In case we have compressed data already loaded in a ReadOnlySpan<byte>, using DeflateStream might be little inefficient - we have to create a MemoryStream and this operation allocates a new array.
function Decompress(ReadOnlySpan<byte> block) {
using(var stream = new MemoryStream(block.ToArray())) {
using(var deflateStream = new DeflateStream(stream, CompressionMode.Decompress)) {
Data = ... read from deflateStream
}
}
}It would be great, if the Deflate algorithm is exposed in the way that supports processing data from ReadOnlySpan<byte>
Reacted by RayKoopa, Drazen Dotlic and Paulus Pärssinen
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.IO.Compression
Activity
karelz commentedon Jan 9, 2018
cc @stephentoub @KrzysztofCwalina
KrzysztofCwalina commentedon Jan 9, 2018
Yes, we have such APIs in Brotli (see BrotliEncoder & BrotliDecoder in https://github.com/dotnet/corefx/issues/25785). We should add similar APIs to Deflate/GZip.
cc: @ianhays, @joshfree
stephentoub commentedon Jan 10, 2018
That isn't the only option; you can create an UnmanagedMemoryStream from it (pinning the span with fixed) and then there's no extra array needed.
And if you have the data as a Memory instead of a Span, you can either do that or create a MemoryStream that wraps the original array if TryGetArray returns one.
karelz commentedon Dec 18, 2019
Duplicate of #16923