'Write the given data to the stream.
Parameters
data : ndarray
Data to stream to the file.
Returns
writecomplete : int
Flag that when `True` indicates that all of the required
data has been written to the stream.
Notes
Only the amount of data specified in the header provided to the class
constructor may be written to the stream.  If the provided data would
cause the stream to overflow, an `IOError` exception is
raised and the data is not written. Once sufficient data has been
written to the stream to satisfy the amount specified in the header,
the stream is padded to fill a complete FITS block and no more data
will be accepted. An attempt to write more data after the stream has
been filled will raise an `IOError` exception. If the
dtype of the input data does not match what is expected by the header,
a `TypeError` exception is raised.'

def write(self, data):

    size = (self._ffo.tell() - self._data_offset)
    if (self.writecomplete or ((size + data.nbytes) > self._size)):
        raise IOError('Attempt    to    write    more    data    to    the    stream    than    the    header    specified.')
    if (BITPIX2DTYPE[self._header['BITPIX']] != data.dtype.name):
        raise TypeError('Supplied    data    does    not    match    the    type    specified    in    the    header.')
    if (data.dtype.str[0] != '>'):
        output = data.byteswap()
    else:
        output = data
    self._ffo.writearray(output)
    if ((self._ffo.tell() - self._data_offset) == self._size):
        self._ffo.write((_pad_length(self._size) * '\x00'))
        self.writecomplete = True
    self._ffo.flush()
    return self.writecomplete
