code: func (bg *Reader) nextBlock() error {
  	base := bg.current.NextBase()
  	ok := bg.cacheSwap(base)
  	if ok {
  		bg.Header = bg.current.header()
  		return nil
  	}
  
  	var err error
  	if bg.dec != nil {
  		bg.dec.using(bg.current).nextBlockAt(base, nil)
  		bg.current, err = bg.dec.wait()
  	} else {
  		var ok bool
  		for i := 0; i < cap(bg.working); i++ {
  			dec := <-bg.working
  			bg.current, err = dec.wait()
  			bg.waiting <- dec
  			if bg.current.Base() == base {
  				ok = true
  				break
  			}
  			if err == nil {
  				bg.keep(bg.current)
  				bg.current = nil
  			}
  		}
  		if !ok {
  			panic("bgzf: unexpected block")
  		}
  	}
  	if err != nil {
  		return err
  	}
  
  	// Only set header if there was no error.
  	h := bg.current.header()
  	if bg.current.isMagicBlock() {
  		// TODO(kortschak): Do this more carefully. It may be that
  		// someone actually has extra data in this field that we are
  		// clobbering.
  		bg.Header.Extra = h.Extra
  	} else {
  		bg.Header = h
  	}
  
  	return nil
  }
docs: // nextBlock swaps the current decompressed block for the next
  // in the stream. If the block is available from the cache
  // no additional work is done, otherwise a decompressor is
  // used or waited on.