aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Common/Utilities/StreamUtils.cs
blob: 4d090fe98dd52bcf526ef97596f9141a256e2be7 (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
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();
        }
    }
}