aboutsummaryrefslogtreecommitdiff
path: root/src/archive.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/archive.rs')
-rw-r--r--src/archive.rs21
1 files changed, 19 insertions, 2 deletions
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 @@
1use crate::driver::{ArchiveRead, ArchiveWrite, Driver}; 1use crate::driver::{ArchiveRead, ArchiveWrite, Driver};
2use crate::ArchiveResult; 2use crate::ArchiveResult;
3use std::fs::File;
3use std::io::{Read, Write}; 4use std::io::{Read, Write};
5use std::path::Path;
4 6
5pub struct Archive<D: Driver> { 7pub struct Archive<D: Driver> {
6 pub driver: D, 8 pub(crate) driver: D,
7} 9}
8 10
9impl<D: ArchiveRead> Archive<D> 11impl<D: ArchiveRead> Archive<D>
10where 12where
11 D::IO: std::io::Read, 13 D::IO: std::io::Read,
12{ 14{
13 pub fn new(io: D::IO) -> ArchiveResult<Self, D::Error> { 15 pub fn read(io: D::IO) -> ArchiveResult<Self, D::Error> {
14 Ok(Self { 16 Ok(Self {
15 driver: D::read(io)?, 17 driver: D::read(io)?,
16 }) 18 })
17 } 19 }
20
21 pub fn read_from_file(path: impl AsRef<Path>) -> ArchiveResult<Self, D::Error>
22 where
23 D: ArchiveRead<IO = File>,
24 {
25 Self::read(File::open(path)?)
26 }
27
28 pub fn files(&self) -> Vec<&D::File> {
29 self.driver.files()
30 }
31
32 pub fn get_file(&self, name: &str) -> Option<&D::File> {
33 self.driver.get_file(name)
34 }
18} 35}
19 36
20impl<D: ArchiveWrite> Archive<D> where D::IO: Read + Write {} 37impl<D: ArchiveWrite> Archive<D> where D::IO: Read + Write {}