2023-03-17 13:14:50 +01:00
|
|
|
|
using Microsoft.IO;
|
|
|
|
|
using Ryujinx.Common.Memory;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-09-15 01:24:49 +02:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Common.Utilities
|
|
|
|
|
{
|
|
|
|
|
public static class StreamUtils
|
|
|
|
|
{
|
|
|
|
|
public static byte[] StreamToBytes(Stream input)
|
|
|
|
|
{
|
2023-03-17 13:14:50 +01:00
|
|
|
|
using (MemoryStream stream = MemoryStreamManager.Shared.GetStream())
|
2021-09-15 01:24:49 +02:00
|
|
|
|
{
|
|
|
|
|
input.CopyTo(stream);
|
|
|
|
|
|
|
|
|
|
return stream.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-17 13:14:50 +01: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-15 01:24:49 +02:00
|
|
|
|
}
|
|
|
|
|
}
|