-
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
GZipStream.Read(byte[],int,int) return a Incorrect length. #71517
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
This is a documented breaking change in .NET 6: Partial and zero-byte reads in DeflateStream, GZipStream, and CryptoStream |
Tagging subscribers to this area: @dotnet/area-system-io-compression Issue DetailsDescription
Reproduction Stepsnone Expected behaviornone Actual behaviornone Regression?in Framework it's ok. Known WorkaroundsI think the specified length should be read and returned while the Stream is not over yet. ConfigurationNo response Other informationNo response
|
By contract, To fulfill, you can use the newly introduced
The |
In fact, I personally think that if you make some changes to the function, you can add a new function Read(byte[]), but directly modifying Read(byte[], int, int) leads to compatibility problems. Because Read(byte[], int, int) works correctly on FrameWork. When I ported to Core or Standard. . caused compatibility issues. now I need to change some code for Core or Standard. |
Hi @DebugST As @meziantou has pointed out, we have introduced this breaking change in .NET 6 and this was done on purpose because since .NET 1.0 As pointed by @huoyaoyuan you can use the new If your code is targeting .NET Framework, .NET Standard and .NET you can just copy-paste the implementation from here: #if !NET6_0_OR_GREATER // won't be included in your .NET 7 builds
namespace System.IO
{
public static class StreamExtensions
{
public static void ReadExactly(this Stream stream, byte[] buffer, int offset, int count)
{
// the copied code goes here
}
}
}
#endif Since this was done on purpose and we don't intend to change it, I am going to close the issue. Thanks! |
Tks..i had changed my code. |
Description
nLen = gs.Read(byTemp, 0, byTemp.Length);
The nLen != byTemp.Length ,byTemp.Length = 275968 but nLen = 11854.
In .Net Framework the nLen = 275968, but in Standard and Net6 also get 11854. And the Stream is not at the end.
If the data of the specified length cannot be read when the Stream is not over, what's the point of passing in a specified length?
Reproduction Steps
none
Expected behavior
none
Actual behavior
none
Regression?
in Framework it's ok.
Known Workarounds
I think the specified length should be read and returned while the Stream is not over yet.
Although I can get around this by reading in a loop. But since the Read function specifies the length to be read, why can't it be read according to the specified length? Otherwise, just Read(byte[]) will do.
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: