skip_bom
Skip the optional encoding BOM (Byte Order Mark) at the start of an I/O stream if it exists.
The SkipEncodingBom data structure does not make any dynamic allocations and supports progressive stream reads.
A list of supported BOMs can be found in the crate documentation.
Examples
use ;
use ;
// Read a stream after checking that it starts with the BOM
const BOM_BYTES: &'static = b"\xEF\xBB\xBFThis stream starts with a UTF-8 BOM.";
let mut reader = new;
assert_eq!;
let mut string = Defaultdefault;
let _ = reader.read_to_string.unwrap;
assert_eq!;
// Read a stream without a starting BOM
const NO_BOM_BYTES: &'static = b"This stream does not start with the UTF-8 BOM: \xEF\xBB\xBF.";
let mut reader = new;
assert_eq!;
let mut buf = Defaultdefault;
let _ = reader.read_to_end.unwrap;
assert_eq!;
// Read a stream and disregard the starting BOM completely
let mut reader = new;
let mut buf = Defaultdefault;
let _ = reader.read_to_end.unwrap;
assert_eq!;
// Check the BOM after the read is over.
assert_eq!;
Progressive reads
This crate supports I/O streams that are incomplete at first and receive data later, even for the initial BOM. Example:
use ;
use ;
let mut reader = new;
let mut buf = Defaultdefault;
let _ = reader.read_to_end.unwrap;
// The stream is incomplete: there are only the first two bytes of the BOM yet
assert_eq!;
assert_eq!;
// Add the next bytes and check that the UTF-8 BOM is accounted for
reader.get_mut.get_mut.extend_from_slice;
let _ = reader.read_to_end.unwrap;
assert_eq!;
assert_eq!;
References
Documentation
Module documentation with examples
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.