aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/LiveTv/ProgressiveFileCopier.cs
diff options
context:
space:
mode:
authorLogicalPhallacy <44458166+LogicalPhallacy@users.noreply.github.com>2019-03-16 00:25:16 -0700
committerGitHub <noreply@github.com>2019-03-16 00:25:16 -0700
commit2d0844b5dbf08869896c5479c10675c4fe7fa988 (patch)
treedea28b14d2b1733edf1a90a46f4163f6123616fe /MediaBrowser.Api/LiveTv/ProgressiveFileCopier.cs
parent221389089cc9ca4b69907d6bf3e9d38bf94393ea (diff)
parent59031ee3b8b2ac8298c41f9171b658e3f15e17bc (diff)
Merge pull request #1 from jellyfin/master
merging myself to latest
Diffstat (limited to 'MediaBrowser.Api/LiveTv/ProgressiveFileCopier.cs')
-rw-r--r--MediaBrowser.Api/LiveTv/ProgressiveFileCopier.cs45
1 files changed, 10 insertions, 35 deletions
diff --git a/MediaBrowser.Api/LiveTv/ProgressiveFileCopier.cs b/MediaBrowser.Api/LiveTv/ProgressiveFileCopier.cs
index 8412bf66b..4c608d9a3 100644
--- a/MediaBrowser.Api/LiveTv/ProgressiveFileCopier.cs
+++ b/MediaBrowser.Api/LiveTv/ProgressiveFileCopier.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
@@ -5,60 +6,39 @@ using System.Threading.Tasks;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Services;
-using MediaBrowser.Model.System;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.LiveTv
{
public class ProgressiveFileCopier : IAsyncStreamWriter, IHasHeaders
{
- private readonly IFileSystem _fileSystem;
private readonly ILogger _logger;
private readonly string _path;
private readonly Dictionary<string, string> _outputHeaders;
- const int StreamCopyToBufferSize = 81920;
-
- public long StartPosition { get; set; }
public bool AllowEndOfFile = true;
private readonly IDirectStreamProvider _directStreamProvider;
- private readonly IEnvironmentInfo _environment;
private IStreamHelper _streamHelper;
- public ProgressiveFileCopier(IFileSystem fileSystem, IStreamHelper streamHelper, string path, Dictionary<string, string> outputHeaders, ILogger logger, IEnvironmentInfo environment)
+ public ProgressiveFileCopier(IStreamHelper streamHelper, string path, Dictionary<string, string> outputHeaders, ILogger logger)
{
- _fileSystem = fileSystem;
_path = path;
_outputHeaders = outputHeaders;
_logger = logger;
- _environment = environment;
_streamHelper = streamHelper;
}
- public ProgressiveFileCopier(IDirectStreamProvider directStreamProvider, IStreamHelper streamHelper, Dictionary<string, string> outputHeaders, ILogger logger, IEnvironmentInfo environment)
+ public ProgressiveFileCopier(IDirectStreamProvider directStreamProvider, IStreamHelper streamHelper, Dictionary<string, string> outputHeaders, ILogger logger)
{
_directStreamProvider = directStreamProvider;
_outputHeaders = outputHeaders;
_logger = logger;
- _environment = environment;
_streamHelper = streamHelper;
}
public IDictionary<string, string> Headers => _outputHeaders;
- private Stream GetInputStream(bool allowAsyncFileRead)
- {
- var fileOpenOptions = FileOpenOptions.SequentialScan;
-
- if (allowAsyncFileRead)
- {
- fileOpenOptions |= FileOpenOptions.Asynchronous;
- }
-
- return _fileSystem.GetFileStream(_path, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.ReadWrite, fileOpenOptions);
- }
-
public async Task WriteToAsync(Stream outputStream, CancellationToken cancellationToken)
{
if (_directStreamProvider != null)
@@ -67,28 +47,23 @@ namespace MediaBrowser.Api.LiveTv
return;
}
- var eofCount = 0;
+ var fileOptions = FileOptions.SequentialScan;
// use non-async filestream along with read due to https://github.com/dotnet/corefx/issues/6039
- var allowAsyncFileRead = true;
-
- using (var inputStream = GetInputStream(allowAsyncFileRead))
+ if (Environment.OSVersion.Platform != PlatformID.Win32NT)
{
- if (StartPosition > 0)
- {
- inputStream.Position = StartPosition;
- }
+ fileOptions |= FileOptions.Asynchronous;
+ }
+ using (var inputStream = new FileStream(_path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4096, fileOptions))
+ {
var emptyReadLimit = AllowEndOfFile ? 20 : 100;
-
+ var eofCount = 0;
while (eofCount < emptyReadLimit)
{
int bytesRead;
bytesRead = await _streamHelper.CopyToAsync(inputStream, outputStream, cancellationToken).ConfigureAwait(false);
- //var position = fs.Position;
- //_logger.LogDebug("Streamed {0} bytes to position {1} from file {2}", bytesRead, position, path);
-
if (bytesRead == 0)
{
eofCount++;