aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/Playback/StaticRemoteStreamWriter.cs
blob: 6bb3b6b80460bba9c287b726a9d8233e3c6d01e2 (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using MediaBrowser.Common.Net;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Services;

namespace MediaBrowser.Api.Playback
{
    /// <summary>
    /// Class StaticRemoteStreamWriter
    /// </summary>
    public class StaticRemoteStreamWriter : IAsyncStreamWriter, IHasHeaders
    {
        /// <summary>
        /// The _input stream
        /// </summary>
        private readonly HttpResponseInfo _response;

        /// <summary>
        /// The _options
        /// </summary>
        private readonly IDictionary<string, string> _options = new Dictionary<string, string>();

        public StaticRemoteStreamWriter(HttpResponseInfo response)
        {
            _response = response;
        }

        /// <summary>
        /// Gets the options.
        /// </summary>
        /// <value>The options.</value>
        public IDictionary<string, string> Headers
        {
            get { return _options; }
        }

        public async Task WriteToAsync(Stream responseStream, CancellationToken cancellationToken)
        {
            using (_response)
            {
                await _response.Content.CopyToAsync(responseStream, 81920, cancellationToken).ConfigureAwait(false);
            }
        }
    }
}