mirror of
https://github.com/RPCS3/discord-bot.git
synced 2024-12-13 22:08:37 +00:00
24 lines
682 B
C#
24 lines
682 B
C#
using System.IO;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CompatBot.Utils
|
|
{
|
|
internal static class StreamExtensions
|
|
{
|
|
public static async Task<int> ReadBytesAsync(this Stream stream, byte[] buffer, int count = 0)
|
|
{
|
|
if (count < 1 || count > buffer.Length)
|
|
count = buffer.Length;
|
|
var result = 0;
|
|
int read;
|
|
do
|
|
{
|
|
var remaining = count - result;
|
|
read = await stream.ReadAsync(buffer, result, remaining).ConfigureAwait(false);
|
|
result += read;
|
|
} while (read > 0 && result < count);
|
|
return result;
|
|
}
|
|
}
|
|
}
|