diff options
Diffstat (limited to 'src/archive.rs')
| -rw-r--r-- | src/archive.rs | 21 |
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 @@ | |||
| 1 | use crate::driver::{ArchiveRead, ArchiveWrite, Driver}; | 1 | use crate::driver::{ArchiveRead, ArchiveWrite, Driver}; |
| 2 | use crate::ArchiveResult; | 2 | use crate::ArchiveResult; |
| 3 | use std::fs::File; | ||
| 3 | use std::io::{Read, Write}; | 4 | use std::io::{Read, Write}; |
| 5 | use std::path::Path; | ||
| 4 | 6 | ||
| 5 | pub struct Archive<D: Driver> { | 7 | pub struct Archive<D: Driver> { |
| 6 | pub driver: D, | 8 | pub(crate) driver: D, |
| 7 | } | 9 | } |
| 8 | 10 | ||
| 9 | impl<D: ArchiveRead> Archive<D> | 11 | impl<D: ArchiveRead> Archive<D> |
| 10 | where | 12 | where |
| 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 | ||
| 20 | impl<D: ArchiveWrite> Archive<D> where D::IO: Read + Write {} | 37 | impl<D: ArchiveWrite> Archive<D> where D::IO: Read + Write {} |
