Browse Source

Throw, don't adjust.

pull/1574/head
James Jackson-South 6 years ago
parent
commit
c609db3b27
  1. 9
      src/ImageSharp/Configuration.cs
  2. 8
      tests/ImageSharp.Tests/ConfigurationTests.cs

9
src/ImageSharp/Configuration.cs

@ -25,8 +25,6 @@ namespace SixLabors.ImageSharp
/// A lazily initialized configuration default instance.
/// </summary>
private static readonly Lazy<Configuration> Lazy = new Lazy<Configuration>(CreateDefaultInstance);
private const int MinStreamProcessingBufferSize = 128;
private const int DefaultStreamProcessingBufferSize = 8096;
private int streamProcessingBufferSize = DefaultStreamProcessingBufferSize;
private int maxDegreeOfParallelism = Environment.ProcessorCount;
@ -79,17 +77,16 @@ namespace SixLabors.ImageSharp
/// <summary>
/// Gets or sets the size of the buffer to use when working with streams.
/// Intitialized with <see cref="DefaultStreamProcessingBufferSize"/> by default
/// and can accept a minimum value of <see cref="MinStreamProcessingBufferSize"/>.
/// Intitialized with <see cref="DefaultStreamProcessingBufferSize"/> by default.
/// </summary>
public int StreamProcessingBufferSize
{
get => this.streamProcessingBufferSize;
set
{
if (value < MinStreamProcessingBufferSize)
if (value <= 0)
{
value = MinStreamProcessingBufferSize;
throw new ArgumentOutOfRangeException(nameof(this.StreamProcessingBufferSize));
}
this.streamProcessingBufferSize = value;

8
tests/ImageSharp.Tests/ConfigurationTests.cs

@ -141,12 +141,10 @@ namespace SixLabors.ImageSharp.Tests
[Fact]
public void StreamBufferSize_CannotGoBelowMinimum()
{
var config = new Configuration
{
StreamProcessingBufferSize = 0
};
var config = new Configuration();
Assert.Equal(128, config.StreamProcessingBufferSize);
Assert.Throws<ArgumentOutOfRangeException>(
() => config.StreamProcessingBufferSize = 0);
}
}
}

Loading…
Cancel
Save