# `PlaywrightEx.Download`
[🔗](https://github.com/ftes/playwright_ex/blob/v0.13.0/lib/playwright_ex/download.ex#L1)

A browser download's metadata and underlying artifact.

Obtain a handle with `PlaywrightEx.Page.await_download/1` or `from_event/2`.
The browser provides `suggested_filename` and `url` when downloading starts.

`save_as/3` waits for completion and preserves the source artifact. Closing
the browser context deletes the source; saved copies belong to the caller.

# `event_opt`

```elixir
@type event_opt() :: {:connection, GenServer.name()}
```

# `opt`

```elixir
@type opt() :: {:timeout, timeout()}
```

# `t`

```elixir
@type t() :: %PlaywrightEx.Download{
  artifact_guid: PlaywrightEx.guid(),
  connection: GenServer.name(),
  page_id: PlaywrightEx.guid(),
  suggested_filename: String.t(),
  url: String.t()
}
```

# `delete`

```elixir
@spec delete(t(), [opt() | PlaywrightEx.unknown_opt()]) ::
  {:ok, any()} | {:error, any()}
```

Explicitly deletes the source download artifact. Saved copies are unaffected.

## Options
* `:timeout` (`t:timeout/0`) - Required. Operation timeout in milliseconds. `0` means no waiting; `:infinity` disables the timeout.

# `from_event`

```elixir
@spec from_event(map(), [event_opt()]) :: t()
```

Builds a download handle from a raw `:download` event without reading its file.

Pass the recorder's connection when using a non-default connection.

## Options
* `:connection` (`t:term/0`) - The Connection process name. Defaults to `PlaywrightEx.Supervisor.Connection`. The default value is `PlaywrightEx.Supervisor.Connection`.

# `save_as`

```elixir
@spec save_as(t(), Path.t(), [opt() | PlaywrightEx.unknown_opt()]) ::
  :ok | {:error, any()}
```

Saves the completed download to `path`, preserving its source artifact.

Uses the handle's connection and applies the timeout to the whole transfer.
The caller owns the saved file. See `PlaywrightEx.Artifact.save_as/3` for details.

## Options
* `:timeout` (`t:timeout/0`) - Required. Operation timeout in milliseconds. `0` means no waiting; `:infinity` disables the timeout.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
