'Creates a new FitsHDU from a given HDUList object.
Parameters
hdulist : HDUList
A valid Headerlet object.
compress : bool, optional
Gzip compress the FITS file'

@classmethod
def fromhdulist(cls, hdulist, compress=False):

    fileobj = bs = io.BytesIO()
    if compress:
        if hasattr(hdulist, '_file'):
            name = fileobj_name(hdulist._file)
        else:
            name = None
        fileobj = gzip.GzipFile(name, mode='wb', fileobj=bs)
    hdulist.writeto(fileobj)
    if compress:
        fileobj.close()
    padding = (_pad_length(bs.tell()) * cls._padding_byte).encode('ascii')
    bs.write(padding)
    bs.seek(0)
    cards = [('XTENSION', cls._extension, 'FITS    extension'), ('BITPIX', 8, 'array    data    type'), ('NAXIS', 1, 'number    of    array    dimensions'), ('NAXIS1', len(bs.getvalue()), 'Axis    length'), ('PCOUNT', 0, 'number    of    parameters'), ('GCOUNT', 1, 'number    of    groups')]
    if (len(hdulist) > 1):
        for (idx, hdu) in enumerate(hdulist[1:]):
            cards.append((('XIND' + str((idx + 1))), hdu._header_offset, 'byte    offset    of    extension    {}'.format((idx + 1))))
    cards.append(('COMPRESS', compress, 'Uses    gzip    compression'))
    header = Header(cards)
    return cls._readfrom_internal(_File(bs), header=header)
