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