# `Alternera.PluginWasmFramework.ModuleFile`
[🔗](https://github.com/10e-ab/alternera-wasm/blob/v0.9.0/alternera_plugin_wasm_framework/lib/alternera/plugin_wasm_framework/module_file.ex#L1)

Reads the outline of a WebAssembly core module from its bytes, without
compiling it: its imports, exports, memories, whether it has a start
function, and its custom sections. The runtime binding does not expose
custom sections, and an uploaded module must be judged before anything
of it runs, so the walk is ours: the module header, then each section's
id and LEB128 length, reading only the sections it needs.

`read/1` answers what it found or the first thing it cannot read, in a
text of ours: a file that is no module, a component rather than a core
module, a section that runs past the end. It checks nothing beyond the
layout: what an uploaded module may contain is `UploadCheck`'s.

# `import`

```elixir
@type import() :: %{module: String.t(), name: String.t(), kind: atom()}
```

An import: its module and name and its kind (`:function`, `:table`,
`:memory`, `:global`, `:tag`).

# `memory`

```elixir
@type memory() :: %{
  min: non_neg_integer(),
  max: non_neg_integer() | nil,
  shared?: boolean(),
  memory64?: boolean()
}
```

A memory a module defines: its minimum and maximum in 64 KiB pages,
and whether it is shared or 64-bit.

# `t`

```elixir
@type t() :: %Alternera.PluginWasmFramework.ModuleFile{
  custom: [{String.t(), binary()}],
  exports: [%{name: String.t(), kind: atom()}],
  imports: [import()],
  memories: [memory()],
  start?: boolean()
}
```

# `custom`

```elixir
@spec custom(t(), String.t()) :: [binary()]
```

The contents of the custom sections named `name`, in file order.

# `page_bytes`

```elixir
@spec page_bytes() :: pos_integer()
```

The size of a memory page, in bytes.

# `read`

```elixir
@spec read(binary()) :: {:ok, t()} | {:error, String.t()}
```

Reads the outline of `wasm`.

---

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