func (c *ShardedBAMCompressor) CloseShard() error {
	if err := c.bgzf.CloseWithoutTerminator(); err != nil {
		return err
	}
	f := c.output
	c.output = nil
	return c.writer.addShard(f)
}
CloseShard finalizes the in-progress shard, and passes the
compressed data to its parent ShardedBAMWriter.  It removes the
current shard from the compressor and prepares the compressor for
the next call to StartShard().

The ShardedBAMWriter will buffer shards up to its queue size, so
the caller must be careful about how out of order it is when
calling CloseShard(), otherwise, calls to CloseShard() will block.
package bam
import (
	"bytes"
	"io"
	"sync"
	"github.com/grailbio/base/syncqueue"
	"github.com/grailbio/bio/encoding/bgzf"
	htsbam "github.com/grailbio/hts/bam"
	"github.com/grailbio/hts/sam"
	"v.io/x/lib/vlog"
)
var (
	magicBlock = []byte{
		0x1f, 0x8b, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x06, 0x00, 0x42, 0x43,
		0x02, 0x00, 0x1b, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	}
)
type ShardedBAMCompressor struct {
	writer *ShardedBAMWriter
	bgzf   *bgzf.Writer
	output *shardedBAMBuffer
	buf    bytes.Buffer
}
func (c *ShardedBAMCompressor) StartShard(shardNum int) error {
	if c.output != nil {
		vlog.Panicf("existing shard still in progress")
	}
	c.output = &shardedBAMBuffer{
		shardNum: shardNum + 1,
	}
	var err error
	c.bgzf, err = bgzf.NewWriter(&c.output.buf, c.writer.gzLevel)
	return err
}
func (c *ShardedBAMCompressor) addHeader(h *sam.Header) error {
	return h.EncodeBinary(c.bgzf)
}
func (c *ShardedBAMCompressor) AddRecord(r *sam.Record) error {
	if err := htsbam.Marshal(r, &c.buf); err != nil {
		return err
	}
	_, err := c.buf.WriteTo(c.bgzf)
	return err
}