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