mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-21 08:41:35 +00:00
Use std::fs
read/write conveniences
In addition to being more ergonomic these are much more efficient at reading large files as they preallocate internally. This provides a nice speed boost locally, reducing the overhead of `wasm-bindgen-test-runner` from 0.23s to 0.19s, yay!
This commit is contained in:
@ -4,8 +4,7 @@ extern crate wasm_bindgen_cli_support;
|
||||
extern crate parity_wasm;
|
||||
|
||||
use std::env;
|
||||
use std::fs::{self, File};
|
||||
use std::io::{Write, Read};
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::process::{self, Command};
|
||||
|
||||
@ -107,9 +106,7 @@ fn rmain() -> Result<(), Error> {
|
||||
// Note that we're collecting *JS objects* that represent the functions to
|
||||
// execute, and then those objects are passed into wasm for it to execute
|
||||
// when it sees fit.
|
||||
let mut wasm = Vec::new();
|
||||
File::open(&wasm_file_to_test)
|
||||
.and_then(|mut f| f.read_to_end(&mut wasm))
|
||||
let wasm = fs::read(&wasm_file_to_test)
|
||||
.context("failed to read wasm file")?;
|
||||
let wasm = Module::deserialize(&mut &wasm[..])
|
||||
.context("failed to deserialize wasm module")?;
|
||||
@ -136,8 +133,7 @@ fn rmain() -> Result<(), Error> {
|
||||
.context("executing `wasm-bindgen` over the wasm file")?;
|
||||
|
||||
let js_path = tmpdir.join("run.js");
|
||||
File::create(&js_path)
|
||||
.and_then(|mut f| f.write_all(js_to_execute.as_bytes()))
|
||||
fs::write(&js_path, js_to_execute)
|
||||
.context("failed to write JS file")?;
|
||||
|
||||
// Last but not least, execute `node`! Add an entry to `NODE_PATH` for the
|
||||
|
@ -4,8 +4,7 @@ extern crate docopt;
|
||||
extern crate failure;
|
||||
extern crate wasm_bindgen_cli_support;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::{Read, Write};
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::process;
|
||||
|
||||
@ -58,9 +57,7 @@ fn main() {
|
||||
}
|
||||
|
||||
fn rmain(args: &Args) -> Result<(), Error> {
|
||||
let mut wasm = Vec::new();
|
||||
File::open(&args.arg_input)
|
||||
.and_then(|mut f| f.read_to_end(&mut wasm))
|
||||
let wasm = fs::read(&args.arg_input)
|
||||
.with_context(|_| format!("failed to read `{}`", args.arg_input.display()))?;
|
||||
|
||||
let object = wasm_bindgen_cli_support::wasm2es6js::Config::new()
|
||||
@ -73,8 +70,7 @@ fn rmain(args: &Args) -> Result<(), Error> {
|
||||
if let Some(ref p) = args.flag_output {
|
||||
let dst = p.with_extension("d.ts");
|
||||
let ts = object.typescript();
|
||||
File::create(&dst)
|
||||
.and_then(|mut f| f.write_all(ts.as_bytes()))
|
||||
fs::write(&dst, ts)
|
||||
.with_context(|_| format!("failed to write `{}`", dst.display()))?;
|
||||
}
|
||||
}
|
||||
@ -83,8 +79,7 @@ fn rmain(args: &Args) -> Result<(), Error> {
|
||||
|
||||
match args.flag_output {
|
||||
Some(ref p) => {
|
||||
File::create(p)
|
||||
.and_then(|mut f| f.write_all(js.as_bytes()))
|
||||
fs::write(p, js)
|
||||
.with_context(|_| format!("failed to write `{}`", p.display()))?;
|
||||
}
|
||||
None => {
|
||||
|
Reference in New Issue
Block a user