# `OpenrelikWorkerCommon.TaskUtils`
[🔗](https://github.com/hacktobeer/openrelik-worker-common-elixir/blob/v0.1.0/lib/openrelik_worker_common/task_utils.ex#L15)

Helper functions for tasks (`openrelik_worker_common.task_utils`).

Provides Base64/JSON serialization of task results, input file resolution from upstream
piped results (`get_input_files/3`), and glob-based file compatibility filtering
(`filter_compatible_files/2`).

# `create_task_result`

```elixir
@spec create_task_result(keyword() | map()) :: String.t()
```

Creates a task result dictionary and encodes it to a Base64 string.

Can be called with a keyword list or map:

    create_task_result(
      output_files: output_files,
      workflow_id: workflow_id,
      task_files: [],
      command: command,
      meta: meta,
      file_reports: [],
      task_report: nil
    )

or with positional arguments matching Python's signature:

    create_task_result(
      output_files,
      workflow_id,
      task_files \\ [],
      command \\ nil,
      meta \\ nil,
      file_reports \\ [],
      task_report \\ nil
    )

# `create_task_result`

```elixir
@spec create_task_result(list(), String.t() | integer() | nil) :: String.t()
```

# `create_task_result`

```elixir
@spec create_task_result(
  list(),
  String.t() | integer() | nil,
  keyword() | map() | list()
) :: String.t()
```

# `create_task_result`

```elixir
@spec create_task_result(
  list(),
  String.t() | integer() | nil,
  list(),
  String.t() | nil,
  map() | nil,
  list(),
  map() | nil
) :: String.t()
```

# `decode_base64_to_dict`

```elixir
@spec decode_base64_to_dict(String.t()) :: map()
```

Decodes a Base64-encoded JSON string into an Elixir map.

# `encode_dict_to_base64`

```elixir
@spec encode_dict_to_base64(map()) :: String.t()
```

Encodes a map (dictionary) to a Base64-encoded JSON string.

# `filter_compatible_files`

```elixir
@spec filter_compatible_files([map()], map()) :: [map()]
```

Filters a list of file dictionaries based on compatibility with `filter_dict`,
supporting glob (`fnmatch`) matching on `"data_types"`, `"mime_types"`, and `"filenames"`.

# `fnmatch?`

```elixir
@spec fnmatch?(String.t(), String.t()) :: boolean()
```

Matches a string against a Unix shell-style wildcard pattern (`fnmatch.fnmatch`).

# `get_field`

```elixir
@spec get_field(map(), String.t()) :: term()
```

Fetches a field from a map by string key or atom key.

# `get_input_files`

```elixir
@spec get_input_files(String.t() | [String.t()] | nil, list() | nil, map() | nil) ::
  list() | term()
```

Prepares the input files for a task.

Determines the appropriate input files by checking for results from a previous task
(`pipe_result` as a single Base64-encoded string or a list of Base64-encoded strings)
and then applies any specified file filtering (`filter`).

---

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