diff options
| author | Igor Tolmachov <me@igorek.dev> | 2023-08-17 15:34:47 +0900 |
|---|---|---|
| committer | Igor Tolmachev <me@igorek.dev> | 2024-06-23 15:34:32 +0900 |
| commit | d8be93a740e8cc8103c4f9e260a62244eba1a6a4 (patch) | |
| tree | acc3b3b7f86fa3e2e4e8656d554efa62a24aa3f7 /src/archive.rs | |
| parent | 22dad8c7431d0ca94acc51d161e7f4ad5a4b1f5d (diff) | |
| download | archivator-d8be93a740e8cc8103c4f9e260a62244eba1a6a4.tar.gz archivator-d8be93a740e8cc8103c4f9e260a62244eba1a6a4.zip | |
Add basic lib architecture
Diffstat (limited to 'src/archive.rs')
| -rw-r--r-- | src/archive.rs | 38 |
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 @@ | |||
| 1 | use crate::result::ArchiveResult; | ||
| 2 | use std::{fs::File, path::Path}; | ||
| 3 | |||
| 4 | use crate::io::{ArchiveRead, ArchiveWrite}; | ||
| 5 | |||
| 6 | pub struct Archive<IO> { | ||
| 7 | io: IO, | ||
| 8 | } | ||
| 9 | |||
| 10 | impl<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 | |||
| 25 | impl<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 | } | ||
