Browse Source

Merge branch 'js/decoder-attempt-2' of https://github.com/SixLabors/ImageSharp into js/decoder-attempt-2

pull/2276/head
Anton Firszov 3 years ago
parent
commit
475825d441
  1. 2
      src/ImageSharp/IO/BufferedReadStream.cs
  2. 2
      tests/ImageSharp.Tests/Image/ImageTests.Decode_Cancellation.cs
  3. 2
      tests/ImageSharp.Tests/TestUtilities/IPausedStream.cs
  4. 4
      tests/ImageSharp.Tests/TestUtilities/PausedMemoryStream.cs
  5. 4
      tests/ImageSharp.Tests/TestUtilities/PausedStream.cs

2
src/ImageSharp/IO/BufferedReadStream.cs

@ -90,6 +90,7 @@ internal sealed class BufferedReadStream : Stream
set set
{ {
Guard.MustBeGreaterThanOrEqualTo(value, 0, nameof(this.Position)); Guard.MustBeGreaterThanOrEqualTo(value, 0, nameof(this.Position));
this.cancellationToken.ThrowIfCancellationRequested();
// Only reset readBufferIndex if we are out of bounds of our working buffer // Only reset readBufferIndex if we are out of bounds of our working buffer
// otherwise we should simply move the value by the diff. // otherwise we should simply move the value by the diff.
@ -262,6 +263,7 @@ internal sealed class BufferedReadStream : Stream
[MethodImpl(MethodImplOptions.NoInlining)] [MethodImpl(MethodImplOptions.NoInlining)]
private void FillReadBuffer() private void FillReadBuffer()
{ {
this.cancellationToken.ThrowIfCancellationRequested();
Stream baseStream = this.BaseStream; Stream baseStream = this.BaseStream;
if (this.readerPosition != baseStream.Position) if (this.readerPosition != baseStream.Position)
{ {

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

@ -86,7 +86,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