'Writes the header to file or file-like object.
By default this writes the header exactly as it would be written to a
FITS file, with the END card included and padding to the next multiple
of 2880 bytes.  However, aspects of this may be controlled.
Parameters
fileobj : str, file, optional
Either the pathname of a file, or an open file handle or file-like
object
sep : str, optional
The character or string with which to separate cards.  By default
there is no separator, but one could use ``\'\\n\'``, for example, to
separate each card with a new line
endcard : bool, optional
If `True` (default) adds the END card to the end of the header
string
padding : bool, optional
If `True` (default) pads the string with spaces out to the next
multiple of 2880 characters
overwrite : bool, optional
If ``True``, overwrite the output file if it exists. Raises an
``OSError`` (``IOError`` for Python 2) if ``False`` and the
output file exists. Default is ``False``.
.. versionchanged:: 1.3
``overwrite`` replaces the deprecated ``clobber`` argument.'

@deprecated_renamed_argument('clobber', 'overwrite', '2.0')
def tofile(self, fileobj, sep='', endcard=True, padding=True, overwrite=False):

    close_file = fileobj_closed(fileobj)
    if (not isinstance(fileobj, _File)):
        fileobj = _File(fileobj, mode='ostream', overwrite=overwrite)
    try:
        blocks = self.tostring(sep=sep, endcard=endcard, padding=padding)
        actual_block_size = _block_size(sep)
        if (padding and ((len(blocks) % actual_block_size) != 0)):
            raise IOError('Header    size    ({})    is    not    a    multiple    of    block    size    ({}).'.format(((len(blocks) - actual_block_size) + BLOCK_SIZE), BLOCK_SIZE))
        if (not fileobj.simulateonly):
            fileobj.flush()
            try:
                offset = fileobj.tell()
            except (AttributeError, IOError):
                offset = 0
            fileobj.write(blocks.encode('ascii'))
            fileobj.flush()
    finally:
        if close_file:
            fileobj.close()
