Skip to content

Commit 0a2d722

Browse files
authored
compressionlevel verification (#32670)
1 parent 953e161 commit 0a2d722

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

docs/core/compatibility/7.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ If you're migrating an app to .NET 7, the breaking changes listed here might aff
4040
| [API obsoletions with default diagnostic ID](core-libraries/7.0/obsolete-apis-with-default-diagnostic.md) | ✔️ || Preview 3 |
4141
| [API obsoletions with non-default diagnostic IDs](core-libraries/7.0/obsolete-apis-with-custom-diagnostics.md) | ✔️ || Preview 1 |
4242
| [BinaryFormatter serialization APIs produce compiler errors](core-libraries/7.0/binaryformatter-apis-produce-errors.md) | ✔️ || RC 1 |
43+
| [BrotliStream no longer allows undefined CompressionLevel values](core-libraries/7.0/brotlistream-ctor.md) || ✔️ | |
4344
| [C++/CLI projects in Visual Studio](core-libraries/7.0/cpluspluscli-compiler-version.md) | ✔️ || Preview 3 |
4445
| [Changes to reflection invoke API exceptions](core-libraries/7.0/reflection-invoke-exceptions.md) || ✔️ | Preview 4 |
4546
| [Collectible Assembly in non-collectible AssemblyLoadContext](core-libraries/7.0/collectible-assemblies.md) || ✔️ | Preview 5 |
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: ".NET 7 breaking change: BrotliStream no longer allows undefined CompressionLevel values"
3+
description: Learn about the .NET 7 breaking change in core .NET libraries where the BrotliStream constructors no longer allow undefined CompressionLevel values.
4+
ms.date: 11/18/2022
5+
---
6+
# BrotliStream no longer allows undefined CompressionLevel values
7+
8+
The <xref:System.IO.Compression.BrotliStream> constructors that take a <xref:System.IO.Compression.CompressionLevel> argument no longer allow values that aren't defined in the <xref:System.IO.Compression.CompressionLevel> enumeration. If you pass an invalid value, an <xref:System.ArgumentException> is thrown.
9+
10+
## Previous behavior
11+
12+
<xref:System.IO.Compression.BrotliStream> allowed you to pass an arbitrary compression level to the constructor by casting the desired level directly to <xref:System.IO.Compression.CompressionLevel>. For example:
13+
14+
```csharp
15+
BrotliStream brotli = new BrotliStream(baseStream,
16+
(CompressionLevel)5); // Use level 5
17+
```
18+
19+
However, if an arbitrary level was provided, that was passed through as-is to the underlying library, resulting in inconsistent and potentially unexpected behavior.
20+
21+
## New behavior
22+
23+
<xref:System.IO.Compression.BrotliStream> only allows the values defined in <xref:System.IO.Compression.CompressionLevel>. If you pass an undefined value to the constructor, an <xref:System.ArgumentException> is thrown.
24+
25+
## Version introduced
26+
27+
.NET 7
28+
29+
## Type of breaking change
30+
31+
This change can affect [binary compatibility](../../categories.md#binary-compatibility).
32+
33+
## Reason for change
34+
35+
The purpose of the <xref:System.IO.Compression.CompressionLevel> enumeration is to let developers use compression algorithms without needing to understand the meaning of their tuning parameters.
36+
37+
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, for example, <xref:System.IO.Compression.DeflateStream>.
38+
39+
With the new tuning of the <xref:System.IO.Compression.CompressionLevel> values and the addition of <xref:System.IO.Compression.CompressionLevel.SmallestSize?displayProperty=nameWithType>, it's now possible to have a variety of trade-offs in the compression algorithms. Users can continue to rely on <xref:System.IO.Compression.CompressionLevel> values as being abstractions of such trade-offs.
40+
41+
## Recommended action
42+
43+
If you were relying on passing undefined values as the <xref:System.IO.Compression.CompressionLevel>, revisit your use case and decide which documented value is the most optimal for it.
44+
45+
## Affected APIs
46+
47+
- <xref:System.IO.Compression.BrotliStream.%23ctor(System.IO.Stream,System.IO.Compression.CompressionLevel,System.Boolean)>
48+
- <xref:System.IO.Compression.BrotliStream.%23ctor(System.IO.Stream,System.IO.Compression.CompressionLevel)>

docs/core/compatibility/toc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ items:
6161
href: core-libraries/7.0/obsolete-apis-with-custom-diagnostics.md
6262
- name: BinaryFormatter serialization APIs produce compiler errors
6363
href: core-libraries/7.0/binaryformatter-apis-produce-errors.md
64+
- name: BrotliStream no longer allows undefined CompressionLevel values
65+
href: core-libraries/7.0/brotlistream-ctor.md
6466
- name: C++/CLI projects in Visual Studio
6567
href: core-libraries/7.0/cpluspluscli-compiler-version.md
6668
- name: Collectible Assembly in non-collectible AssemblyLoadContext
@@ -869,6 +871,8 @@ items:
869871
href: core-libraries/7.0/obsolete-apis-with-custom-diagnostics.md
870872
- name: BinaryFormatter serialization APIs produce compiler errors
871873
href: core-libraries/7.0/binaryformatter-apis-produce-errors.md
874+
- name: BrotliStream no longer allows undefined CompressionLevel values
875+
href: core-libraries/7.0/brotlistream-ctor.md
872876
- name: C++/CLI projects in Visual Studio
873877
href: core-libraries/7.0/cpluspluscli-compiler-version.md
874878
- name: Collectible Assembly in non-collectible AssemblyLoadContext

0 commit comments

Comments
 (0)