Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikus1993 committed Feb 29, 2024
1 parent 33c5cc4 commit 34ed0d4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/BuildingBlocks/Common/Common.csproj
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<Project Sdk="Microsoft.NET.Sdk">

</Project>
<Project Sdk="Microsoft.NET.Sdk" />
28 changes: 28 additions & 0 deletions src/BuildingBlocks/Common/Extensions/StreamExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Common.Extensions;

public static class StreamExtensions
{
public static byte[] ReadBytes(this Stream stream, int count)
{
ArgumentOutOfRangeException.ThrowIfNegative(count);
ArgumentNullException.ThrowIfNull(stream);
if (stream.Length == 0)
{
return [];
}

if (count == 0)
{
return [];
}

var buffer = new byte[count];
var readBytes = stream.ReadAtLeast(buffer, count, false);

if (readBytes < count)
{
Array.Resize(ref buffer, readBytes);
}
return buffer;
}
}

0 comments on commit 34ed0d4

Please sign in to comment.