// Write a single sequence and return the number of bytes written and any error. func (w *Writer) Write(s seq.Sequence) (n int, err error) { var ( _n int prefix = append([]byte{'\n'}, w.SeqPrefix...) ) id, desc := s.Name(), s.Description() header := make([]byte, 0, len(w.IDPrefix)+len(id)+len(desc)+1) header = append(header, w.IDPrefix...) header = append(header, id...) if len(desc) > 0 { header = append(header, ' ') header = append(header, desc...) } n, err = w.w.Write(header) if err != nil { return n, err } for i := 0; i < s.Len(); i++ { if i%w.Width == 0 { _n, err = w.w.Write(prefix) if n += _n; err != nil { return n, err } } _n, err = w.w.Write([]byte{byte(s.At(i).L)}) if n += _n; err != nil { return n, err } } _n, err = w.w.Write([]byte{'\n'}) if n += _n; err != nil { return n, err } return n, nil }
func (w *Writer) writeHeader(prefix byte, s seq.Sequence) (n int, err error) { var _n int n, err = w.w.Write([]byte{prefix}) if err != nil { return } _n, err = io.WriteString(w.w, s.Name()) if n += _n; err != nil { return } if desc := s.Description(); len(desc) != 0 { _n, err = w.w.Write([]byte{' '}) if n += _n; err != nil { return } _n, err = io.WriteString(w.w, desc) if n += _n; err != nil { return } } _n, err = w.w.Write([]byte("\n")) n += _n return }