code: func readRecord(r io.Reader, buf []byte, recTyped bool, crcTable *crc32.Table, checkCRC bool) ([]byte, int, recordType, error) {
  	_header := [recordHeaderSize]byte{}
  	header := _header[:]
  	if _, err := io.ReadFull(r, header); err != nil {
  		return buf, 0, recNoType, err
  	}
  	recType := recNoType
  	recSize := 0
  	firstInt := int(util.ByteOrder.Uint32(header[:4]))
  	if recTyped {
  		recType = recordType(firstInt >> 24 & 0xFF)
  		recSize = firstInt & 0xFFFFFF
  	} else {
  		recSize = firstInt
  	}
  	if recSize == 0 && recType == 0 {
  		crc := util.ByteOrder.Uint32(header[4:recordHeaderSize])
  		if crc == 0 {
  			return buf, 0, 0, errNeedRewind
  		}
  	}
  	// Now we are going to read the payload
  	buf = util.EnsureBufBigEnough(buf, recSize)
  	if _, err := io.ReadFull(r, buf[:recSize]); err != nil {
  		return buf, 0, recNoType, err
  	}
  	if checkCRC {
  		crc := util.ByteOrder.Uint32(header[4:recordHeaderSize])
  		// check CRC against what was stored
  		if c := crc32.Checksum(buf[:recSize], crcTable); c != crc {
  			return buf, 0, recNoType, fmt.Errorf("corrupted data, expected crc to be 0x%08x, got 0x%08x", crc, c)
  		}
  	}
  	return buf, recSize, recType, nil
  }
docs: // readRecord reads a record from `r`, possibly checking the CRC-32 checksum.
  // When `buf`` is not nil, this function ensures the buffer is big enough to
  // hold the payload (expanding if necessary). Therefore, this call always
  // return `buf`, regardless if there is an error or not.
  // The caller is indicating if the record is supposed to be typed or not.