Pristine.Ports.Compression behaviour (Pristine v0.3.0)

Copy Markdown View Source

Compression boundary for request/response payloads.

Implementations handle encoding and decoding of compressed data, typically gzip for HTTP request/response bodies.

Summary

Callbacks

Compresses binary data.

Returns the content encoding identifier for this compression type.

Decompresses binary data.

Callbacks

compress(binary, keyword)

@callback compress(binary(), keyword()) :: {:ok, binary()} | {:error, term()}

Compresses binary data.

Options

Options are implementation-specific. Common options may include:

  • :level - Compression level (implementation-dependent)

Returns

  • {:ok, compressed} - Successfully compressed binary
  • {:error, reason} - Compression failed

content_encoding()

@callback content_encoding() :: String.t()

Returns the content encoding identifier for this compression type.

Used for HTTP Content-Encoding headers.

Examples

  • Gzip adapter returns "gzip"
  • Deflate adapter would return "deflate"

decompress(binary, keyword)

@callback decompress(binary(), keyword()) :: {:ok, binary()} | {:error, term()}

Decompresses binary data.

Options

Options are implementation-specific.

Returns

  • {:ok, decompressed} - Successfully decompressed binary
  • {:error, reason} - Decompression failed (e.g., invalid data)