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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
use crate::{
condow_client::CondowClient,
errors::{CondowError, GetSizeError},
reporter::{NoReporter, Reporter, ReporterFactory},
streams::{ChunkStream, PartStream},
Condow, DownloadRange, GetSizeMode, Outcome,
};
pub struct Downloader<C: CondowClient, RF: ReporterFactory = NoReporter> {
pub get_size_mode: GetSizeMode,
condow: Condow<C, RF>,
}
impl<C: CondowClient, RF: ReporterFactory> Downloader<C, RF> {
pub(crate) fn new(condow: Condow<C, RF>) -> Self {
Self {
condow,
get_size_mode: GetSizeMode::default(),
}
}
}
impl<C: CondowClient, RF: ReporterFactory> Downloader<C, RF> {
pub fn get_size_mode<T: Into<GetSizeMode>>(mut self, get_size_mode: T) -> Self {
self.get_size_mode = get_size_mode.into();
self
}
pub async fn download<R: Into<DownloadRange>>(
&self,
location: C::Location,
range: R,
) -> Result<PartStream<ChunkStream>, CondowError> {
self.download_chunks(location, range)
.await
.and_then(PartStream::from_chunk_stream)
}
pub async fn download_chunks<R: Into<DownloadRange>>(
&self,
location: C::Location,
range: R,
) -> Result<ChunkStream, CondowError> {
self.condow
.download_chunks_internal(location, range, self.get_size_mode, NoReporter)
.await
.map(|o| o.stream)
}
pub async fn download_rep<R: Into<DownloadRange>>(
&self,
location: C::Location,
range: R,
) -> Result<Outcome<PartStream<ChunkStream>, RF::ReporterType>, CondowError> {
let reporter = self.condow.reporter_factory.make();
self.download_wrep(location, range, reporter).await
}
pub async fn download_chunks_rep<R: Into<DownloadRange>>(
&self,
location: C::Location,
range: R,
) -> Result<Outcome<ChunkStream, RF::ReporterType>, CondowError> {
let reporter = self.condow.reporter_factory.make();
self.download_chunks_wrep(location, range, reporter).await
}
pub async fn download_wrep<R: Into<DownloadRange>, RP: Reporter>(
&self,
location: C::Location,
range: R,
reporter: RP,
) -> Result<Outcome<PartStream<ChunkStream>, RP>, CondowError> {
self.download_chunks_wrep(location, range, reporter)
.await?
.part_stream()
}
pub async fn download_chunks_wrep<R: Into<DownloadRange>, RP: Reporter>(
&self,
location: C::Location,
range: R,
reporter: RP,
) -> Result<Outcome<ChunkStream, RP>, CondowError> {
self.condow
.download_chunks_internal(location, range, self.get_size_mode, reporter)
.await
}
pub async fn get_size(&self, location: C::Location) -> Result<usize, GetSizeError> {
self.condow.get_size(location).await
}
}