Skip to content

Commit

Permalink
Export more utilities.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephank committed Jan 23, 2023
1 parent 69a2301 commit 918911a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@
mod resolve;
mod response_builder;
mod service;
mod util;

/// Lower level utilities.
pub mod util;

pub use crate::resolve::*;
pub use crate::response_builder::*;
pub use crate::service::*;

// For compatiblity. Removed in 0.10.
pub use crate::util::{FileBytesStream, FileResponseBuilder};
14 changes: 7 additions & 7 deletions src/util/file_bytes_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,15 @@ enum FileSeekState {
Reading,
}

/// Wraps a `tokio::fs::File`, and implements a stream of `Bytes`s reading a portion of the
/// file given by `range`.
/// Wraps a `tokio::fs::File` and implements a stream of `Bytes`s reading a portion of the file.
pub struct FileBytesStreamRange {
file_stream: FileBytesStream,
seek_state: FileSeekState,
start_offset: u64,
}

impl FileBytesStreamRange {
/// Create a new stream from the given file and range
/// Create a new stream from the given file and range.
pub fn new(file: File, range: HttpRange) -> FileBytesStreamRange {
FileBytesStreamRange {
file_stream: FileBytesStream::new_with_limit(file, range.length),
Expand Down Expand Up @@ -145,10 +144,8 @@ impl FileBytesStreamRange {
}
}

/// Wraps a `tokio::fs::File`, and implements a stream of `Bytes`s reading multiple portions of
/// the file given by `ranges` using a chunked multipart/byteranges response. A boundary is
/// required to separate the chunked components and therefore needs to be unlikely to be in any
/// file.
/// Wraps a `tokio::fs::File` and implements a stream of `Bytes`s providing multiple ranges of the
/// file contents in HTTP chunked transfer encoding.
pub struct FileBytesStreamMultiRange {
file_range: FileBytesStreamRange,
range_iter: vec::IntoIter<HttpRange>,
Expand All @@ -161,6 +158,9 @@ pub struct FileBytesStreamMultiRange {

impl FileBytesStreamMultiRange {
/// Create a new stream from the given file, ranges, boundary and file length.
///
/// A boundary is required to separate the chunked components and therefore needs to be
/// unlikely to be in any file.
pub fn new(
file: File,
ranges: Vec<HttpRange>,
Expand Down
4 changes: 2 additions & 2 deletions src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ mod requested_path;

pub use self::file_bytes_stream::*;
pub use self::file_response_builder::*;
pub use self::open_with_metadata::*;
pub use self::requested_path::*;
pub(crate) use self::open_with_metadata::*;
pub(crate) use self::requested_path::*;

0 comments on commit 918911a

Please sign in to comment.