mirror of
https://github.com/AlexMacocian/SystemExtensions.git
synced 2026-07-22 17:19:30 +00:00
Added various extensions.
Added coding style helpers. Unit tests.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using System.IO;
|
||||
|
||||
namespace System.Extensions
|
||||
{
|
||||
public static class BytesExtensions
|
||||
{
|
||||
public static byte[] ReadAllBytes(this Stream stream)
|
||||
{
|
||||
if (stream is null) throw new ArgumentNullException(nameof(stream));
|
||||
|
||||
var buffer = new byte[256];
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
int read;
|
||||
while ((read = stream.Read(buffer, 0, 256)) > 0)
|
||||
{
|
||||
ms.Write(buffer, 0, read);
|
||||
}
|
||||
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user