def genBinaryFileRDD(sc, path, numPartitions=None):
  """
    Read files from a directory to a RDD.
    :param sc: SparkContext.
    :param path: str, path to files.
    :param numPartition: int, number or partitions to use for reading files.
    :return: RDD with a pair of key and value: (filePath: str, fileData: BinaryType)
    """
  numPartitions = numPartitions or sc.defaultParallelism
  rdd = sc.binaryFiles(
    path, minPartitions=numPartitions).repartition(numPartitions)
  #rdd = rdd.map(lambda x: (x[0], bytearray(x[1])))
  return rdd