Skip to content

[API Proposal]: Add support for Brotli Large Window decompression #133018

Description

@KHDHaDi

Background and motivation

 BrotliStream  and  BrotliDecoder  currently have no way to decode streams with large window sizes. The underlying native Brotli decoder supports "Large Window Brotli", but only behind a boolean switch ( BROTLI_DECODER_PARAM_LARGE_WINDOW ) that must be set before any data is processed.

API Proposal

namespace System.IO.Compression
{
    public sealed class BrotliDecompressionOptions
    {
        public BrotliDecompressionOptions();
        public int MaxWindowLog2 { get; set; } // default: 24
    }

    public partial struct BrotliDecoder : IDisposable
    {
        public BrotliDecoder(BrotliDecompressionOptions decompressionOptions);
    }

    public sealed partial class BrotliStream : Stream
    {
        public BrotliStream(Stream stream, BrotliDecompressionOptions decompressionOptions, bool leaveOpen = false);
    }
}

API Usage

var options = new BrotliDecompressionOptions { MaxWindowLog2 = 27 };
using var brotli = new BrotliStream(pdfObjectStream, options);

using var decoder = new BrotliDecoder(new BrotliDecompressionOptions { MaxWindowLog2 = 27 });

Alternative Designs

  • bool EnableLargeWindow instead of a numeric ceiling. This maps directly onto the native switch and is the simplest possible shape.
  • A direct int maxWindowLog2 constructor overload, mirroring Zstandard, instead of requiring the options object. (Zstandard also has ZstandardDecompressionOptions with int MaxWindowLog2 inside.)
public ZstandardDecoder(int maxWindowLog2);
public ZstandardDecoder(ZstandardDictionary dictionary, int maxWindowLog2);

The equivalent for Brotli would be:

public BrotliDecoder(int maxWindowLog2);

Activity

  1. added
    api-suggestion
    on Sep 1, 2026
  2. added
    untriaged
    on Sep 1, 2026
  3. dotnet-policy-service commented on Sep 1, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @karelz, @dotnet/area-system-io-compression
    See info in area-owners.md if you want to be subscribed.

  4. rzikm commented on Sep 1, 2026

    @rzikm
    Member

    An alternative API design could expose the maximum accepted window size instead of a Boolean:

    We might prefer this one for parity with Zstandard, if the native API allows expressing such policy, or at least if it is possible to query the information before the library actually allocates the working memory for it.

    Does this require also a corresponding parameter on the encoder side? Being able to produce such payloads would simplify testing.

  5. added theissue type on Sep 1, 2026
  6. KHDHaDi commented on Sep 1, 2026

    @KHDHaDi
    Author

    Yes, I think MaxWindowLog would be the better API for parity with Zstandard.

    The native Brotli decoder only exposes BROTLI_DECODER_PARAM_LARGE_WINDOW as a Boolean; it does not provide a direct “maximum accepted window” parameter. However, the required window size is encoded in the stream header, so the .NET layer should be able to validate it against MaxWindowLog before committing to the corresponding large ring-buffer allocation. The native decoder already separates stream/window parsing from its ring-buffer allocation strategy.

    I also think a corresponding encoder-side option is useful. The reference Brotli encoder supports Large Window streams up to lgwin=30 through --large_window, while the current normal Brotli range stops at 24.

    That would allow straightforward round-trip and boundary tests, for example:

    encode with window 24 → accepted by the default decoder
    encode with window 25 → rejected with MaxWindowLog = 24, accepted with MaxWindowLog >= 25
    encode with window 30 → accepted only when explicitly allowed

    So I would favor something like BrotliDecompressionOptions.MaxWindowLog, together with an encoder option capable of producing Large Window payloads.

  7. removed
    untriaged
    on Sep 3, 2026
  8. added this to the 12.0.0 milestone on Sep 3, 2026
  9. added
    api-ready-for-review
    and removed
    api-suggestion
    on Oct 7, 2026
  10. bartonjs commented on Oct 13, 2026

    @bartonjs
    Member

    Video

    Looks good as proposed.

    namespace System.IO.Compression
    {
        public sealed class BrotliDecompressionOptions
        {
            public BrotliDecompressionOptions();
            public int MaxWindowLog2 { get; set; } // default: 24
        }
    
        public partial struct BrotliDecoder : IDisposable
        {
            public BrotliDecoder(BrotliDecompressionOptions decompressionOptions);
        }
    
        public sealed partial class BrotliStream : Stream
        {
            public BrotliStream(Stream stream, BrotliDecompressionOptions decompressionOptions, bool leaveOpen = false);
        }
    }
  11. added
    api-approved
    and removed
    api-ready-for-review
    on Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api-approvedarea-System.IO.Compression

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions