package sbhpfv1 import ( "encoding/binary" "errors" "io" ) // getWriterPosition returns the current write position. func getWriterPosition(w io.Writer) int64 { if seeker, ok := w.(io.Seeker); ok { pos, _ := seeker.Seek(0, io.SeekCurrent) return pos } return -1 } // writeUint32AtPosition writes an uint32 at a given position. func writeUint32AtPosition(w io.Writer, pos int64, value uint32) error { if seeker, ok := w.(io.Seeker); ok { curPos, _ := seeker.Seek(0, io.SeekCurrent) // Save current position if _, err := seeker.Seek(pos, io.SeekStart); err != nil { return err } if err := binary.Write(w, binary.LittleEndian, value); err != nil { return err } _, _ = seeker.Seek(curPos, io.SeekStart) // Restore position return nil } return errors.New("writer does not support seeking") }