text search for the atmosphere
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041package cursor
import ( "errors" "io/fs" "os" "path/filepath" "strconv" "strings")
// File persists the last-processed Jetstream Seq to disk. Writes are atomic// via rename so a crash mid-write cannot corrupt the cursor.type File struct { path string}
func New(path string) *File { return &File{path: path} }
func (f *File) Load() (uint64, error) { b, err := os.ReadFile(f.path) if errors.Is(err, fs.ErrNotExist) { return 0, nil } if err != nil { return 0, err } return strconv.ParseUint(strings.TrimSpace(string(b)), 10, 64)}
func (f *File) Save(seq uint64) error { if err := os.MkdirAll(filepath.Dir(f.path), 0o755); err != nil { return err } tmp := f.path + ".tmp" if err := os.WriteFile(tmp, []byte(strconv.FormatUint(seq, 10)), 0o644); err != nil { return err } return os.Rename(tmp, f.path)}