Skip to main content

Module io

Module io 

Source
Expand description

Shared I/O helpers for content-reading rules.

Enums§

Classification
Classification of a file’s contents. Computed lazily — callers check the subset they care about.

Constants§

TEXT_INSPECT_LEN
How much of a file to sample when classifying text vs. binary.

Functions§

classify_bytes
read_prefix
Read up to TEXT_INSPECT_LEN bytes from the start of a file. Returned Ok(None) means the file was empty; Err is propagated I/O error.
read_prefix_n
Read up to n bytes from the start of path. Used by rules that only need to inspect a leading window — executable_has_shebang (2 bytes for #!), file_starts_with (pattern.len() bytes). Reads less than n if the file is shorter; returns the actual byte count in the returned Vec’s length.
read_suffix_n
Read up to n bytes from the END of path. Used by rules that only need to inspect the tail — file_ends_with (pattern.len() bytes). Returns the actual byte count in the returned Vec’s length; fewer than n bytes if the file is shorter. Files smaller than n are read whole.