Fix some logic errors, use some of the read/write methods previously set
up
This commit is contained in:
parent
458e572bb0
commit
d69198d7f8
14
src/lib.rs
14
src/lib.rs
@ -232,7 +232,7 @@ impl File {
|
|||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum FileType {
|
pub enum FileType {
|
||||||
Normal = 0,
|
Normal(File),
|
||||||
HardLink(String),
|
HardLink(String),
|
||||||
SoftLink(String),
|
SoftLink(String),
|
||||||
Directory,
|
Directory,
|
||||||
@ -246,7 +246,10 @@ impl FileType {
|
|||||||
let mut buf = [0; 1];
|
let mut buf = [0; 1];
|
||||||
reader.read_exact(&mut buf)?;
|
reader.read_exact(&mut buf)?;
|
||||||
match buf[0] {
|
match buf[0] {
|
||||||
0 => Ok(Self::Normal),
|
0 => {
|
||||||
|
let file = File::read(reader)?;
|
||||||
|
Ok(Self::Normal(file))
|
||||||
|
},
|
||||||
1 => {
|
1 => {
|
||||||
let mut len = [0; 8];
|
let mut len = [0; 8];
|
||||||
reader.read_exact(&mut len)?;
|
reader.read_exact(&mut len)?;
|
||||||
@ -283,7 +286,12 @@ impl FileType {
|
|||||||
|
|
||||||
pub fn write<T: Write>(&self, writer: &mut T) -> Result<(), Error> {
|
pub fn write<T: Write>(&self, writer: &mut T) -> Result<(), Error> {
|
||||||
match self {
|
match self {
|
||||||
Self::Normal => writer.write_all(&[0])?,
|
Self::Normal(f) => {
|
||||||
|
writer.write_all(&[0])?;
|
||||||
|
writer.write_all(&f.len.to_le_bytes())?;
|
||||||
|
f.checksum.write(writer)?;
|
||||||
|
writer.write_all(&f.data)?;
|
||||||
|
},
|
||||||
Self::HardLink(s) => {
|
Self::HardLink(s) => {
|
||||||
writer.write_all(&[1])?;
|
writer.write_all(&[1])?;
|
||||||
let len = s.len() as u64;
|
let len = s.len() as u64;
|
||||||
|
Loading…
Reference in New Issue
Block a user