poe_data_tools_cli/commands/cat.rs
1use std::io::{self, BufWriter, Write};
2
3use anyhow::{Context, Result};
4use poe_data_tools::fs::{FS, FileSystem};
5
6/// Write the contents of the file to stdout
7pub fn cat_file(fs: &mut FS, path: &str) -> Result<()> {
8 let contents = fs.read(path).context("Failed to read file")?;
9
10 let mut stdout = BufWriter::new(io::stdout().lock());
11 stdout
12 .write_all(&contents)
13 .context("Failed to write to stdout")?;
14
15 stdout.flush().context("Failed to flush stdout")
16}