Crate getattrlistbulk

Crate getattrlistbulk 

Source
Expand description

§getattrlistbulk

Safe Rust bindings for the macOS getattrlistbulk() system call.

This crate provides high-performance directory enumeration by retrieving file metadata in bulk, reducing the number of syscalls from O(n) to O(n/batch_size).

§Performance

ApproachComplexity10K Files
Traditional (readdir + stat)O(n)~20,000 syscalls
getattrlistbulkO(n/batch)~12 syscalls

~1,600x fewer syscalls → ~4x faster on NVMe SSDs (up to 50x on network storage).

Traditional:  opendir() → [readdir() + stat()] × N → closedir()
This crate:   open() → getattrlistbulk() × ceil(N/800) → close()

Run cargo bench --bench compare for reproducible benchmarks on your hardware.

§Example

use getattrlistbulk::{read_dir, RequestedAttributes};

let attrs = RequestedAttributes {
    name: true,
    size: true,
    ..Default::default()
};

for entry in read_dir("/Users", attrs).unwrap() {
    let entry = entry.unwrap();
    println!("{}: {} bytes", entry.name, entry.size.unwrap_or(0));
}

§Platform Support

This crate only compiles on macOS. Attempting to compile on other platforms will result in a compile-time error.

Structs§

DirEntries
Iterator over directory entries.
DirEntry
Metadata for a single directory entry.
DirReader
Builder for configuring directory reads.
RequestedAttributes
Attributes to request for each directory entry.

Enums§

Error
Error type for directory operations.
ObjectType
Type of filesystem object.

Functions§

read_dir
Read directory entries with specified attributes.
read_dir_with_buffer
Read directory entries with custom buffer size.