-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
ZLibStream does not seem to decompress correctly. #62858
Comments
Tagging subscribers to this area: @dotnet/area-system-io-compression Issue DetailsDescriptionI'm working on a save editor for the game Kingdoms of Amalur. Parts of the save file can be stored in compressed chunks using zlib compression. I have created a repro here: Reproduction StepsClone the repro repository and run the program. Expected behaviorOutput should be: Actual behavior
Regression?No. Known WorkaroundsUse a third party library. Configuration.net 6.10 Other informationNo response
|
This is a known change in .NET 6. See https://docs.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/6.0/partial-byte-reads-in-streams. You need to call |
Ah interesting. I didn't realize that the new ZLibStream is also impacted by this change. It's not mentioned on that page. |
I presume that ZLibStream was affected by the change; it has been following the standard stream contract from the start, so it isn't listed there. In your case I'm guessing you were assuming DotNetZip's behavior, and then you switched to ZLibStream, it would have appeared to be a break. @mburbea if you verify that this works for you, we can close the issue. Thanks for reporting it though. |
ZLibStream is new in .NET 6 so that is probably why it was not documented as a behavior change. However, from the
It's valid for any stream implementation to return fewer bytes than requested. |
Good to know, I know I have some .net 5 code on at work that assumes that gzipped data can just be read into a MemoryStream as a one shot. public static int ReadAll(this ZLibStream stream, Span<byte> buffer)
{
var totalAmountRead = 0;
while (stream.Read(buffer) is int read and > 0)
{
totalAmountRead += read;
buffer = buffer[read..];
}
return totalAmountRead;
} @danmoseley, I'm closing the issue thanks for the quick triage! |
this may get wrapped into a helper/extension method in future version #58216 |
Description
I'm working on a save editor for the game Kingdoms of Amalur. Parts of the save file can be stored in compressed chunks using zlib compression.
Before .net6, I was using the nuget package DotNetZip and that seems to work correctly. However, I tried to switch from the library to the new
System.IO.Compression.ZLibStream
and it was no longer being read correctly. It seems to be cutting the data short.I have created a repro here:
https://github.com/mburbea/ZlibStreamRepro/tree/master
Reproduction Steps
Clone the repro repository and run the program.
Expected behavior
Output should be:
Both read the same amount
Actual behavior
Regression?
No.
Known Workarounds
Use a third party library.
Configuration
.net 6.10
Windows 11 x64
Other information
No response
The text was updated successfully, but these errors were encountered: