| 42 | } |
| 43 | |
| 44 | pub fn write_output_bytes(output: &str, bytes: &[u8], force: bool) -> Result<()> { |
| 45 | if output == "-" { |
| 46 | std::io::stdout().write_all(bytes)?; |
| 47 | std::io::stdout().flush()?; |
| 48 | return Ok(()); |
| 49 | } |
| 50 | |
| 51 | let path = Path::new(output); |
| 52 | if path.exists() && !force { |
| 53 | bail!("output file already exists: {output}; pass --force to overwrite") |
| 54 | } |
| 55 | |
| 56 | std::fs::write(path, bytes).with_context(|| format!("failed to write output file `{output}`"))?; |
| 57 | Ok(()) |
| 58 | } |
| 59 | |
| 60 | fn load_module_from_bytes(input: &str, bytes: &[u8]) -> Result<LoadedModule> { |
| 61 | if bytes.starts_with(b"TWAS") { |