# `Alternera.Plugin.BodyFilter`
[🔗](https://github.com/10e-ab/alternera-sdk/blob/v0.9.0/alternera_plugin_sdk/lib/alternera/plugin/body_filter.ex#L1)

A streaming step's filter: the module a `call/3` plugin declared with
`use Alternera.Plugin, streams: true` names when its `call/3` answers
`{:stream, first, {module, state}, writes}`.

The proxy feeds the step's own body through it, piece by piece, whether
the body streams or is held (`Plugin.CallAdapter`): when the walk holds,
the adapter feeds the held body in the same pieces and joins what comes
out. So the step has one code path; a setting that cannot stream does its
work in `finish/1`, on what `chunk/2` gathered.

  * `chunk(bytes, state)`: one piece of the decoded body; `{:ok, out,
    state}`, `out` the iodata that goes on.
  * `finish(state)`: after the last piece; `{:ok, last, summary}`, or
    `{:skip, last, reason}` when the step took no part: the body went on
    as it came (`last` is what the filter still held of it), and the step
    is recorded as skipped, as it would be held.
  * `abort(reason, state)` (optional): the stream ended early (a
    filter failed, the client went, the upstream broke off; `reason`
    says which), so the filter frees what it holds. At most once, and
    never after a `finish/1` that answered `:ok` or a skip.

`chunk/2` and `finish/1` may answer `{:error, type, message}`;
`malformed_body` blames the body. Streamed, what went out cannot be taken
back and the step fails; held, nothing went out, so the step skips and
the body goes on as it came.

# `abort`
*optional* 

```elixir
@callback abort(reason :: term(), state :: term()) :: :ok
```

# `chunk`

```elixir
@callback chunk(binary(), state :: term()) ::
  {:ok, iodata(), term()} | {:error, atom() | String.t(), String.t()}
```

# `finish`

```elixir
@callback finish(state :: term()) ::
  {:ok, iodata(), map()}
  | {:skip, iodata(), atom() | String.t()}
  | {:error, atom() | String.t(), String.t()}
```

---

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