rust-fatfs/examples/cat.rs

20 lines
553 B
Rust
Raw Normal View History

extern crate fatfs;
2017-09-23 05:20:06 +08:00
2017-09-24 20:34:23 +08:00
use std::env;
2017-09-23 05:20:06 +08:00
use std::fs::File;
use std::io::{self, prelude::*};
2017-09-23 05:20:06 +08:00
use fatfs::{FileSystem, FsOptions, BufStream};
2017-09-23 05:20:06 +08:00
fn main() -> io::Result<()> {
let file = File::open("resources/fat32.img")?;
let mut buf_rdr = BufStream::new(file);
let fs = FileSystem::new(&mut buf_rdr, FsOptions::new())?;
2017-09-23 05:20:06 +08:00
let mut root_dir = fs.root_dir();
let mut file = root_dir.open_file(&env::args().nth(1).unwrap())?;
2017-09-24 20:34:23 +08:00
let mut buf = vec![];
file.read_to_end(&mut buf)?;
print!("{}", String::from_utf8_lossy(&buf));
Ok(())
2017-09-23 05:20:06 +08:00
}