Skip to main content

is_binary_file

Function is_binary_file 

Source
pub fn is_binary_file(path: &Path) -> bool
Expand description

Returns whether the file at path appears to be binary by reading only its first 8 KiB (streaming, no full allocation for large files).

Heuristic: true when a NUL byte appears in the probe window (same rule as is_binary). Returns false if the path cannot be opened or read (missing, permission, FIFO/socket/device, …); callers that need a typed open error should open the path themselves.

Public for embedder preflight (#1884) so hosts do not reimplement the window size or probe semantics. Writers still enforce binary themselves via load_text_strict or ops::file::ensure_not_binary_file. Available with default features and under features = ["files"] (always compiled; no cli gate).