def _read_chunk(headerfile, delimiter):
    """
    Reads one chunk of header data. Based on delimiter, this may be a tag
    (ended by " ") or the value of a tag (ended by ";").
    """
    prior_delimiter = None
    chunk = bytes()
    while True:
        c = headerfile.read(1)
        if c.decode() != delimiter:
            chunk += c
            if c.decode() == '"':
                # switch delimiter to make sure to parse the whole string
                # enclosed in '"'.
                delimiter, prior_delimiter = c.decode(), delimiter
        elif prior_delimiter:
            # switch back delimiter
            chunk += c
            delimiter, prior_delimiter = prior_delimiter, None
        else:
            return chunk.decode()