Skip to content

v0.0.7 — POSIX fd hashing and opt-in mmap fast path

Latest

Choose a tag to compare

@Preeternal Preeternal released this 10 Jul 17:48

Highlights

  • Added POSIX fdHash / zfh_fd_hash for wrappers that already have an open
    file descriptor but do not have a usable filesystem path. This covers
    Android content:// providers, security-scoped URLs, provider-backed URLs,
    and other platform APIs that expose files only as file descriptors. The path
    API cannot represent these sources reliably without copying them to a
    temporary file.
  • The fd API keeps the read loop inside Zig, avoids copying the source to a
    temporary file or calling into Zig for every chunk, reads from the file
    descriptor's current position, and never closes it. It remains a streaming
    implementation and intentionally does not use mmap.
  • Added an opt-in mmap fast path for fileHash / fileHashInDir and
    zfh_context_file_hash. Enable it with Zig's HashRequest.use_mmap or the
    C flag ZFH_OPTION_USE_MMAP when hashing a stable regular file.
  • mmap is disabled by default. It is a file-I/O optimization, not a different
    hashing algorithm: the digest stays identical while the input is processed
    through a memory mapping and 64 KiB chunks. Callers should benchmark their
    workload before enabling it; local measurements were usually within a few
    percent, ranging from slightly slower to about 20% faster. The mapped file
    must not be modified or truncated while it is being hashed.

Compatibility notes

  • C ABI version is now ZFH_API_VERSION = 4.
  • ZFH_OPTION_USE_MMAP does not change the layout of zfh_options.
  • The mmap option affects path-based file hashing only; it is ignored by
    zfh_fd_hash and the streaming hasher APIs.