@@ -171,6 +171,7 @@ pub(crate) struct WasmEnvironment {
171
171
js_on_stderr : Function ,
172
172
js_glob_files : Function ,
173
173
js_read_file : Function ,
174
+ js_write_file : Function ,
174
175
js_sleep : Function ,
175
176
js_is_absolute : Function ,
176
177
js_cwd : Function ,
@@ -203,6 +204,9 @@ impl From<JsValue> for WasmEnvironment {
203
204
js_read_file : js_sys:: Reflect :: get ( & val, & JsValue :: from_str ( "js_read_file" ) )
204
205
. unwrap ( )
205
206
. into ( ) ,
207
+ js_write_file : js_sys:: Reflect :: get ( & val, & JsValue :: from_str ( "js_write_file" ) )
208
+ . unwrap ( )
209
+ . into ( ) ,
206
210
js_is_absolute : js_sys:: Reflect :: get ( & val, & JsValue :: from_str ( "js_is_absolute" ) )
207
211
. unwrap ( )
208
212
. into ( ) ,
@@ -308,6 +312,18 @@ impl Environment for WasmEnvironment {
308
312
Ok ( Uint8Array :: from ( ret) . to_vec ( ) )
309
313
}
310
314
315
+ async fn write_file ( & self , path : & Path , bytes : & [ u8 ] ) -> Result < ( ) , anyhow:: Error > {
316
+ let path_str = JsValue :: from_str ( & path. to_string_lossy ( ) ) ;
317
+ let this = JsValue :: null ( ) ;
318
+ let data = JsValue :: from ( js_sys:: Uint8Array :: from ( bytes) ) ;
319
+ let res: JsValue = self . js_write_file . call2 ( & this, & path_str, & data) . unwrap ( ) ;
320
+
321
+ JsFuture :: from ( Promise :: from ( res) )
322
+ . await
323
+ . map ( |_| ( ) )
324
+ . map_err ( |err| anyhow ! ( "{:?}" , err) )
325
+ }
326
+
311
327
fn is_absolute ( & self , path : & Path ) -> bool {
312
328
let path_str = JsValue :: from_str ( & path. to_string_lossy ( ) ) ;
313
329
let this = JsValue :: null ( ) ;
0 commit comments