'Construct a `StreamingHDU` object given a file name and a header.
Parameters
name : file path, file object, or file like object
The file to which the header and data will be streamed.  If opened,
the file object must be opened in a writeable binary mode such as
\'wb\' or \'ab+\'.
header : `Header` instance
The header object associated with the data to be written
to the file.
Notes
The file will be opened and the header appended to the end of
the file.  If the file does not already exist, it will be
created, and if the header represents a Primary header, it
will be written to the beginning of the file.  If the file
does not exist and the provided header is not a Primary
header, a default Primary HDU will be inserted at the
beginning of the file and the provided header will be added as
the first extension.  If the file does already exist, but the
provided header represents a Primary header, the header will
be modified to an image extension header and appended to the
end of the file.'

def __init__(self, name, header):

    if isinstance(name, gzip.GzipFile):
        raise TypeError('StreamingHDU    not    supported    for    GzipFile    objects.')
    self._header = header.copy()
    filename = (fileobj_name(name) or '')
    newfile = False
    if filename:
        if ((not os.path.exists(filename)) or (os.path.getsize(filename) == 0)):
            newfile = True
    elif (hasattr(name, 'len') and (name.len == 0)):
        newfile = True
    if newfile:
        if ('SIMPLE' not in self._header):
            hdulist = HDUList([PrimaryHDU()])
            hdulist.writeto(name, 'exception')
    elif ('SIMPLE' in self._header):
        self._header.set('XTENSION', 'IMAGE', 'Image    extension', after='SIMPLE')
        del self._header['SIMPLE']
        if ('PCOUNT' not in self._header):
            dim = self._header['NAXIS']
            if (dim == 0):
                dim = ''
            else:
                dim = str(dim)
            self._header.set('PCOUNT', 0, 'number    of    parameters', after=('NAXIS' + dim))
        if ('GCOUNT' not in self._header):
            self._header.set('GCOUNT', 1, 'number    of    groups', after='PCOUNT')
    self._ffo = _File(name, 'append')
    tmp_hdu = _BaseHDU()
    tmp_hdu._header = self._header
    self._header_offset = tmp_hdu._writeheader(self._ffo)[0]
    self._data_offset = self._ffo.tell()
    self._size = self.size
    if (self._size != 0):
        self.writecomplete = False
    else:
        self.writecomplete = True
