pub fn extract_context_reader<R: BufRead>(
reader: R,
config: &LogContextConfig,
) -> Result<LogContextResult>Expand description
Streaming variant of extract_context for large inputs.
Reads reader line by line using a sliding ring buffer of
config.context_lines lines. Memory usage is
O(context_lines × max_line_length) regardless of total file size,
making it safe for multi-gigabyte log files.
Semantics match extract_context: case handling, max_matches,
truncated, and first-keyword-wins on a line all behave identically.
“Before” and “after” context windows are clipped at file boundaries.
§Example
use sanitize_engine::log_context::{LogContextConfig, extract_context_reader};
use std::io::BufReader;
let data = b"INFO start\nERROR disk full\nINFO retrying\n";
let config = LogContextConfig::new().with_context_lines(1);
let result = extract_context_reader(BufReader::new(data.as_ref()), &config).unwrap();
assert_eq!(result.match_count, 1);
assert_eq!(result.matches[0].line_number, 2);
assert_eq!(result.matches[0].before, vec!["INFO start"]);
assert_eq!(result.matches[0].after, vec!["INFO retrying"]);§Errors
Returns an io::Error if reading from reader fails.