code: func (r *bufferingReaderAt) ReadAt(p []byte, offset int64) (read int, err error) {
  	if len(p) == 0 {
  		return r.r.ReadAt(p, offset)
  	}
  
  	r.l.Lock()
  	defer r.l.Unlock()
  
  	bs := int64(r.blockSize)
  	blockOff := int64((offset / bs) * bs) // block-aligned offset
  
  	// Sequentially read blocks that intersect with the requested segment.
  	for {
  		// err here may be EOF or some other error. We consume all data first and
  		// deal with errors later.
  		data, err := r.readBlock(blockOff)
  
  		// The first block may be read from the middle, since 'min' may be less than
  		// 'offset'.
  		if offset > blockOff {
  			pos := offset - blockOff // position inside the block to read from
  			if pos < int64(len(data)) {
  				data = data[pos:] // grab the tail of the block
  			} else {
  				data = nil // we probably hit EOF before the requested offset
  			}
  		}
  
  		// 'copy' copies min of len(data) and whatever space is left in 'p', so this
  		// is always safe. The last block may be copied partially (if there's no
  		// space left in 'p').
  		read += copy(p[read:], data)
  
  		switch {
  		case read == len(p):
  			// We managed to read everything we wanted, ignore the last error, if any.
  			return read, nil
  		case err != nil:
  			return read, err
  		}
  
  		// The last read was successful. Per ReaderAt contract (that we double
  		// checked in readBlock) it means it read ALL requested data (and we request
  		// 'bs' bytes). So move on to the next block.
  		blockOff += bs
  	}
  }
docs: // ReadAt implements io.ReaderAt interface.