Skip to content

Commit cd50b9c

Browse files
committedOct 8, 2018
add compileToText(File)
1 parent 0c25c89 commit cd50b9c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
 

‎src/de/inetsoftware/jwebassembly/JWebAssembly.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
import java.io.FileOutputStream;
2222
import java.io.IOException;
2323
import java.io.OutputStream;
24+
import java.io.OutputStreamWriter;
2425
import java.net.MalformedURLException;
2526
import java.net.URL;
27+
import java.nio.charset.StandardCharsets;
2628
import java.util.ArrayList;
2729
import java.util.HashMap;
2830
import java.util.List;
@@ -112,6 +114,22 @@ public String compileToText() throws WasmException {
112114
return output.toString();
113115
}
114116

117+
/**
118+
* Convert the added files to a WebAssembly module in text representation.
119+
*
120+
* @param file
121+
* the target for the module data
122+
* @throws WasmException
123+
* if any conversion error occurs
124+
*/
125+
public void compileToText( File file ) throws WasmException {
126+
try (TextModuleWriter writer = new TextModuleWriter( new OutputStreamWriter( new FileOutputStream( file ), StandardCharsets.UTF_8 ) )) {
127+
compile( writer );
128+
} catch( Exception ex ) {
129+
throw WasmException.create( ex );
130+
}
131+
}
132+
115133
/**
116134
* Convert the added files to a WebAssembly module in text representation.
117135
*

0 commit comments

Comments
 (0)