Skip to main content

Module utils

Module utils 

Source
Expand description

Shared utility functions for file operations.

Structs§

AtomicOutputFile
Crash-safe output writing: content goes to a hidden temporary file next to final_path, and AtomicOutputFile::commit fsyncs it and renames it into place. Until then the final path holds whatever the caller put there (typically an empty placeholder claiming the name), so a crash or error never leaves a truncated file that looks complete. Dropping without committing removes the temporary file.

Functions§

read_n_bytes_from_file
read_up_to
Reads from reader until buf is full or EOF; returns the bytes read. Unlike a bare read call this only returns short on EOF, which the streaming loops rely on to spot the final chunk.
resolve_output_dir
Resolves the output directory for a workflow: the given path (created if missing) or the current directory.
sanitize_relative_path
Sanitizes a ‘/’-separated path from decrypted metadata into a relative path that cannot escape the output directory: rejects .. components, backslashes, and (on Windows) drive prefixes and : stream separators, drops empty and . components (which also relativizes absolute paths). The decrypted name is deliberately not echoed into error messages.