Store the file handle in our internal File type
This commit is contained in:
parent
7faa693d5c
commit
263a3b7780
1 changed files with 18 additions and 0 deletions
|
@ -5,6 +5,8 @@ use std::fmt;
|
||||||
use super::parser::{FileHeaderParser, Parser, ParserError};
|
use super::parser::{FileHeaderParser, Parser, ParserError};
|
||||||
use storage::file_id::*;
|
use storage::file_id::*;
|
||||||
|
|
||||||
|
use std::fs::File as FSFile;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum FileHeaderSpec {
|
pub enum FileHeaderSpec {
|
||||||
Null,
|
Null,
|
||||||
|
@ -167,6 +169,7 @@ pub struct File {
|
||||||
header : FileHeaderData,
|
header : FileHeaderData,
|
||||||
data : String,
|
data : String,
|
||||||
id : FileID,
|
id : FileID,
|
||||||
|
handle : Option<FSFile>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> File {
|
impl<'a> File {
|
||||||
|
@ -180,9 +183,24 @@ impl<'a> File {
|
||||||
header: h,
|
header: h,
|
||||||
data: d,
|
data: d,
|
||||||
id: from_path_string(path),
|
id: from_path_string(path),
|
||||||
|
handle: None,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_handle(id: FileID, f: FSFile) -> File {
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
|
let mut contents = String::new();
|
||||||
|
f.read_to_string(&mut contents);
|
||||||
|
|
||||||
|
File {
|
||||||
|
header: FileHeaderData::Null,
|
||||||
|
data: contents,
|
||||||
|
id: id,
|
||||||
|
handle: Some(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn getID(&self) -> FileID {
|
fn getID(&self) -> FileID {
|
||||||
self.id.clone()
|
self.id.clone()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue