def parse_binvox_header(fp):
    """
    Read the header from a binvox file.
    Spec available:
    https://www.patrickmin.com/binvox/binvox.html

    Parameters
    ------------
    fp: file-object
      File like object with binvox file

    Returns
    ----------
    shape : tuple
      Shape of binvox according to binvox spec
    translate : tuple
      Translation
    scale : float
      Scale of voxels

    Raises
    ------------
    IOError
      If invalid binvox file.
    """

    line = fp.readline().strip()
    if hasattr(line, 'decode'):
        binvox = b'#binvox'
        space = b' '
    else:
        binvox = '#binvox'
        space = ' '
    if not line.startswith(binvox):
        raise IOError('Not a binvox file')
    shape = tuple(
        int(s) for s in fp.readline().strip().split(space)[1:])
    translate = tuple(
        float(s) for s in fp.readline().strip().split(space)[1:])
    scale = float(fp.readline().strip().split(space)[1])
    fp.readline()
    return shape, translate, scale