State Management
preader’s main feature is saving your read position and resuming later. This chapter covers how state works, from manual saves to autosave and file change detection
A state captures everything needed to resume a read:
- Name: A string identifier you choose (e.g.
"job-1") or one derived automatically from the file path - Position: The byte offset just past the last finished item
- File Metadata: The tracked file’s path, size, modification time, and fingerprint
- Timestamps: When the state was created and last updated
- Checksum: A SHA-256 seal that detects tampering
States are saved as JSON files in the configured state_dir. The file name is <name>.state.json, and a / in the name creates subdirectories
When you call
save(), the item you are currently processing is not included. On resume, that item will be read again. This way you never accidentally skip data
The pages below walk through each part of the state lifecycle
- ▶️ Saving and Resuming: Manual saves, checkpoints, and the resume flow
- 💾 Autosave: Periodic saves that protect against crashes
- 🔒 State Verification: How preader detects file changes before resuming
- 🔄 Resync: Updating a state after a file moved or grew