Skip to main content

Module io

Module io 

Source

Enums§

FileData
Holds file data — either zero-copy mmap or an owned Vec. Dereferences to &[u8] for transparent use.

Functions§

file_size
Get file size without reading it (for byte-count-only optimization).
read_file
Read a file with zero-copy mmap for large files or read() for small files. Opens once with O_NOATIME, uses fstat for metadata to save a syscall.
read_file_mmap
Read a file always using mmap, with MADV_WILLNEED (no MADV_SEQUENTIAL). Used by tac which scans forward then outputs in reverse, and benefits from zero-copy vmsplice output from mmap pages. Skips the MMAP_THRESHOLD — even small files benefit from mmap since:
read_file_vec
Read a file entirely into a mutable Vec. Uses exact-size allocation from fstat + single read() for efficiency. Preferred over mmap when the caller needs mutable access (e.g., in-place decode).
read_stdin
Read all bytes from stdin into a Vec. On Linux, uses raw libc::read() to bypass Rust’s StdinLock/BufReader overhead. Uses a direct read() loop into a pre-allocated buffer instead of read_to_end(), which avoids Vec’s grow-and-probe pattern (extra read() calls and memcpy). Callers should enlarge the pipe buffer via fcntl(F_SETPIPE_SZ) before calling. Uses the full spare capacity for each read() to minimize syscalls.