def read_cdx(file, encoding='utf8'):
    '''Iterate CDX file.

    Args:
        file (str): A file object.
        encoding (str): The encoding of the file.

    Returns:
        iterator: Each item is a dict that maps from field key to value.
    '''
    with codecs.getreader(encoding)(file) as stream:
        header_line = stream.readline()
        separator = header_line[0]
        field_keys = header_line.strip().split(separator)

        if field_keys.pop(0) != 'CDX':
            raise ValueError('CDX header not found.')

        for line in stream:
            yield dict(zip(field_keys, line.strip().split(separator)))
Iterate CDX file.

    Args:
        file (str): A file object.
        encoding (str): The encoding of the file.

    Returns:
        iterator: Each item is a dict that maps from field key to value.