I have an input file opened as a BufReader
in Rust. Now I'd like to copy a specific range of bytes into a new output file. What would be the idiomatic way to do this in Rust v1.24?
use std::io::{self, BufReader, BufWriter, SeekFrom, Seek};
use std::fs::File;
fn copy_file_range(input_file: &str, output_file: &str, offset: u64, length: u64) -> io::Result<bool> {
let f = File::open(input_file).expect("Cannot open input file");
let mut reader = BufReader::new(f);
let f = File::create(output_file).expect("Cannot create output file");
let mut writer = BufWriter::new(f);
reader.seek(SeekFrom::Start(offset))?;
// ...
Ok(true)
}