aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/IO/AsyncStreamCopier.cs
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2017-05-25 09:00:55 -0400
committerGitHub <noreply@github.com>2017-05-25 09:00:55 -0400
commit40bc3b7b2205d7bc0802cf81bf199c655b81efd7 (patch)
treece7efa462a2620c3d2eddeaec41464ac3959f50c /Emby.Server.Implementations/IO/AsyncStreamCopier.cs
parent2715db6ad794588614a2585a51d1cfde6d8e2941 (diff)
parentb527e56ec3b7d644245b2a2b6bd39c1e2a375c83 (diff)
Merge pull request #2664 from MediaBrowser/dev
Dev
Diffstat (limited to 'Emby.Server.Implementations/IO/AsyncStreamCopier.cs')
-rw-r--r--Emby.Server.Implementations/IO/AsyncStreamCopier.cs19
1 files changed, 10 insertions, 9 deletions
diff --git a/Emby.Server.Implementations/IO/AsyncStreamCopier.cs b/Emby.Server.Implementations/IO/AsyncStreamCopier.cs
index e7330591c..9e5ce0604 100644
--- a/Emby.Server.Implementations/IO/AsyncStreamCopier.cs
+++ b/Emby.Server.Implementations/IO/AsyncStreamCopier.cs
@@ -8,7 +8,7 @@ namespace Emby.Server.Implementations.IO
public class AsyncStreamCopier : IDisposable
{
// size in bytes of the buffers in the buffer pool
- private const int DefaultBufferSize = 4096;
+ private const int DefaultBufferSize = 81920;
private readonly int _bufferSize;
// number of buffers in the pool
private const int DefaultBufferCount = 4;
@@ -38,15 +38,16 @@ namespace Emby.Server.Implementations.IO
// stored here for rethrow
private Exception _exception;
- public TaskCompletionSource<bool> TaskCompletionSource;
+ public TaskCompletionSource<long> TaskCompletionSource;
private long _bytesToRead;
private long _totalBytesWritten;
private CancellationToken _cancellationToken;
+ public int IndividualReadOffset = 0;
public AsyncStreamCopier(Stream source,
Stream target,
- long bytesToRead,
- CancellationToken cancellationToken,
+ long bytesToRead,
+ CancellationToken cancellationToken,
bool closeStreamsOnEnd = false,
int bufferSize = DefaultBufferSize,
int bufferCount = DefaultBufferCount)
@@ -77,15 +78,15 @@ namespace Emby.Server.Implementations.IO
ThrowExceptionIfNeeded();
}
- public static Task CopyStream(Stream source, Stream target, int bufferSize, int bufferCount, CancellationToken cancellationToken)
+ public static Task<long> CopyStream(Stream source, Stream target, int bufferSize, int bufferCount, CancellationToken cancellationToken)
{
return CopyStream(source, target, 0, bufferSize, bufferCount, cancellationToken);
}
- public static Task CopyStream(Stream source, Stream target, long size, int bufferSize, int bufferCount, CancellationToken cancellationToken)
+ public static Task<long> CopyStream(Stream source, Stream target, long size, int bufferSize, int bufferCount, CancellationToken cancellationToken)
{
var copier = new AsyncStreamCopier(source, target, size, cancellationToken, false, bufferSize, bufferCount);
- var taskCompletion = new TaskCompletionSource<bool>();
+ var taskCompletion = new TaskCompletionSource<long>();
copier.TaskCompletionSource = taskCompletion;
@@ -109,7 +110,7 @@ namespace Emby.Server.Implementations.IO
try
{
copier.EndCopy(result);
- taskCompletion.TrySetResult(true);
+ taskCompletion.TrySetResult(copier._totalBytesWritten);
}
catch (Exception ex)
{
@@ -238,7 +239,7 @@ namespace Emby.Server.Implementations.IO
bytesToWrite = _sizes[bufferIndex];
}
- _target.BeginWrite(_buffers[bufferIndex], 0, bytesToWrite, EndWrite, null);
+ _target.BeginWrite(_buffers[bufferIndex], IndividualReadOffset, bytesToWrite - IndividualReadOffset, EndWrite, null);
_totalBytesWritten += bytesToWrite;
}