Skip to content
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

[Xamarin.MacDev] Use Stream.ReadExactly instead of Stream.Read when we can. #121

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Xamarin.MacDev/PListObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,11 @@ protected override DateTime ReadDate ()
protected override byte [] ReadData ()
{
var bytes = new byte [currentLength];
#if NET7_0_OR_GREATER
stream.ReadExactly (bytes, 0, currentLength);
#else
stream.Read (bytes, 0, currentLength);
#endif
return bytes;
}

Expand All @@ -1350,11 +1354,19 @@ protected override string ReadString ()
switch (CurrentType) {
case PlistType.@string: // ASCII
bytes = new byte [currentLength];
#if NET7_0_OR_GREATER
stream.ReadExactly (bytes, 0, bytes.Length);
#else
stream.Read (bytes, 0, bytes.Length);
#endif
return Encoding.ASCII.GetString (bytes);
case PlistType.wideString: //CFBinaryPList.c: Unicode string...big-endian 2-byte uint16_t
bytes = new byte [currentLength * 2];
#if NET7_0_OR_GREATER
stream.ReadExactly (bytes, 0, bytes.Length);
#else
stream.Read (bytes, 0, bytes.Length);
#endif
return Encoding.BigEndianUnicode.GetString (bytes);
}

Expand Down Expand Up @@ -1418,7 +1430,11 @@ public override bool ReadDict (PDictionary dict)
byte [] ReadBigEndianBytes (int count)
{
var bytes = new byte [count];
#if NET7_0_OR_GREATER
stream.ReadExactly (bytes, 0, count);
#else
stream.Read (bytes, 0, count);
#endif
if (BitConverter.IsLittleEndian)
Array.Reverse (bytes);
return bytes;
Expand Down
Loading