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
28/// Trait used to read from a storage layer
29pub trait StorageReader: Read + Seek + Send {}
30
31impl<T> StorageReader for T where T: Read + Seek + Send {}
32
33/// Handle for writing to the underlying storage layer.
34pub trait StorageWriter: Write + Seek + Send + 'static {}
35
36impl<T> StorageWriter for T where T: Write + Seek + Send + 'static {}