Skip to main content

FileStream

Struct FileStream 

Source
pub struct FileStream<S> {
    pub stream: S,
    pub file_name: Option<String>,
    pub content_size: Option<u64>,
}
Available on crate feature file-stream only.
Expand description

HTTP file stream with metadata support for efficient file delivery.

FileStream wraps any stream that produces bytes and associates it with optional metadata like filename and content size. This enables proper HTTP headers to be set for file downloads, including Content-Disposition for filename suggestions and Content-Length for known file sizes. The implementation supports both regular responses and HTTP range requests for partial content delivery.

Fields§

§stream: S

The underlying byte stream

§file_name: Option<String>

Optional filename for Content-Disposition header

§content_size: Option<u64>

Optional content size for Content-Length header

Implementations§

Source§

impl<S> FileStream<S>
where S: TryStream + Send + 'static, S::Ok: Into<Bytes>, S::Error: Into<Box<dyn Error + Send + Sync>>,

Source

pub fn new( stream: S, file_name: Option<String>, content_size: Option<u64>, ) -> Self

Creates a new file stream with the provided metadata.

Source

pub async fn from_path<P>( path: P, ) -> Result<FileStream<Once<Ready<Result<Bytes, Error>>>>>
where P: AsRef<Path>,

Available on crate feature compio only.

Creates a file stream from a file system path with automatic metadata detection (compio variant).

Source

pub fn into_range_response( self, start: u64, end: u64, total_size: u64, ) -> Response

Creates an HTTP 206 Partial Content response for range requests.

Source

pub async fn try_range_response<P>( path: P, start: u64, end: u64, ) -> Result<Response>
where P: AsRef<Path>,

Available on crate feature compio only.

Try to create a range response for a file stream (compio variant).

Trait Implementations§

Source§

impl<S> Responder for FileStream<S>
where S: TryStream + Send + 'static, S::Ok: Into<Bytes>, S::Error: Into<Box<dyn Error + Send + Sync>>,

Source§

fn into_response(self) -> Response

Converts the file stream into an HTTP response with appropriate headers.

Auto Trait Implementations§

§

impl<S> Freeze for FileStream<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for FileStream<S>
where S: RefUnwindSafe,

§

impl<S> Send for FileStream<S>
where S: Send,

§

impl<S> Sync for FileStream<S>
where S: Sync,

§

impl<S> Unpin for FileStream<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for FileStream<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for FileStream<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more