code: func (r *Reader) Read() (*Record, error) {
  	b, err := r.r.ReadBytes('\n')
  	if err != nil {
  		return nil, err
  	}
  	b = b[:len(b)-1]
  	if b[len(b)-1] == '\r' {
  		b = b[:len(b)-1]
  	}
  	var rec Record
  
  	// Handle cases where a header was present.
  	if r.seenRefs == nil {
  		err = rec.UnmarshalSAM(r.h, b)
  		if err != nil {
  			return nil, err
  		}
  		return &rec, nil
  	}
  
  	// Handle cases where no SAM header is present.
  	err = rec.UnmarshalSAM(nil, b)
  	if err != nil {
  		return nil, err
  	}
  
  	if ref, ok := r.seenRefs[rec.Ref.Name()]; ok {
  		rec.Ref = ref
  	} else if rec.Ref != nil {
  		err = r.h.AddReference(rec.Ref)
  		if err != nil {
  			return nil, err
  		}
  		r.seenRefs[rec.Ref.Name()] = rec.Ref
  	} else {
  		r.seenRefs["*"] = nil
  	}
  	if ref, ok := r.seenRefs[rec.MateRef.Name()]; ok {
  		rec.MateRef = ref
  	} else if rec.MateRef != nil {
  		err = r.h.AddReference(rec.MateRef)
  		if err != nil {
  			return nil, err
  		}
  		r.seenRefs[rec.MateRef.Name()] = rec.MateRef
  	} else {
  		r.seenRefs["*"] = nil
  	}
  
  	return &rec, nil
  }
docs: // Read returns the next sam.Record in the SAM stream.