diff --git a/.editorconfig b/.editorconfig index 53ba635..5d37088 100644 --- a/.editorconfig +++ b/.editorconfig @@ -41,8 +41,12 @@ csharp_style_var_elsewhere = true:suggestion # Disallow throw expressions. csharp_style_throw_expression = false:suggestion +# Ignore Use 'ArgumentNullException.ThrowIfNull'. We have to support older .net +dotnet_diagnostic.CA1510.severity = none + # Newline settings csharp_new_line_before_open_brace = all + csharp_new_line_before_else = true csharp_new_line_before_catch = true csharp_new_line_before_finally = true @@ -53,7 +57,7 @@ csharp_new_line_before_members_in_anonymous_types = true csharp_style_namespace_declarations = file_scoped # Brace settings -csharp_prefer_braces = true # Prefer curly braces even for one line of code +csharp_prefer_braces = when_multiline # name all constant fields using PascalCase dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion @@ -66,11 +70,10 @@ dotnet_naming_style.pascal_case_style.capitalization = pascal_case # internal and private fields should be _camelCase dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields -dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style +dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case dotnet_naming_symbols.private_internal_fields.applicable_kinds = field dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal -dotnet_naming_style.camel_case_underscore_style.required_prefix = _ -dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case + [*.{xml,config,*proj,nuspec,props,resx,targets,yml,tasks}] indent_size = 2 @@ -457,4 +460,4 @@ dotnet_diagnostic.IDE0161.severity = silent [{**/Shared/**.cs,**/microsoft.extensions.hostfactoryresolver.sources/**.{cs,vb}}] # IDE0005: Remove unused usings. Ignore for shared src files since imports for those depend on the projects in which they are included. -dotnet_diagnostic.IDE0005.severity = silent \ No newline at end of file +dotnet_diagnostic.IDE0005.severity = silent diff --git a/src/Imageflow/Fluent/StreamDestination.cs b/src/Imageflow/Fluent/StreamDestination.cs index 8fca871..fdd199c 100644 --- a/src/Imageflow/Fluent/StreamDestination.cs +++ b/src/Imageflow/Fluent/StreamDestination.cs @@ -52,6 +52,7 @@ public void Write(ReadOnlySpan bytes) public Task FlushAsync(CancellationToken cancellationToken) { ObjectDisposedHelper.ThrowIf(_underlying == null, this); + // Truncate the stream if it's seekable and we haven't written to the end if (_underlying is { CanSeek: true, CanWrite: true } && _underlying.Position < _underlying.Length) { diff --git a/tests/Imageflow.Test/Imageflow.Test.csproj b/tests/Imageflow.Test/Imageflow.Test.csproj index d3c83c8..843dbb8 100644 --- a/tests/Imageflow.Test/Imageflow.Test.csproj +++ b/tests/Imageflow.Test/Imageflow.Test.csproj @@ -22,9 +22,9 @@ - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -42,4 +42,4 @@ - \ No newline at end of file + diff --git a/tests/Imageflow.Test/NonSeekableReadStream.cs b/tests/Imageflow.Test/NonSeekableReadStream.cs index c3fac57..4ed2d0e 100644 --- a/tests/Imageflow.Test/NonSeekableReadStream.cs +++ b/tests/Imageflow.Test/NonSeekableReadStream.cs @@ -6,7 +6,7 @@ public class NonSeekableReadStream : Stream { private byte[] data; - private long position = 0; // Current position within the data + private long position; // =0 Current position within the data public NonSeekableReadStream(byte[] dataSource) { @@ -33,7 +33,8 @@ public override void Flush() public override int Read(byte[] buffer, int offset, int count) { if (buffer == null) throw new ArgumentNullException(nameof(buffer)); - if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException("offset or count is negative."); + if (offset < 0) throw new ArgumentOutOfRangeException(nameof(offset), "offset or count is negative."); + if (count < 0) throw new ArgumentOutOfRangeException(nameof(count), "count is negative."); if (buffer.Length - offset < count) throw new ArgumentException("The sum of offset and count is greater than the buffer length."); int available = data.Length - (int)position; diff --git a/tests/Imageflow.Test/TestApi.cs b/tests/Imageflow.Test/TestApi.cs index e3b5464..a4be8e4 100644 --- a/tests/Imageflow.Test/TestApi.cs +++ b/tests/Imageflow.Test/TestApi.cs @@ -21,7 +21,7 @@ public TestApi(ITestOutputHelper output) [Fact] [Obsolete("Obsolete")] - public async void TestGetImageInfoLegacy() + public async Task TestGetImageInfoLegacy() { var imageBytes = Convert.FromBase64String( "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/TQBcNTh/AAAAAXRSTlPM0jRW/QAAAApJREFUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII="); @@ -37,7 +37,7 @@ public async void TestGetImageInfoLegacy() // test the new GetImageInfoAsync [Fact] - public async void TestGetImageInfoAsync() + public async Task TestGetImageInfoAsync() { var imageBytes = Convert.FromBase64String( "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/TQBcNTh/AAAAAXRSTlPM0jRW/QAAAApJREFUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII=");