One possible solution is to use a single threaded BGZF writer. This
exists at 28b030[1]. The code there will not currently compile, but
with a small amount of work it could be made to work. With some more, a
Write call could be made to update a bgzf.Chunk for each write.
Obviously, this would require that you fork the BAM writer to use that
BGZF writer. If you really want this, this would be my suggestion.
The alternative is for the existing concurrent writer to make available
the block offset component for each write (no issue here) and a block
number, and then make available a list of block starts when they are
ready to be written (I really don't like this - either it becomes a
[]int64 or a <-chan int64, I guess this could be checked for nil and
only written to if not, but the API becomes very fragile to ensure that
the pairs of values are properly collated, and I don't like that).
[1]
https://github.com/biogo/hts/blob/28b0306e7cfd423046d3d09a34da68615a4af1ea/bgzf/bgzf.go