mirror of
https://github.com/RPCS3/discord-bot.git
synced 2025-04-16 11:49:57 +00:00
21 lines
590 B
C#
21 lines
590 B
C#
using System.IO;
|
|
|
|
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.AsMemory(result, remaining)).ConfigureAwait(false);
|
|
result += read;
|
|
} while (read > 0 && result < count);
|
|
return result;
|
|
}
|
|
} |