Open jnix-abk opened 2 years ago
Tagging subscribers to this area: @dotnet/area-system-io-compression See info in area-owners.md if you want to be subscribed.
Author: | jnix-abk |
---|---|
Assignees: | - |
Labels: | `api-suggestion`, `area-System.IO.Compression` |
Milestone: | - |
@carlossanlop @Jozkee @stephentoub are there any reasons why we should not expose this data?
Any update on this?
@stephentoub are there any reasons why we should not expose this data?
I don't have fundamental objections to this, other than it "feels" strange. If the goal is to avoid DeflateStream/GZipStream/ZLibStream consuming more of the source stream than actually contains the relevant data, could we have the streams seek backwards themselves once they're closed if the source is seekable? Or would this be a better for fit https://github.com/dotnet/runtime/issues/39327 / https://github.com/dotnet/runtime/issues/62113 such that the developer is handling all of the interactions with the source stream themselves and knows exactly how many of the bytes were consumed by the decompression process?
ZLib data does not have an easy size indicator that I could use to grab just the compressed data. If I knew the size, I'd just extract it and shove it in a MemoryStream. That is why I need the above property exposed.
My current workaround for this is to catch and then ignore the EndOfStreamException
which is thrown from attempting to read past the end of the stream.
Background and motivation
I am working with data that has packed objects that contain header bytes and then a ZLib blob. The DeflateStream class has an internal buffer that advances the BaseStream to fetch data. The problem is that the underlying Stream is then advanced past where the ZLib blob ends. Currently, I have to use reflection to reach down into the object model to get the number of bytes that were not consumed in the buffer so I can re-wind the BaseStream to where the ZLib data ended. Like so:
API Proposal
Can you add
below this: https://github.com/dotnet/runtime/blob/a3fb0d383adf98ee2fb2ab816c28735dc1caaba0/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/Inflater.cs#L43
And then add
here: https://github.com/dotnet/runtime/blob/a3fb0d383adf98ee2fb2ab816c28735dc1caaba0/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/DeflateStream.cs#L120
And then add
below: https://github.com/dotnet/runtime/blob/a3fb0d383adf98ee2fb2ab816c28735dc1caaba0/src/libraries/System.IO.Compression/ref/System.IO.Compression.cs#L131
Finally add:
here: https://github.com/dotnet/runtime/blob/d2c991effcdf543cc60632e5588984aa22dd6772/src/libraries/System.IO.Compression/src/System/IO/Compression/ZLibStream.cs#L66
I have added these to a local copy and built the whole thing. It works as expected.
API Usage
Alternative Designs
No response
Risks
There are no risks as this is simply exposing data to read that is already present.