stream_download/storage/mod.rs
1//! Configurable implementations for the buffer's storage layer.
2//! Pre-configured implementations are available for memory and temporary file-based storage.
3
4use std::io::{self, Read, Seek, Write};
5
6pub mod adaptive;
7pub mod bounded;
8pub mod memory;
9#[cfg(feature = "temp-storage")]
10pub mod temp;
11
12/// Creates a [`StorageReader`] and [`StorageWriter`] based on the content
13/// length returned from the [`SourceStream`](crate::source::SourceStream).
14/// The reader and writer must track their position in the stream independently.
15pub trait StorageProvider: Send {
16 /// Source used to read from the underlying storage.
17 type Reader: StorageReader;
18 /// Handle that can write to the underlying storage.
19 type Writer: StorageWriter;
20
21 /// Turn the provider into a reader and writer.
22 fn into_reader_writer(
23 self,
24 content_length: Option<u64>,
25 ) -> io::Result<(Self::Reader, Self::Writer)>;
26
27 /// Returns the maximum number of bytes this provider can hold at a time.
28 fn max_capacity(&self) -> Option<usize> {
29 None
30 }
31}
32
33/// Trait used to read from a storage layer
34pub trait StorageReader: Read + Seek + Send {}
35
36impl<T> StorageReader for T where T: Read + Seek + Send {}
37
38/// Handle for writing to the underlying storage layer.
39pub trait StorageWriter: Write + Seek + Send + 'static {}
40
41impl<T> StorageWriter for T where T: Write + Seek + Send + 'static {}