2023-03-17 08:14:50 -04:00
|
|
|
|
using Microsoft.IO;
|
|
|
|
|
using Ryujinx.Common.Memory;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-09-14 19:24:49 -04:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Common.Utilities
|
|
|
|
|
{
|
|
|
|
|
public static class StreamUtils
|
|
|
|
|
{
|
|
|
|
|
public static byte[] StreamToBytes(Stream input)
|
|
|
|
|
{
|
2023-03-17 08:14:50 -04:00
|
|
|
|
using (MemoryStream stream = MemoryStreamManager.Shared.GetStream())
|
2021-09-14 19:24:49 -04:00
|
|
|
|
{
|
|
|
|
|
input.CopyTo(stream);
|
|
|
|
|
|
|
|
|
|
return stream.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-17 08:14:50 -04:00
|
|
|
|
|
|
|
|
|
public static async Task<byte[]> StreamToBytesAsync(Stream input, CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
using (MemoryStream stream = MemoryStreamManager.Shared.GetStream())
|
|
|
|
|
{
|
|
|
|
|
await input.CopyToAsync(stream, cancellationToken);
|
|
|
|
|
|
|
|
|
|
return stream.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-14 19:24:49 -04:00
|
|
|
|
}
|
|
|
|
|
}
|