code: func scanForLastCompleteBlock(rootDir string, fileNum int, startingOffset int64) ([]byte, int64, int, error) {
  	//scan the passed file number suffix starting from the passed offset to find the last completed block
  	numBlocks := 0
  	var lastBlockBytes []byte
  	blockStream, errOpen := newBlockfileStream(rootDir, fileNum, startingOffset)
  	if errOpen != nil {
  		return nil, 0, 0, errOpen
  	}
  	defer blockStream.close()
  	var errRead error
  	var blockBytes []byte
  	for {
  		blockBytes, errRead = blockStream.nextBlockBytes()
  		if blockBytes == nil || errRead != nil {
  			break
  		}
  		lastBlockBytes = blockBytes
  		numBlocks++
  	}
  	if errRead == ErrUnexpectedEndOfBlockfile {
  		logger.Debugf(`Error:%s
  		The error may happen if a crash has happened during block appending.
  		Resetting error to nil and returning current offset as a last complete block's end offset`, errRead)
  		errRead = nil
  	}
  	logger.Debugf("scanForLastCompleteBlock(): last complete block ends at offset=[%d]", blockStream.currentOffset)
  	return lastBlockBytes, blockStream.currentOffset, numBlocks, errRead
  }
docs: // scanForLastCompleteBlock scan a given block file and detects the last offset in the file
  // after which there may lie a block partially written (towards the end of the file in a crash scenario).