NewModuleFromFile reads the contents of the `file` provided and interprets them as either the text format or the binary format for WebAssembly. Afterwards delegates to the `NewModule` constructor with the contents read.
(engine *Engine, file string)
| 7 | // |
| 8 | // Afterwards delegates to the `NewModule` constructor with the contents read. |
| 9 | func NewModuleFromFile(engine *Engine, file string) (*Module, error) { |
| 10 | wasm, err := os.ReadFile(file) |
| 11 | if err != nil { |
| 12 | return nil, err |
| 13 | } |
| 14 | // If this wasm isn't actually wasm, treat it as the text format and |
| 15 | // parse it as such. |
| 16 | if len(wasm) > 0 && wasm[0] != 0 { |
| 17 | wasm, err = Wat2Wasm(string(wasm)) |
| 18 | if err != nil { |
| 19 | return nil, err |
| 20 | } |
| 21 | } |
| 22 | return NewModule(engine, wasm) |
| 23 | } |