Allow bcftools reheader --fai to read its input file from a stream #2129
+31
−45
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This didn't work in the past because update_from_fai() opened, read the header from, and then closed the input file, preventing the reheader_* functions from accessing the rest of the file contents when the input is a stream. As all the reheader_* functions read the header into a kstring, it's possible to make streaming work by passing this kstring into update_from_fai() and adjusting it to work directly on that copy of the data.
As update_from_fai() no longer needs to write a temporary file, args_t::rm_tmpfile and args_t::tmp_prefix can be removed. The -T option is ignored as it's no longer needed, but is still accepted for compatibility. The init_tmp_prefix() function is still used by some other bcftools subcommands, so is left in place for now.
Fixes #2088