diff options
| author | hatharry <hatharry@hotmail.com> | 2016-07-25 23:29:52 +1200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-07-25 23:29:52 +1200 |
| commit | f21f9923de6291aaf985f32dbbbaddbb26d07fb1 (patch) | |
| tree | 1a313e9a1c6790a755926bcef221c5f680537eae /MediaBrowser.Server.Implementations/HttpServer/StreamWriter.cs | |
| parent | 6332d0b9436c511a59e2abd67ea8c24ce3d82ace (diff) | |
| parent | 8328f39834f042e1808fd8506bbc7c48151703ab (diff) | |
Merge pull request #15 from MediaBrowser/dev
Dev
Diffstat (limited to 'MediaBrowser.Server.Implementations/HttpServer/StreamWriter.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/HttpServer/StreamWriter.cs | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/MediaBrowser.Server.Implementations/HttpServer/StreamWriter.cs b/MediaBrowser.Server.Implementations/HttpServer/StreamWriter.cs index a756f4aa8..f5906f6b7 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/StreamWriter.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/StreamWriter.cs @@ -4,13 +4,15 @@ using System; using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Threading.Tasks; +using ServiceStack; namespace MediaBrowser.Server.Implementations.HttpServer { /// <summary> /// Class StreamWriter /// </summary> - public class StreamWriter : IStreamWriter, IHasOptions + public class StreamWriter : IStreamWriter, IAsyncStreamWriter, IHasOptions { private ILogger Logger { get; set; } @@ -73,30 +75,49 @@ namespace MediaBrowser.Server.Implementations.HttpServer { } + // 256k + private const int BufferSize = 262144; + /// <summary> /// Writes to. /// </summary> /// <param name="responseStream">The response stream.</param> public void WriteTo(Stream responseStream) { - WriteToInternal(responseStream); + try + { + using (var src = SourceStream) + { + src.CopyTo(responseStream, BufferSize); + } + } + catch (Exception ex) + { + Logger.ErrorException("Error streaming data", ex); + + if (OnError != null) + { + OnError(); + } + + throw; + } + finally + { + if (OnComplete != null) + { + OnComplete(); + } + } } - // 256k - private const int BufferSize = 262144; - - /// <summary> - /// Writes to async. - /// </summary> - /// <param name="responseStream">The response stream.</param> - /// <returns>Task.</returns> - private void WriteToInternal(Stream responseStream) + public async Task WriteToAsync(Stream responseStream) { try { using (var src = SourceStream) { - src.CopyTo(responseStream, BufferSize); + await src.CopyToAsync(responseStream, BufferSize).ConfigureAwait(false); } } catch (Exception ex) @@ -107,7 +128,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer { OnError(); } - + throw; } finally |
