StaticRemoteStreamWriter.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using MediaBrowser.Common.Net;
  6. using MediaBrowser.Model.Services;
  7. namespace MediaBrowser.Api.Playback
  8. {
  9. /// <summary>
  10. /// Class StaticRemoteStreamWriter
  11. /// </summary>
  12. public class StaticRemoteStreamWriter : IAsyncStreamWriter, IHasHeaders
  13. {
  14. /// <summary>
  15. /// The _input stream
  16. /// </summary>
  17. private readonly HttpResponseInfo _response;
  18. /// <summary>
  19. /// The _options
  20. /// </summary>
  21. private readonly IDictionary<string, string> _options = new Dictionary<string, string>();
  22. public StaticRemoteStreamWriter(HttpResponseInfo response)
  23. {
  24. _response = response;
  25. }
  26. /// <summary>
  27. /// Gets the options.
  28. /// </summary>
  29. /// <value>The options.</value>
  30. public IDictionary<string, string> Headers => _options;
  31. public async Task WriteToAsync(Stream responseStream, CancellationToken cancellationToken)
  32. {
  33. using (_response)
  34. {
  35. await _response.Content.CopyToAsync(responseStream, 81920, cancellationToken).ConfigureAwait(false);
  36. }
  37. }
  38. }
  39. }