From c759bdef4cd2fac10af75cd20537e235d12b3ead Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sat, 1 Jan 2022 22:46:37 +0000 Subject: [PATCH] add file chunks stream adapter --- actix-files/src/lib.rs | 1 - actix-files/src/named.rs | 8 +++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/actix-files/src/lib.rs b/actix-files/src/lib.rs index 41113f2ab..69a0bd565 100644 --- a/actix-files/src/lib.rs +++ b/actix-files/src/lib.rs @@ -33,7 +33,6 @@ mod path_buf; mod range; mod service; -pub use self::chunked::ChunkedReadFile; pub use self::directory::Directory; pub use self::files::Files; pub use self::named::NamedFile; diff --git a/actix-files/src/named.rs b/actix-files/src/named.rs index a307c6385..569f6ed77 100644 --- a/actix-files/src/named.rs +++ b/actix-files/src/named.rs @@ -21,8 +21,9 @@ use actix_web::{ Error, HttpMessage, HttpRequest, HttpResponse, Responder, }; use bitflags::bitflags; +use bytes::Bytes; use derive_more::{Deref, DerefMut}; -use futures_core::future::LocalBoxFuture; +use futures_core::{future::LocalBoxFuture, Stream}; use mime_guess::from_path; use crate::{encoding::equiv_utf8_text, range::HttpRange}; @@ -527,6 +528,11 @@ impl NamedFile { res.body(SizedStream::new(length, reader)) } + + /// Returns stream of chunks for the complete file. + pub fn into_chunk_stream(self) -> impl Stream> { + chunked::new_chunked_read(self.md.len(), 0, self.file) + } } /// Returns true if `req` has no `If-Match` header or one which matches `etag`.