From a867677218c1d55dadfcac1ca5b8cd32a78a3c28 Mon Sep 17 00:00:00 2001 From: Igor Tolmachev Date: Thu, 27 Jun 2024 00:22:52 +0900 Subject: Implement file getter in archive --- src/archive.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/archive.rs') diff --git a/src/archive.rs b/src/archive.rs index fe03a12..e635007 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -1,20 +1,37 @@ use crate::driver::{ArchiveRead, ArchiveWrite, Driver}; use crate::ArchiveResult; +use std::fs::File; use std::io::{Read, Write}; +use std::path::Path; pub struct Archive { - pub driver: D, + pub(crate) driver: D, } impl Archive where D::IO: std::io::Read, { - pub fn new(io: D::IO) -> ArchiveResult { + pub fn read(io: D::IO) -> ArchiveResult { Ok(Self { driver: D::read(io)?, }) } + + pub fn read_from_file(path: impl AsRef) -> ArchiveResult + where + D: ArchiveRead, + { + Self::read(File::open(path)?) + } + + pub fn files(&self) -> Vec<&D::File> { + self.driver.files() + } + + pub fn get_file(&self, name: &str) -> Option<&D::File> { + self.driver.get_file(name) + } } impl Archive where D::IO: Read + Write {} -- cgit v1.2.3