From 1b97abfbca195145a1963821dcb7617bd8143f33 Mon Sep 17 00:00:00 2001 From: Joseph LaFreniere Date: Sat, 24 Dec 2022 15:41:16 -0600 Subject: [PATCH] fixup! Implement async `postproc_pagebreaks` --- src/adapters/postproc.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/adapters/postproc.rs b/src/adapters/postproc.rs index 0ccfae6..68bb3d5 100644 --- a/src/adapters/postproc.rs +++ b/src/adapters/postproc.rs @@ -150,7 +150,7 @@ pub fn postproc_pagebreaks(input: impl AsyncRead + Send) -> impl AsyncRead + Sen let regex_linefeed = regex::bytes::Regex::new(r"\x0c").unwrap(); let regex_newline = regex::bytes::Regex::new("\n").unwrap(); let mut page_count: i32 = 1; - let mut page_prefix: String = format!("\nPage {}:", page_count); + let mut page_prefix: String = format!("Page {}:", page_count); let input_stream = ReaderStream::new(input); let output_stream = stream! { @@ -162,6 +162,7 @@ pub fn postproc_pagebreaks(input: impl AsyncRead + Send) -> impl AsyncRead + Sen for sub_chunk in sub_chunks { // println!("{}", String::from_utf8_lossy(page_prefix.as_bytes())); yield Ok(Bytes::copy_from_slice(page_prefix.as_bytes())); + page_prefix = format!("\nPage {}:", page_count); yield Ok(Bytes::copy_from_slice(®ex_newline.replace_all(&sub_chunk, page_prefix.as_bytes()))); page_count += 1; page_prefix = format!("\nPage {}:", page_count); @@ -191,7 +192,7 @@ mod tests { assert!(matches!(res, Ok(_))); assert_eq!( output, - b"\nPage 1:Hello\nPage 1:World\nPage 2:Foo Bar\nPage 2:\nPage 3:Test" + b"Page 1:Hello\nPage 1:World\nPage 2:Foo Bar\nPage 2:\nPage 3:Test" ); }