diff --git a/src/node.rs b/src/node.rs index 2877c17..c6e7b7a 100644 --- a/src/node.rs +++ b/src/node.rs @@ -170,9 +170,8 @@ impl Node { } else if kind == Kind::Pipe { break 'blk FileType::Fifo; } else if kind == Kind::Normal { - let mut len = meta.len(); - let mut data = Vec::with_capacity(len.try_into()?); - len = reader.read_to_end(&mut data)?.try_into()?; + let mut data = vec![]; + let len = reader.read_to_end(&mut data)?.try_into()?; let checksum = match algorithm { Algorithm::Md5 => { let mut hasher = Md5::new(); @@ -319,9 +318,13 @@ mod tests { fn from_path() { let links = Mutex::new(HashMap::new()); let node = Node::from_path("test/li.txt", Algorithm::Sha256, &links).unwrap(); - let FileType::Normal(f) = node.filetype else { panic!() }; + let FileType::Normal(f) = node.filetype else { + panic!() + }; assert_eq!(f.len, 1005); - let Checksum::Sha256(sum) = f.checksum else { panic!() }; + let Checksum::Sha256(sum) = f.checksum else { + panic!() + }; let mut s = String::new(); for c in &sum { write!(s, "{c:02x}").unwrap(); @@ -344,8 +347,12 @@ mod tests { let fd = std::fs::File::open("test/li.node").unwrap(); let mut reader = BufReader::new(fd); let node = Node::read(&mut reader).unwrap(); - let FileType::Normal(f) = node.filetype else { panic!() }; - let Checksum::Sha1(sum) = f.checksum else { panic!() }; + let FileType::Normal(f) = node.filetype else { + panic!() + }; + let Checksum::Sha1(sum) = f.checksum else { + panic!() + }; let mut s = String::new(); for c in &sum { write!(s, "{c:02x}").unwrap();