StaticRemoteStreamWriter.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using MediaBrowser.Common.Net;
  2. using ServiceStack.Web;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Threading.Tasks;
  6. namespace MediaBrowser.Api.Playback
  7. {
  8. /// <summary>
  9. /// Class StaticRemoteStreamWriter
  10. /// </summary>
  11. public class StaticRemoteStreamWriter : IStreamWriter, IHasOptions
  12. {
  13. /// <summary>
  14. /// The _input stream
  15. /// </summary>
  16. private readonly HttpResponseInfo _response;
  17. /// <summary>
  18. /// The _options
  19. /// </summary>
  20. private readonly IDictionary<string, string> _options = new Dictionary<string, string>();
  21. public StaticRemoteStreamWriter(HttpResponseInfo response)
  22. {
  23. _response = response;
  24. }
  25. /// <summary>
  26. /// Gets the options.
  27. /// </summary>
  28. /// <value>The options.</value>
  29. public IDictionary<string, string> Options
  30. {
  31. get { return _options; }
  32. }
  33. /// <summary>
  34. /// Writes to.
  35. /// </summary>
  36. /// <param name="responseStream">The response stream.</param>
  37. public void WriteTo(Stream responseStream)
  38. {
  39. var task = WriteToAsync(responseStream);
  40. Task.WaitAll(task);
  41. }
  42. /// <summary>
  43. /// Writes to async.
  44. /// </summary>
  45. /// <param name="responseStream">The response stream.</param>
  46. /// <returns>Task.</returns>
  47. public async Task WriteToAsync(Stream responseStream)
  48. {
  49. using (var remoteStream = _response.Content)
  50. {
  51. await remoteStream.CopyToAsync(responseStream, 819200).ConfigureAwait(false);
  52. }
  53. }
  54. }
  55. }