diff options
| author | Eric Reed <ebr@mediabrowser3.com> | 2013-05-18 18:18:41 -0400 |
|---|---|---|
| committer | Eric Reed <ebr@mediabrowser3.com> | 2013-05-18 18:18:41 -0400 |
| commit | 00449ff66dbbaba9901c47c65070868ca111ac45 (patch) | |
| tree | 14980d9711cbcc5d5d92a02031715d8f79b0eaf8 /MediaBrowser.Api/Playback/StaticRemoteStreamWriter.cs | |
| parent | 584641a6f43fee18f65dc9c8abd24b88742922ce (diff) | |
| parent | 407016a30702694e39505afbb599791ed7c2dcfe (diff) | |
Merge branch 'master' of https://github.com/MediaBrowser/MediaBrowser
Diffstat (limited to 'MediaBrowser.Api/Playback/StaticRemoteStreamWriter.cs')
| -rw-r--r-- | MediaBrowser.Api/Playback/StaticRemoteStreamWriter.cs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/MediaBrowser.Api/Playback/StaticRemoteStreamWriter.cs b/MediaBrowser.Api/Playback/StaticRemoteStreamWriter.cs new file mode 100644 index 000000000..89e13acb3 --- /dev/null +++ b/MediaBrowser.Api/Playback/StaticRemoteStreamWriter.cs @@ -0,0 +1,75 @@ +using ServiceStack.Service; +using ServiceStack.ServiceHost; +using System.Collections.Generic; +using System.IO; +using System.Net.Http; +using System.Threading.Tasks; + +namespace MediaBrowser.Api.Playback +{ + /// <summary> + /// Class StaticRemoteStreamWriter + /// </summary> + public class StaticRemoteStreamWriter : IStreamWriter, IHasOptions + { + /// <summary> + /// The _input stream + /// </summary> + private readonly HttpResponseMessage _msg; + + private readonly HttpClient _client; + + /// <summary> + /// The _options + /// </summary> + private readonly IDictionary<string, string> _options = new Dictionary<string, string>(); + + /// <summary> + /// Initializes a new instance of the <see cref="StaticRemoteStreamWriter"/> class. + /// </summary> + public StaticRemoteStreamWriter(HttpResponseMessage msg, HttpClient client) + { + _msg = msg; + _client = client; + } + + /// <summary> + /// Gets the options. + /// </summary> + /// <value>The options.</value> + public IDictionary<string, string> Options + { + get { return _options; } + } + + /// <summary> + /// Writes to. + /// </summary> + /// <param name="responseStream">The response stream.</param> + public void WriteTo(Stream responseStream) + { + var task = WriteToAsync(responseStream); + + Task.WaitAll(task); + } + + /// <summary> + /// Writes to async. + /// </summary> + /// <param name="responseStream">The response stream.</param> + /// <returns>Task.</returns> + public async Task WriteToAsync(Stream responseStream) + { + using (_client) + { + using (_msg) + { + using (var input = await _msg.Content.ReadAsStreamAsync().ConfigureAwait(false)) + { + await input.CopyToAsync(responseStream).ConfigureAwait(false); + } + } + } + } + } +} |
