From 65936f8f275c838b8e0815a21264d766600aa1bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Harabie=C5=84?= Date: Fri, 22 Sep 2017 23:20:06 +0200 Subject: [PATCH] Restructure into proper crate. --- Cargo.lock | 2 +- Cargo.toml | 2 +- examples/sample.rs | 18 ++++++++++++++++++ src/dir.rs | 5 +++-- src/file.rs | 1 + src/fs.rs | 3 ++- src/lib.rs | 13 +++++++++++++ src/main.rs | 30 ------------------------------ tests/integration-test.rs | 19 +++++++++++++++++++ 9 files changed, 58 insertions(+), 35 deletions(-) create mode 100644 examples/sample.rs create mode 100644 src/lib.rs delete mode 100644 src/main.rs create mode 100644 tests/integration-test.rs diff --git a/Cargo.lock b/Cargo.lock index 741476f..b3fdc64 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,5 @@ [root] -name = "rust-fat" +name = "rustfat" version = "0.1.0" dependencies = [ "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 7fe934f..cd5763a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "rust-fat" +name = "rustfat" version = "0.1.0" authors = ["Rafał Harabień "] diff --git a/examples/sample.rs b/examples/sample.rs new file mode 100644 index 0000000..29f709e --- /dev/null +++ b/examples/sample.rs @@ -0,0 +1,18 @@ +extern crate rustfat; + +use std::fs::File; +use std::io::BufReader; +use std::str; + +use rustfat::FatFileSystem; + +fn main() { + let file = File::open("resources/floppy.img").unwrap(); + let mut buf_rdr = BufReader::new(file); + let mut fs = FatFileSystem::new(&mut buf_rdr).unwrap(); + let mut root_dir = fs.root_dir(); + let entries = fs.read_dir(&mut root_dir).unwrap(); + for e in entries { + println!("{} - size {} - modified {}", e.get_name(), e.get_size(), e.get_modify_time()); + } +} diff --git a/src/dir.rs b/src/dir.rs index b987e77..bbaa13f 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -1,11 +1,12 @@ use std::io::prelude::*; use std::io; +use std::io::Cursor; use std::str; use byteorder::{LittleEndian, ReadBytesExt}; +use chrono::{DateTime, Date, TimeZone, Local}; + use fs::FatFileSystem; use file::FatFile; -use std::io::Cursor; -use chrono::{DateTime, Date, TimeZone, Local}; #[derive(Debug, PartialEq)] #[allow(dead_code)] diff --git a/src/file.rs b/src/file.rs index 6d5b1d1..59a8d80 100644 --- a/src/file.rs +++ b/src/file.rs @@ -1,5 +1,6 @@ use std::io::prelude::*; use std::io; + use fs::FatFileSystem; #[allow(dead_code)] diff --git a/src/fs.rs b/src/fs.rs index a4cc73c..54fcd5c 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -1,8 +1,9 @@ use std::io::prelude::*; +use std::io::{Error, ErrorKind, SeekFrom}; use std::io; use std::str; -use std::io::{Error, ErrorKind, SeekFrom}; use byteorder::{LittleEndian, ReadBytesExt}; + use file::FatFile; // FAT implementation based on: diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..691f6a6 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,13 @@ +#![crate_type = "lib"] +#![crate_name = "rustfat"] + +extern crate byteorder; +extern crate chrono; + +pub mod fs; +pub mod dir; +pub mod file; + +pub use fs::*; +pub use dir::*; +pub use file::*; diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index f86ee53..0000000 --- a/src/main.rs +++ /dev/null @@ -1,30 +0,0 @@ -extern crate byteorder; -extern crate chrono; - -use std::fs::File; -use std::io::BufReader; -use std::io; -use std::str; -use fs::FatFileSystem; - -pub mod fs; -pub mod dir; -pub mod file; - -fn fat_test() -> io::Result<()> { - let file = File::open("resources/floppy.img")?; - let mut buf_rdr = BufReader::new(file); - let mut fs = FatFileSystem::new(&mut buf_rdr)?; - let mut root_dir = fs.root_dir(); - let entries = fs.read_dir(&mut root_dir)?; - for e in entries { - println!("{} - size {} - modified {}", e.get_name(), e.get_size(), e.get_modify_time()); - //println!("name {} size {} cluster {}", name_str, entry.size, entry.first_cluster_lo); - } - Ok(()) -} - -fn main() { - println!("FAT test!"); - fat_test().unwrap(); -} diff --git a/tests/integration-test.rs b/tests/integration-test.rs new file mode 100644 index 0000000..01a6c95 --- /dev/null +++ b/tests/integration-test.rs @@ -0,0 +1,19 @@ +extern crate rustfat; + +use std::fs::File; +use std::io::BufReader; +use std::str; + +use rustfat::FatFileSystem; + +#[test] +fn fat12_test() { + let file = File::open("resources/floppy.img").unwrap(); + let mut buf_rdr = BufReader::new(file); + let mut fs = FatFileSystem::new(&mut buf_rdr).unwrap(); + let mut root_dir = fs.root_dir(); + let entries = fs.read_dir(&mut root_dir).unwrap(); + assert_eq!(entries.len(), 2); + assert_eq!(entries[0].get_name(), "RAFOS"); + assert_eq!(entries[1].get_name(), "GRUB"); +}