-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from Visionaid-International-Ltd/avoid-inexac…
…t-reads Avoid inexact stream reads (CA2022)
- Loading branch information
Showing
5 changed files
with
49 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace OpenMcdf | ||
{ | ||
internal static class StreamExtensions | ||
{ | ||
public static void ReadExactly(this Stream stream, byte[] buffer, int offset, int count) | ||
{ | ||
if (stream is null) | ||
throw new ArgumentNullException(nameof(stream)); | ||
|
||
int totalRead = 0; | ||
do | ||
{ | ||
int read = stream.Read(buffer, offset + totalRead, count - totalRead); | ||
if (read == 0) | ||
throw new EndOfStreamException(); | ||
|
||
totalRead += read; | ||
} while (totalRead < count); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters