aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Common/Utilities/StreamUtils.cs
blob: da97188d8b1994c7bd20f321a16775e78e083feb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using Microsoft.IO;
using Ryujinx.Common.Memory;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

namespace Ryujinx.Common.Utilities
{
    public static class StreamUtils
    {
        public static byte[] StreamToBytes(Stream input)
        {
            using (MemoryStream stream = MemoryStreamManager.Shared.GetStream())
            {
                input.CopyTo(stream);

                return stream.ToArray();
            }
        }

        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();
            }
        }
    }
}