def _write_array_header(fp, d, version=None):
import struct<EOL>header = ["<STR_LIT:{>"]<EOL>for key, value in sorted(d.items()):<EOL><INDENT>header.append("<STR_LIT>" % (key, repr(value)))<EOL><DEDENT>header.append("<STR_LIT:}>")<EOL>header = "<STR_LIT>".join(header)<EOL>current_header_len = MAGIC_LEN + <NUM_LIT:2> + len(header) + <NUM_LIT:1>  <EOL>topad = <NUM_LIT:16> - (current_header_len % <NUM_LIT:16>)<EOL>header = header + '<STR_LIT:U+0020>'*topad + '<STR_LIT:\n>'<EOL>header = asbytes(_filter_header(header))<EOL>if len(header) >= (<NUM_LIT>*<NUM_LIT>) and version == (<NUM_LIT:1>, <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % (<NUM_LIT>*<NUM_LIT>))<EOL><DEDENT>if len(header) < (<NUM_LIT>*<NUM_LIT>):<EOL><INDENT>header_len_str = struct.pack('<STR_LIT>', len(header))<EOL>version = (<NUM_LIT:1>, <NUM_LIT:0>)<EOL><DEDENT>elif len(header) < (<NUM_LIT:2>**<NUM_LIT:32>):<EOL><INDENT>header_len_str = struct.pack('<STR_LIT>', len(header))<EOL>version = (<NUM_LIT:2>, <NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>fp.write(magic(*version))<EOL>fp.write(header_len_str)<EOL>fp.write(header)<EOL>return version<EOL>
Write the header for an array and returns the version used

    Parameters
    ----------
    fp : filelike object
    d : dict
        This has the appropriate entries for writing its string representation
        to the header of the file.
    version: tuple or None
        None means use oldest that works
        explicit version will raise a ValueError if the format does not
        allow saving this data.  Default: None
    Returns
    -------
    version : tuple of int
        the file version which needs to be used to store the data