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
//! [`ByteRangeReader`].
use *;
/// Trait for reading arbitrary byte ranges from a data source.
///
/// This trait abstracts the data source, allowing the index system to work
/// with local files, HTTP resources, cloud storage, or any other source
/// that supports random access.
///
/// # Implementing Custom Readers
///
/// ```ignore
/// use mdf4_rs::index::ByteRangeReader;
///
/// struct HttpRangeReader {
/// url: String,
/// client: reqwest::blocking::Client,
/// }
///
/// impl ByteRangeReader for HttpRangeReader {
/// type Error = mdf4_rs::Error;
///
/// fn read_range(&mut self, offset: u64, length: u64) -> Result<Vec<u8>, Self::Error> {
/// let end = offset + length - 1;
/// let response = self.client
/// .get(&self.url)
/// .header("Range", format!("bytes={}-{}", offset, end))
/// .send()
/// .map_err(|e| mdf4_rs::Error::BlockSerializationError(e.to_string()))?;
/// response.bytes()
/// .map(|b| b.to_vec())
/// .map_err(|e| mdf4_rs::Error::BlockSerializationError(e.to_string()))
/// }
/// }
/// ```