Validate CompressionLevel for BrotliStream

The CompressionLevel argument that's passed to BrotliStream constructors is now validated to be one of the defined values of the enumeration.

Previous behavior

Passing any value between 0 and 11 for the CompressionLevel parameter was considered valid. The value would either map to one of the enumeration's defined values or be passed as-is to the underlying Brotli implementation.

New behavior

The only valid values for the CompressionLevel parameter of BrotliStream constructors are:

If you pass any other value, an ArgumentException is thrown at run time.

Version introduced

.NET 7

Type of breaking change

This change can affect binary compatibility.

Reason for change

Being able to pass arbitrary values that aren't defined by the CompressionLevel enumeration is unexpected and undocumented, and is likely to lead to mistakes.

If necessary, change your code to pass in one of the valid CompressionLevel values.

Affected APIs