[Breaking change]: BrotliStream ctor no longer allows values not defined in CompressionLevel enum #32620
Closed
1 of 2 tasks
Labels
binary incompatible
Existing binaries may encounter a breaking change in behavior.
breaking-change
Indicates a .NET Core breaking change
🏁 Release: .NET 7
Work items for the .NET 7 release
doc-idea
Indicates issues that are suggestions for new topics [org][type][category]
Pri1
High priority, do before Pri2 and Pri3
Description
BrotliStream ctor no longer allows values not defined in CompressionLevel enum, an ArgumentException is thrown if that's the case.
Version
.NET 7
Previous behavior
BrotliStream allowed to pass in the level to the ctor by casting the desired level directly to CompressionLevel, like this:
New behavior
BrotliStream only allows the values defined in CompressionLevel, passing an undefined defined will result in an
ArgumentException
.Type of breaking change
Reason for change
The purpose of the CompressionLevel enumeration is to let folks use compression algorithms without needing to understand the meaning of their tuning parameters.
If an arbitrary level was provided, that was passed through as-is to the underlying library, resulting in inconsistent and potentially unexpected behavior. With this change the behavior is aligned with other compression streams e.g:
DeflateStream
.With the tuning of the CompressionLevel values made in dotnet/runtime#72266 and with the addition of
CompressionLevel.SmallestSize
dotnet/runtime#41960, it is now possible to have a variety of trade-offs in the compression algorithms and users can keep relying in CompressionLevel as being an abstraction of such trade-off.Recommended action
If you were relying in passing undefined values as the CompressionLevel, be advised that you need to re-visit your use case and decide which documented value is the most optimal for it.
Feature area
Core .NET libraries
Affected APIs
The text was updated successfully, but these errors were encountered: