pub struct BinaryDetection(/* private fields */);
Expand description

The behavior of binary detection while searching.

Binary detection is the process of heuristically identifying whether a given chunk of data is binary or not, and then taking an action based on the result of that heuristic. The motivation behind detecting binary data is that binary data often indicates data that is undesirable to search using textual patterns. Of course, there are many cases in which this isn’t true, which is why binary detection is disabled by default.

Unfortunately, binary detection works differently depending on the type of search being executed:

  1. When performing a search using a fixed size buffer, binary detection is applied to the buffer’s contents as it is filled. Binary detection must be applied to the buffer directly because binary files may not contain line terminators, which could result in exorbitant memory usage.
  2. When performing a search using memory maps or by reading data off the heap, then binary detection is only guaranteed to be applied to the parts corresponding to a match. When Quit is enabled, then the first few KB of the data are searched for binary data.

Implementations§

source§

impl BinaryDetection

source

pub fn none() -> BinaryDetection

No binary detection is performed. Data reported by the searcher may contain arbitrary bytes.

This is the default.

source

pub fn quit(binary_byte: u8) -> BinaryDetection

Binary detection is performed by looking for the given byte.

When searching is performed using a fixed size buffer, then the contents of that buffer are always searched for the presence of this byte. If it is found, then the underlying data is considered binary and the search stops as if it reached EOF.

When searching is performed with the entire contents mapped into memory, then binary detection is more conservative. Namely, only a fixed sized region at the beginning of the contents are detected for binary data. As a compromise, any subsequent matching (or context) lines are also searched for binary data. If binary data is detected at any point, then the search stops as if it reached EOF.

source

pub fn convert(binary_byte: u8) -> BinaryDetection

Binary detection is performed by looking for the given byte, and replacing it with the line terminator configured on the searcher. (If the searcher is configured to use CRLF as the line terminator, then this byte is replaced by just LF.)

When searching is performed using a fixed size buffer, then the contents of that buffer are always searched for the presence of this byte and replaced with the line terminator. In effect, the caller is guaranteed to never observe this byte while searching.

When searching is performed with the entire contents mapped into memory, then this setting has no effect and is ignored.

source

pub fn quit_byte(&self) -> Option<u8>

If this binary detection uses the “quit” strategy, then this returns the byte that will cause a search to quit. In any other case, this returns None.

source

pub fn convert_byte(&self) -> Option<u8>

If this binary detection uses the “convert” strategy, then this returns the byte that will be replaced by the line terminator. In any other case, this returns None.

Trait Implementations§

source§

impl Clone for BinaryDetection

source§

fn clone(&self) -> BinaryDetection

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for BinaryDetection

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for BinaryDetection

source§

fn default() -> BinaryDetection

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.