Function read_with_crlf_suppression

Source
pub fn read_with_crlf_suppression<R: Read>(reader: R) -> Result<Vec<u8>>
Expand description

Reads all bytes from the given reader, suppressing CR (\r) bytes that are immediately followed by LF (\n).

This function is intended to normalize line endings by removing carriage return characters that precede line feeds (i.e., converting CRLF sequences to LF).

§Arguments

  • reader - Any type that implements std::io::Read, such as a file, buffer, or stream.

§Returns

A std::io::Result containing a Vec<u8> with the filtered bytes, or an error if one occurs while reading from the input.

§Example

use std::io::Cursor;
use tpnote_lib::text_reader::read_with_crlf_suppression;

let data = b"foo\r\nbar\nbaz\r\n";
let cursor = Cursor::new(data);
let result = read_with_crlf_suppression(cursor).unwrap();
assert_eq!(result, b"foo\nbar\nbaz\n");

§Errors

Returns any I/O error encountered while reading from the provided reader.

§See Also

std::io::Read, std::fs::File