Browse Source

Base the buffer size on the stream length

pull/2276/head
James Jackson-South 4 years ago
parent
commit
e2c574856e
  1. 2
      tests/ImageSharp.Tests/Image/ImageTests.Decode_Cancellation.cs
  2. 2
      tests/ImageSharp.Tests/TestUtilities/IPausedStream.cs
  3. 4
      tests/ImageSharp.Tests/TestUtilities/PausedMemoryStream.cs
  4. 4
      tests/ImageSharp.Tests/TestUtilities/PausedStream.cs

2
tests/ImageSharp.Tests/Image/ImageTests.Decode_Cancellation.cs

@ -85,7 +85,7 @@ public partial class ImageTests
Configuration configuration = Configuration.CreateDefaultInstance(); Configuration configuration = Configuration.CreateDefaultInstance();
configuration.FileSystem = new SingleStreamFileSystem((Stream)pausedStream); configuration.FileSystem = new SingleStreamFileSystem((Stream)pausedStream);
configuration.StreamProcessingBufferSize = 256; configuration.StreamProcessingBufferSize = (int)Math.Min(128, pausedStream.Length / 4);
DecoderOptions options = new() DecoderOptions options = new()
{ {

2
tests/ImageSharp.Tests/TestUtilities/IPausedStream.cs

@ -12,4 +12,6 @@ public interface IPausedStream : IDisposable
public void Next(); public void Next();
public void Release(); public void Release();
public long Length { get; }
} }

4
tests/ImageSharp.Tests/TestUtilities/PausedMemoryStream.cs

@ -12,9 +12,9 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities;
/// </summary> /// </summary>
public class PausedMemoryStream : MemoryStream, IPausedStream public class PausedMemoryStream : MemoryStream, IPausedStream
{ {
private readonly SemaphoreSlim semaphore = new SemaphoreSlim(0); private readonly SemaphoreSlim semaphore = new(0);
private readonly CancellationTokenSource cancelationTokenSource = new CancellationTokenSource(); private readonly CancellationTokenSource cancelationTokenSource = new();
private Action<Stream> onWaitingCallback; private Action<Stream> onWaitingCallback;

4
tests/ImageSharp.Tests/TestUtilities/PausedStream.cs

@ -7,9 +7,9 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities;
public class PausedStream : Stream, IPausedStream public class PausedStream : Stream, IPausedStream
{ {
private readonly SemaphoreSlim semaphore = new SemaphoreSlim(0); private readonly SemaphoreSlim semaphore = new(0);
private readonly CancellationTokenSource cancelationTokenSource = new CancellationTokenSource(); private readonly CancellationTokenSource cancelationTokenSource = new();
private readonly Stream innerStream; private readonly Stream innerStream;
private Action<Stream> onWaitingCallback; private Action<Stream> onWaitingCallback;

Loading…
Cancel
Save