__init__.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. from __future__ import annotations
  2. __all__ = ["Compression"]
  3. from typing import Protocol
  4. class Compression(Protocol):
  5. """Protocol for compression methods.
  6. By default, gzip compression is used. Other compression methods can be
  7. used by specifying implementations of this protocol. We provide standard
  8. implementations for:
  9. - br ([BrotliCompression][connectrpc.compression.brotli.BrotliCompression]) -
  10. requires the `brotli` dependency.
  11. - zstd ([ZstdCompression][connectrpc.compression.zstd.ZstdCompression]) -
  12. requires the `zstandard` dependency.
  13. """
  14. def name(self) -> str:
  15. """Returns the name of the compression method. This value is used in HTTP
  16. headers to indicate accepted and used compression.
  17. """
  18. ...
  19. def compress(self, data: bytes | bytearray | memoryview) -> bytes:
  20. """Compress the given data."""
  21. ...
  22. def decompress(self, data: bytes | bytearray | memoryview) -> bytes:
  23. """Decompress the given data."""
  24. ...