//
// Copyright (c) alveus.dev. All rights reserved. Licensed under the MIT License.
//
namespace Astral.Core.Extensions;
///
/// extensions.
///
public static class StreamExtensions
{
///
/// Return a byte array of the contents of the stream.
///
/// Instance of .
/// Collection of bytes.
public static byte[] ToByteArray(this Stream stream)
{
stream.Position = 0;
var buffer = new byte[stream.Length];
for (var totalBytesCopied = 0; totalBytesCopied < stream.Length;)
{
totalBytesCopied +=
stream.Read(buffer, totalBytesCopied, Convert.ToInt32(stream.Length) - totalBytesCopied);
}
return buffer;
}
}