Rename DirReader to DirRawStream.

This commit is contained in:
Rafał Harabień 2017-10-07 15:00:27 +02:00
parent a1a2ffc2af
commit 120c9b035c
2 changed files with 14 additions and 14 deletions

View File

@ -14,25 +14,25 @@ use fs::{FileSystemRef, DiskSlice};
use file::File; use file::File;
#[derive(Clone)] #[derive(Clone)]
pub(crate) enum DirReader<'a, 'b: 'a> { pub(crate) enum DirRawStream<'a, 'b: 'a> {
File(File<'a, 'b>), File(File<'a, 'b>),
Root(DiskSlice<'a, 'b>), Root(DiskSlice<'a, 'b>),
} }
impl <'a, 'b> Read for DirReader<'a, 'b> { impl <'a, 'b> Read for DirRawStream<'a, 'b> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
match self { match self {
&mut DirReader::File(ref mut file) => file.read(buf), &mut DirRawStream::File(ref mut file) => file.read(buf),
&mut DirReader::Root(ref mut raw) => raw.read(buf), &mut DirRawStream::Root(ref mut raw) => raw.read(buf),
} }
} }
} }
impl <'a, 'b> Seek for DirReader<'a, 'b> { impl <'a, 'b> Seek for DirRawStream<'a, 'b> {
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> { fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
match self { match self {
&mut DirReader::File(ref mut file) => file.seek(pos), &mut DirRawStream::File(ref mut file) => file.seek(pos),
&mut DirReader::Root(ref mut raw) => raw.seek(pos), &mut DirRawStream::Root(ref mut raw) => raw.seek(pos),
} }
} }
} }
@ -202,7 +202,7 @@ impl <'a, 'b> DirEntry<'a, 'b> {
panic!("This is a file"); panic!("This is a file");
} }
let file = File::new(self.first_cluster(), None, self.fs); let file = File::new(self.first_cluster(), None, self.fs);
Dir::new(DirReader::File(file), self.fs) Dir::new(DirRawStream::File(file), self.fs)
} }
pub fn len(&self) -> u64 { pub fn len(&self) -> u64 {
@ -230,13 +230,13 @@ impl <'a, 'b> fmt::Debug for DirEntry<'a, 'b> {
#[derive(Clone)] #[derive(Clone)]
pub struct Dir<'a, 'b: 'a> { pub struct Dir<'a, 'b: 'a> {
rdr: DirReader<'a, 'b>, rdr: DirRawStream<'a, 'b>,
fs: FileSystemRef<'a, 'b>, fs: FileSystemRef<'a, 'b>,
} }
impl <'a, 'b> Dir<'a, 'b> { impl <'a, 'b> Dir<'a, 'b> {
pub(crate) fn new(rdr: DirReader<'a, 'b>, fs: FileSystemRef<'a, 'b>) -> Dir<'a, 'b> { pub(crate) fn new(rdr: DirRawStream<'a, 'b>, fs: FileSystemRef<'a, 'b>) -> Dir<'a, 'b> {
Dir { rdr, fs } Dir { rdr, fs }
} }
@ -286,7 +286,7 @@ impl <'a, 'b> Dir<'a, 'b> {
#[derive(Clone)] #[derive(Clone)]
pub struct DirIter<'a, 'b: 'a> { pub struct DirIter<'a, 'b: 'a> {
rdr: DirReader<'a, 'b>, rdr: DirRawStream<'a, 'b>,
fs: FileSystemRef<'a, 'b>, fs: FileSystemRef<'a, 'b>,
err: bool, err: bool,
} }

View File

@ -7,7 +7,7 @@ use std::io;
use byteorder::{LittleEndian, ReadBytesExt}; use byteorder::{LittleEndian, ReadBytesExt};
use file::File; use file::File;
use dir::{DirReader, Dir}; use dir::{DirRawStream, Dir};
use table::ClusterIterator; use table::ClusterIterator;
// FAT implementation based on: // FAT implementation based on:
@ -125,9 +125,9 @@ impl <'a> FileSystem<'a> {
pub fn root_dir<'b>(&'b self) -> Dir<'b, 'a> { pub fn root_dir<'b>(&'b self) -> Dir<'b, 'a> {
let root_rdr = { let root_rdr = {
match self.fat_type { match self.fat_type {
FatType::Fat12 | FatType::Fat16 => DirReader::Root(DiskSlice::from_sectors( FatType::Fat12 | FatType::Fat16 => DirRawStream::Root(DiskSlice::from_sectors(
self.first_data_sector - self.root_dir_sectors, self.root_dir_sectors, self)), self.first_data_sector - self.root_dir_sectors, self.root_dir_sectors, self)),
_ => DirReader::File(File::new(Some(self.boot.bpb.root_dir_first_cluster), None, self)), _ => DirRawStream::File(File::new(Some(self.boot.bpb.root_dir_first_cluster), None, self)),
} }
}; };
Dir::new(root_rdr, self) Dir::new(root_rdr, self)