BaileysEx.Media.Download (baileys_ex v0.1.0-alpha.9)

Copy Markdown View Source

Download and decrypt WhatsApp CDN media referenced by media message structs.

Summary

Functions

Download and decrypt media referenced by a WhatsApp media message.

Download and decrypt media directly to a file path without buffering the full media body in memory.

Types

download_error()

@type download_error() ::
  :missing_media_key
  | :missing_media_url
  | :unknown_media_type
  | :invalid_media_payload
  | :invalid_padding
  | {:http_error, pos_integer(), term()}

media_message()

@type media_message() :: %{
  optional(:__struct__) => module(),
  optional(:url) => binary(),
  optional(:direct_path) => binary(),
  optional(:media_key) => binary()
}

Functions

download(media_message, opts \\ [])

@spec download(
  media_message(),
  keyword()
) :: {:ok, binary()} | {:error, download_error()}

Download and decrypt media referenced by a WhatsApp media message.

Supports :start_byte and :end_byte options for Baileys-style ranged media downloads. :end_byte is an exclusive upper bound.

The streamed path decrypts aligned AES-CBC chunks on the fly and does not validate the trailing 10-byte media MAC. For full-payload MAC verification, use BaileysEx.Media.Crypto.decrypt/3.

download_to_file(media_message, path, opts \\ [])

@spec download_to_file(media_message(), Path.t(), keyword()) ::
  {:ok, Path.t()} | {:error, download_error()}

Download and decrypt media directly to a file path without buffering the full media body in memory.

Like download/2, this uses chunked AES-CBC decryption and does not verify the trailing media MAC while streaming.