'Compress the image data so that it may be written to a file.'

def _update_compressed_data(self):

    image_bitpix = DTYPE2BITPIX[self.data.dtype.name]
    if ((image_bitpix != self._orig_bitpix) or (self.data.shape != self.shape)):
        self._update_header_data(self.header)
    old_data = self.data
    if _is_pseudo_unsigned(self.data.dtype):
        self.data = np.array((self.data - _unsigned_zero(self.data.dtype)), dtype='=i{}'.format(self.data.dtype.itemsize))
        should_swap = False
    else:
        should_swap = (not self.data.dtype.isnative)
    if should_swap:
        if self.data.flags.writeable:
            self.data.byteswap(True)
        else:
            self.data = self.data.byteswap(False)
    try:
        nrows = self._header['NAXIS2']
        tbsize = (self._header['NAXIS1'] * nrows)
        self._header['PCOUNT'] = 0
        if ('THEAP' in self._header):
            del self._header['THEAP']
        self._theap = tbsize
        del self.compressed_data
        (heapsize, self.compressed_data) = compression.compress_hdu(self)
    finally:
        if should_swap:
            self.data.byteswap(True)
        self.data = old_data
    dtype = self.columns.dtype.newbyteorder('>')
    buf = self.compressed_data
    compressed_data = buf[:self._theap].view(dtype=dtype, type=np.rec.recarray)
    self.compressed_data = compressed_data.view(FITS_rec)
    self.compressed_data._coldefs = self.columns
    self.compressed_data._heapoffset = self._theap
    self.compressed_data._heapsize = heapsize
