Skip to content

Commit

Permalink
Factor SizeLimited constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
mrd0ll4r authored and remram44 committed Dec 11, 2024
1 parent 5fcc2e9 commit c26983e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,7 @@ impl<I: ChunkerImpl> Chunker<I> {
pub fn max_size(self, max: usize) -> Chunker<SizeLimited<I>> {
assert!(max > 0);
Chunker {
inner: SizeLimited {
inner: self.inner,
pos: 0,
max_size: max,
},
inner: SizeLimited::new(self.inner, max),
}
}
}
Expand Down Expand Up @@ -445,6 +441,17 @@ pub struct SizeLimited<I: ChunkerImpl> {
max_size: usize,
}

impl<I: ChunkerImpl> SizeLimited<I> {
/// Wraps the given chunker implementation to limit the size of produced chunks.
pub fn new(inner: I, max_size: usize) -> Self {
SizeLimited {
inner,
pos: 0,
max_size,
}
}
}

impl<I: ChunkerImpl> ChunkerImpl for SizeLimited<I> {
fn find_boundary(&mut self, data: &[u8]) -> Option<usize> {
assert!(self.max_size > self.pos);
Expand Down

0 comments on commit c26983e

Please sign in to comment.