Skip to main content
`Ctrl`+`K`

# Gzip2

class astropy.io.fits.hdu.compressed._codecs.Gzip2(*, itemsize)

  Bases: `Codec`

  The FITS GZIP2 compression and decompression algorithm.

  The gzip2 algorithm is a variation on ‘GZIP 1’. In this case the buffer in the array of data values are shuffled so that they are arranged in order of decreasing significance before being compressed.

  For example, a five-element contiguous array of two-byte (16-bit) integer values, with an original big-endian byte order of:

  \[A1 A2 B1 B2 C1 C2 D1 D2 E1 E2\]

  will have the following byte order after shuffling:

  \[A1 B1 C1 D1 E1 A2 B2 C2 D2 E2,\]

  where A1, B1, C1, D1, and E1 are the most-significant buffer from each of the integer values.

  Byte shuffling shall only be performed for integer or floating-point numeric data types; logical, bit, and character types must not be shuffled.

  Parameters:
    itemsize

      The number of buffer per value (e.g. 2 for a 16-bit integer)

  Attributes Summary

  `codec_id` |

  Methods Summary

  `decode`(buf) | Decompress buffer using the GZIP_2 algorithm.
  `encode`(buf) | Compress the data in the buffer using the GZIP_2 algorithm.

  Attributes Documentation

  codec_id = 'FITS_GZIP2'

  Methods Documentation

  decode(buf)

    Decompress buffer using the GZIP_2 algorithm.

    Parameters:
      buf `bytes` or numpy:array_like

        The buffer to decompress.

    Returns:
      buf `np.ndarray`

        The decompressed buffer.

  encode(buf)

    Compress the data in the buffer using the GZIP_2 algorithm.

    Parameters:
      buf `bytes` or numpy:array_like

        The buffer to compress.

    Returns:
      `bytes`

        The compressed bytes.