func writeHD(w io.Writer, hd map[string]string) error {
// Define the order of specific keys
orderedKeys := []string{"VN", "SO", "GO", "SS"}
// String builder to accumulate the output
var sb strings.Builder
// Write specific keys first if they exist
for _, key := range orderedKeys {
if value, exists := hd[key]; exists {
sb.WriteString(fmt.Sprintf("%s:%s\t", key, value))
}
}
// Write the remaining key-value pairs
for key, value := range hd {
// Skip if the key is one of the specific keys
if key == "VN" || key == "SO" || key == "GO" || key == "SS" {
continue
}
sb.WriteString(fmt.Sprintf("%s:%s\t", key, value))
}
// Write to the io.Writer
_, err := w.Write([]byte(sb.String()))
return err
}
Basically, accumulate the output in a builder before writing out to the io.Writer. This has advantages, since writing more bytes at once will likely be more efficient than writing super often. It also decreases the amount of tests needed.
This should be implemented across all parsers in a single PR.
Here is an example written by ChatGPT:
Basically, accumulate the output in a builder before writing out to the io.Writer. This has advantages, since writing more bytes at once will likely be more efficient than writing super often. It also decreases the amount of tests needed.
This should be implemented across all parsers in a single PR.