Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking change]: BrotliStream ctor no longer allows values not defined in CompressionLevel enum #32620

Closed
1 of 2 tasks
jozkee opened this issue Nov 16, 2022 · 1 comment · Fixed by #32670
Closed
1 of 2 tasks
Assignees
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

Comments

@jozkee
Copy link
Member

jozkee commented Nov 16, 2022

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:

BrotliStream brotli = new BrotliStream(baseStream,
                                       CompressionMode.Compress,
                                       leaveOpen,
                                       bufferSize,
                                       (CompressionLevel)5); // Use level 5

New behavior

BrotliStream only allows the values defined in CompressionLevel, passing an undefined defined will result in an ArgumentException.

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load/execute or different run-time behavior.
  • Source incompatible: Source code may encounter a breaking change in behavior when targeting the new runtime/component/SDK, such as compile errors or different run-time behavior.

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

public BrotliStream (System.IO.Stream stream, System.IO.Compression.CompressionLevel compressionLevel);
public BrotliStream (System.IO.Stream stream, System.IO.Compression.CompressionMode mode);
public BrotliStream (System.IO.Stream stream, System.IO.Compression.CompressionLevel compressionLevel, bool leaveOpen);
public BrotliStream (System.IO.Stream stream, System.IO.Compression.CompressionMode mode, bool leaveOpen);
@jozkee jozkee added doc-idea Indicates issues that are suggestions for new topics [org][type][category] breaking-change Indicates a .NET Core breaking change Pri1 High priority, do before Pri2 and Pri3 labels Nov 16, 2022
@dotnet-bot dotnet-bot added binary incompatible Existing binaries may encounter a breaking change in behavior. ⌚ Not Triaged Not triaged labels Nov 16, 2022
@gewarren gewarren added 🏁 Release: .NET 7 Work items for the .NET 7 release and removed ⌚ Not Triaged Not triaged labels Nov 16, 2022
@jozkee
Copy link
Member Author

jozkee commented Nov 18, 2022

I listed all ctors as affected APIs, it should only be the ones with compressionLevel argument. Sorry.

@ghost ghost added the in-pr This issue will be closed (fixed) by an active pull request. label Nov 18, 2022
@ghost ghost removed the in-pr This issue will be closed (fixed) by an active pull request. label Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants