|
2 | 2 | using System.IO; |
3 | 3 | using System.Text; |
4 | 4 | using System.Collections.Generic; |
5 | | -using System.Runtime.InteropServices; |
6 | 5 |
|
7 | 6 | namespace Wasmtime |
8 | 7 | { |
@@ -593,6 +592,29 @@ public Module LoadModule(string path) |
593 | 592 | return LoadModule(Path.GetFileNameWithoutExtension(path), File.ReadAllBytes(path)); |
594 | 593 | } |
595 | 594 |
|
| 595 | + /// <summary> |
| 596 | + /// Loads a <see cref="Module"/> given a stream. |
| 597 | + /// </summary> |
| 598 | + /// <param name="name">The name of the module.</param> |
| 599 | + /// <param name="stream">The stream of the module data.</param> |
| 600 | + /// <returns>Returns a new <see cref="Module"/>.</returns> |
| 601 | + public Module LoadModule(string name, Stream stream) |
| 602 | + { |
| 603 | + if (string.IsNullOrEmpty(name)) |
| 604 | + { |
| 605 | + throw new ArgumentNullException(nameof(name)); |
| 606 | + } |
| 607 | + |
| 608 | + if (stream is null) |
| 609 | + { |
| 610 | + throw new ArgumentNullException(nameof(stream)); |
| 611 | + } |
| 612 | + |
| 613 | + using var ms = new MemoryStream(); |
| 614 | + stream.CopyTo(ms); |
| 615 | + return LoadModule(name, ms.ToArray()); |
| 616 | + } |
| 617 | + |
596 | 618 | /// <summary> |
597 | 619 | /// Loads a <see cref="Module"/> based on a WebAssembly text format representation. |
598 | 620 | /// </summary> |
@@ -646,6 +668,28 @@ public Module LoadModuleText(string path) |
646 | 668 | return LoadModuleText(Path.GetFileNameWithoutExtension(path), File.ReadAllText(path)); |
647 | 669 | } |
648 | 670 |
|
| 671 | + /// <summary> |
| 672 | + /// Loads a <see cref="Module"/> given stream as WebAssembly text format stream. |
| 673 | + /// </summary> |
| 674 | + /// <param name="name">The name of the module.</param> |
| 675 | + /// <param name="stream">The stream of the module data.</param> |
| 676 | + /// <returns>Returns a new <see cref="Module"/>.</returns> |
| 677 | + public Module LoadModuleText(string name, Stream stream) |
| 678 | + { |
| 679 | + if (string.IsNullOrEmpty(name)) |
| 680 | + { |
| 681 | + throw new ArgumentNullException(nameof(name)); |
| 682 | + } |
| 683 | + |
| 684 | + if (stream is null) |
| 685 | + { |
| 686 | + throw new ArgumentNullException(nameof(stream)); |
| 687 | + } |
| 688 | + |
| 689 | + using var reader = new StreamReader(stream); |
| 690 | + return LoadModuleText(name, reader.ReadToEnd()); |
| 691 | + } |
| 692 | + |
649 | 693 | /// <summary> |
650 | 694 | /// Instantiates a WebAssembly module. |
651 | 695 | /// </summary> |
|
0 commit comments