code: func (bh *Header) EncodeBinary(w io.Writer) error {
  	wb := &errWriter{w: w}
  
  	binary.Write(wb, binary.LittleEndian, bamMagic)
  	text, _ := bh.MarshalText()
  	binary.Write(wb, binary.LittleEndian, int32(len(text)))
  	wb.Write(text)
  	binary.Write(wb, binary.LittleEndian, int32(len(bh.refs)))
  
  	if !validInt32(len(bh.refs)) {
  		return errors.New("sam: value out of range")
  	}
  	var name []byte
  	for _, r := range bh.refs {
  		name = append(name, []byte(r.name)...)
  		name = append(name, 0)
  		binary.Write(wb, binary.LittleEndian, int32(len(name)))
  		wb.Write(name)
  		name = name[:0]
  		binary.Write(wb, binary.LittleEndian, r.lRef)
  	}
  	if wb.err != nil {
  		return wb.err
  	}
  
  	return nil
  }
docs: // EncodeBinary writes a binary encoding of the Header to the given io.Writer.
  // The format of the encoding is defined in the SAM specification, section 4.2.