State Verification
When verify_state is true (the default), preader checks the file against the saved state before resuming. This catches file changes that happened between runs
What Is Checked
Verification runs the following checks in order:
- Checksum: The state file’s internal SHA-256 seal. Detects manual edits to the JSON file
- File Existence: The tracked file must still be on disk
- Fingerprint: SHA-256 of the first 4096 bytes of the tracked file. Detects content replacement
- File Size: Must match the size recorded when the state was last saved
- Modification Time: Must match the recorded mtime
File Path is checked separately. If the state tracks a different file than the one you are opening,
preaderraisesMismatch::Pathregardless of theverify_statesetting. If the state file was edited and its internal checksum no longer matches,Mismatch::Checksumtakes priority
Each check failure produces a specific error:
| Check | Rust Variant | Python Exception | Meaning |
|---|---|---|---|
| File path | Mismatch::Path | StateOutdatedError | State tracks a different file (always checked) |
| Checksum | Mismatch::Checksum | StateCorruptError | State file was edited outside preader |
| File missing | Mismatch::Missing | StateOutdatedError | File was deleted |
| Fingerprint | Mismatch::Identity | StateMismatchError | File content was replaced |
| File size | Mismatch::Size | StateOutdatedError | File grew or shrank |
| Modification time | Mismatch::Mtime | StateOutdatedError | File was touched |
The fingerprint is the SHA-256 hash of the first 4096 bytes of the file. It detects content replacement even when the file size and modification time happen to be unchanged
Disabling Verification
Set verify_state to false in your config to skip file metadata checks:
Rust
use preader::Config;
let config = Config {
verify_state: false,
..Config::default()
};
Python
from preader import Config
config = Config(verify_state=False)
When verification is off, only the file path is checked. Checksum, size, mtime, and fingerprint checks are skipped entirely
With
verify_stateset tofalse, file modifications go undetected. Use this only when you know the file has not changed and want to skip the fingerprint read
Additional Integrity Checks
One more mismatch type can occur regardless of the verify_state setting:
| Rust Variant | Python Exception | Meaning |
|---|---|---|
Mismatch::Stale | StateConflictError | Another process or iterator saved to the same state file since you last loaded it |
When verify_state is true, passing a State object that has unsaved modifications raises Mismatch::Unsealed (StateMismatchError in Python)
These protect against concurrent access (two writers to the same state) and programming errors (using a modified State object)
See Recovery Patterns for how to handle each of these errors