Skip to content

Commit 305c621

Browse files
committed
Use ReadAtLeast in .NET 7.0.
1 parent e50affa commit 305c621

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/MySqlConnector/Protocol/Serialization/CompressedPayloadHandler.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,16 @@ private ValueTask<int> ReadBytesAsync(Memory<byte> buffer, ProtocolErrorBehavior
128128
var uncompressedData = new byte[uncompressedLength];
129129
using var compressedStream = new MemoryStream(payloadReadBytes.Array!, payloadReadBytes.Offset, payloadReadBytes.Count);
130130
using var decompressingStream = new ZLibStream(compressedStream, CompressionMode.Decompress);
131+
#if NET7_0_OR_GREATER
132+
var totalBytesRead = decompressingStream.ReadAtLeast(uncompressedData, uncompressedLength, throwOnEndOfStream: false);
133+
#else
131134
int bytesRead, totalBytesRead = 0;
132135
do
133136
{
134137
bytesRead = decompressingStream.Read(uncompressedData, totalBytesRead, uncompressedLength - totalBytesRead);
135138
totalBytesRead += bytesRead;
136139
} while (bytesRead > 0);
140+
#endif
137141
if (totalBytesRead != uncompressedLength && protocolErrorBehavior == ProtocolErrorBehavior.Throw)
138142
return ValueTaskExtensions.FromException<int>(new InvalidOperationException("Expected to read {0:n0} uncompressed bytes but only read {1:n0}".FormatInvariant(uncompressedLength, totalBytesRead)));
139143
m_remainingData = new(uncompressedData, 0, totalBytesRead);

0 commit comments

Comments
 (0)