Merge pull request #1117 from Bond-009/ffmpeg

Check before flushing ffmpeg log
This commit is contained in:
Joshua M. Boniface 2019-03-18 23:59:12 -04:00 committed by GitHub
commit c7e7aa0a61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,7 +10,7 @@ namespace MediaBrowser.Controller.MediaEncoding
{ {
public class JobLogger public class JobLogger
{ {
private readonly CultureInfo _usCulture = new CultureInfo("en-US"); private static readonly CultureInfo _usCulture = CultureInfo.ReadOnly(new CultureInfo("en-US"));
private readonly ILogger _logger; private readonly ILogger _logger;
public JobLogger(ILogger logger) public JobLogger(ILogger logger)
@ -24,7 +24,7 @@ namespace MediaBrowser.Controller.MediaEncoding
{ {
using (var reader = new StreamReader(source)) using (var reader = new StreamReader(source))
{ {
while (!reader.EndOfStream) while (!reader.EndOfStream && reader.BaseStream.CanRead)
{ {
var line = await reader.ReadLineAsync().ConfigureAwait(false); var line = await reader.ReadLineAsync().ConfigureAwait(false);
@ -39,6 +39,13 @@ namespace MediaBrowser.Controller.MediaEncoding
} }
await target.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false); await target.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
// Check again, the stream could have been closed
if (!target.CanWrite)
{
break;
}
await target.FlushAsync().ConfigureAwait(false); await target.FlushAsync().ConfigureAwait(false);
} }
} }