import zipfile


def zip_zchunkstore(zip_file, url=None):
    """Returns a reference description for ReferenceFileSystem from an
    uncompressed Zarr zip file store.

      https://github.com/intake/fsspec-reference-maker

    Parameters
    ----------

    zip_file: str
        Path to the zip file.
    url: str, optional
        URL where the zip file will be served. Defaults to zip_file.

    Returns
    -------

    JSON-serializable reference description.
    """
    zchunkstore = {}
    with zipfile.ZipFile(zip_file) as zf:
        if zf.compression != 0:
            raise RuntimeError("Compressed zip's are not supported.")

        zarr_json_files = ('.zattrs', '.zgroup', '.zmetadata', '.zarray')

        data_url = zip_file
        if url is not None:
            data_url = url

        for info in zf.infolist():
            name_bytes = len(info.filename.encode("utf-8"))
            offset = info.header_offset + 30 + name_bytes
            size = info.compress_size
            if any([info.filename.endswith(z) for z in zarr_json_files]):
                content = zipfile.Path(zf, at=info.filename).read_text(encoding='utf-8')
                zchunkstore[info.filename] = content
            else:
                zchunkstore[info.filename] = [data_url, offset, size]

    return zchunkstore