PeachDrawing.Text
PeachDrawing.Text.Compression
BrotliCompression Class
A pluggable Brotli encoder, the counterpart of BrotliDecompression. By default PeachDrawing.Text compresses with .NET’s own System.IO.Compression.BrotliEncoder. On a host where that throws System.PlatformNotSupportedException - WebAssembly in a browser, at the time of writing - TryCompress(ReadOnlySpan<byte>, int, byte[]) reports failure (and IsAvailable is false) so a caller can fall back to another compression; call SetCompressor(Func<Stream,int,Stream>) once to supply a managed Brotli encoder instead and recover Brotli output on such a host.
public static class BrotliCompression
Inheritance System.Object → BrotliCompression
| Properties | |
|---|---|
| IsAvailable | Whether Brotli compression works on this host: a custom compressor is registered, or the .NET runtime’s own encoder is supported. |
| Methods | |
|---|---|
| SetCompressor(Func<Stream,int,Stream>) | Registers compressor as the encoder used in place of the .NET runtime’s own Brotli support. It receives the destination System.IO.Stream and the Brotli quality (0-11) and returns a writable System.IO.Stream: bytes written to it are Brotli-compressed into the destination, and disposing it completes the Brotli data. It must leave the destination open; PeachDrawing.Text disposes the destination itself. Pass null to go back to the default. |
| TryCompress(ReadOnlySpan<byte>, int, byte[]) | Compresses data as one Brotli stream. Returns false (and an empty array) when no encoder is available or compression failed; it does not throw for either. |