Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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:

  1. Checksum: The state file’s internal SHA-256 seal. Detects manual edits to the JSON file
  2. File Existence: The tracked file must still be on disk
  3. Fingerprint: SHA-256 of the first 4096 bytes of the tracked file. Detects content replacement
  4. File Size: Must match the size recorded when the state was last saved
  5. 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, preader raises Mismatch::Path regardless of the verify_state setting. If the state file was edited and its internal checksum no longer matches, Mismatch::Checksum takes priority

Each check failure produces a specific error:

CheckRust VariantPython ExceptionMeaning
File pathMismatch::PathStateOutdatedErrorState tracks a different file (always checked)
ChecksumMismatch::ChecksumStateCorruptErrorState file was edited outside preader
File missingMismatch::MissingStateOutdatedErrorFile was deleted
FingerprintMismatch::IdentityStateMismatchErrorFile content was replaced
File sizeMismatch::SizeStateOutdatedErrorFile grew or shrank
Modification timeMismatch::MtimeStateOutdatedErrorFile 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_state set to false, 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 VariantPython ExceptionMeaning
Mismatch::StaleStateConflictErrorAnother 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