1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use crate::storage::{
IntoInner,
PathGenerator,
StorageBackend,
TarArchive,
TarArchiveError,
};
type InnerObject = std::io::BufWriter<std::fs::File>;
pub struct TarFile<G: PathGenerator> {
archive: TarArchive<InnerObject, G>,
}
impl<G: PathGenerator> TarFile<G> {
pub fn new<P: AsRef<std::path::Path>>(target_path: P, path_generator: G) -> Result<Self, TarArchiveError> {
let archive = std::fs::File::create(target_path)?;
let archive = std::io::BufWriter::new(archive);
Ok(Self {
archive: TarArchive::new(archive, path_generator),
})
}
}
impl<G: PathGenerator> StorageBackend for TarFile<G> {
type Error = <TarArchive<InnerObject, G> as StorageBackend>::Error;
fn append_file(&mut self, mfile: libatm::MIDIFile, mode: Option<u32>) -> Result<(), Self::Error> {
self.archive.append_file(mfile, mode)
}
fn finish(&mut self) -> Result<(), Self::Error> {
self.archive.finish()
}
}
impl<G: PathGenerator> IntoInner for TarFile<G> {
type Inner = InnerObject;
fn into_inner(self) -> Result<Self::Inner, <Self as StorageBackend>::Error> {
self.archive.into_inner()
}
}