aboutsummaryrefslogtreecommitdiff
path: root/src/archive.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/archive.rs')
-rw-r--r--src/archive.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/archive.rs b/src/archive.rs
new file mode 100644
index 0000000..a1fe344
--- /dev/null
+++ b/src/archive.rs
@@ -0,0 +1,38 @@
1use crate::result::ArchiveResult;
2use std::{fs::File, path::Path};
3
4use crate::io::{ArchiveRead, ArchiveWrite};
5
6pub struct Archive<IO> {
7 io: IO,
8}
9
10impl<IO: ArchiveRead> Archive<IO> {
11 pub fn open(path: impl AsRef<Path>) -> ArchiveResult<Self>
12 where
13 IO: ArchiveRead<Reader = File>,
14 {
15 Self::reader(File::open(path)?)
16 }
17
18 pub fn reader(reader: IO::Reader) -> ArchiveResult<Self> {
19 Ok(Self {
20 io: IO::new(reader)?,
21 })
22 }
23}
24
25impl<IO: ArchiveWrite> Archive<IO> {
26 pub fn create(path: impl AsRef<Path>) -> ArchiveResult<Self>
27 where
28 IO: ArchiveWrite<Writer = File>,
29 {
30 Self::writer(File::create(path)?)
31 }
32
33 pub fn writer(writer: IO::Writer) -> ArchiveResult<Self> {
34 Ok(Self {
35 io: IO::new(writer)?,
36 })
37 }
38}