See the question and my original answer on StackOverflow

To avoid the need for Python, I have forked the original brotli source here and created a Windows DLL version of it that you can use with .NET. I've added a directory that contains a "WinBrotli" Visual Studio 2015 solution with two projects:

  • WinBrotli: a Windows DLL (x86 and x64) that contains original unchanged C/C++ brotli code.
  • Brotli: a Windows Console Application (Any Cpu) written in C# that contains P/Invoke interop code for WinBrotli.

To reuse the Winbrotli DLL, just copy WinBrotli.x64.dll and WinBrotli.x86.dll (you can find already built release versions in the WinBrotli/binaries folder) aside your .NET application, and incorporate the BrotliCompression.cs file in your C# project (or port it to VB or another language if C# is not your favorite language). The interop code will automatically pick the right DLL that correspond to the current process' bitness (X86 or X64).

Once you've done that, using it is fairly simple (input and output can be file paths or standard .NET Streams):

        // compress
        BrotliCompression.Compress(input, output);

        // decompress
        BrotliCompression.Decompress(input, output);

To create WinBrotli, here's what I've done (for others that would want to use other Visual Studio versions)

  • Created a standard DLL project, removed the precompiled header
  • Included all encoder and decoder original brotli C/C++ files (never changed anything in there, so we can update the original files when needed)
  • Configured the project to remove dependencies on MSVCRT (so we don't need to deploy other DLL)
  • Disabled the 4146 warning (otherwise we just can't compile)
  • Added a very standard dllmain.cpp file that does nothing special
  • Added a WinBrotli.cpp file that exposes brotli compression and decompression code to the outside Windows world (with a very thin adaptation layer, so it's easier to interop in .NET)
  • Added a WinBrotli.def file that exports 4 functions