Decompression is applied if the first to bytes matches with
  the gzip magic numbers. 
  There is once chance in 65536 that a file that is not gzipped will
  be ungzipped.
179759
def gunzip(content):
  
  gzip_magic_numbers = [ 0x1f, 0x8b ]
  first_two_bytes = [ byte for byte in bytearray(content)[:2] ]
  if first_two_bytes != gzip_magic_numbers:
    raise DecompressionError('File is not in gzip format. Magic numbers {}, {} did not match {}, {}.'.format(
      hex(first_two_bytes[0]), hex(first_two_bytes[1])), hex(gzip_magic_numbers[0]), hex(gzip_magic_numbers[1]))

  stringio = BytesIO(content)
  with gzip.GzipFile(mode='rb', fileobj=stringio) as gfile:
    return gfile.read()
1294717
private static String decompress(String str) throws EncoderException {
    /* First base64 decode the string */
    byte[] bytes = Base64.decodeBase64(str);
    GZIPInputStream zi = null;
    try {
      zi = new GZIPInputStream(new ByteArrayInputStream(bytes));
      InputStreamReader reader = new InputStreamReader(zi);
      BufferedReader in = new BufferedReader(reader);
      StringBuilder sb = new StringBuilder();
      String read;
      while ((read = in.readLine()) != null) {
        sb.append(read + "\n");
      }

      String molfile = sb.toString();
      reader.close();
      in.close();
      zi.close();
      return molfile;

    } catch (IOException e) {
      throw new EncoderException("Molfile could not be decompressed. " + str);
    } finally {
      IOUtils.closeQuietly(zi);
    }

  }
1172952
def __decompressContent(coding, pgctnt):
    '''
    
    '''

    log.trace("Decompressing %s byte content with compression type: %s", len(pgctnt), coding)

    if coding == 'deflate':
        pgctnt = zlib.decompress(pgctnt, -zlib.MAX_WBITS)

    elif coding == 'gzip':
        buf = io.BytesIO(pgctnt)
        f = gzip.GzipFile(fileobj=buf)
        pgctnt = f.read()

    elif coding == "sdch":
        raise ValueError("SDCH compression is not currently supported")
    elif coding == "br":
        raise ValueError("Brotli compression is not currently supported")
    elif coding == "compress":
        raise ValueError("LZW compression is not currently supported")

    elif coding == 'identity':
        pass

    log.trace("Content size after decompression: %s", len(pgctnt))
    return pgctnt
1092644
def ungzipper(fh, blocksize=16384):
    
    import zlib
    uzip = zlib.decompressobj(16 + zlib.MAX_WBITS)
    data = uzip.decompress(fh.read(blocksize)).split("\n")

    while len(data[0]):
        # last chunk might not be a full line.
        save = data.pop()
        for line in data:
            yield line
        data = uzip.decompress(fh.read(blocksize)).split("\n")
        # first line is prepended with saved chunk from end of last set.
        data[0] = save + data[0]
64766
private int decodeNextBWTByte() {
        int mergedPointer = bwtCurrentMergedPointer;
        int nextDecodedByte =  mergedPointer & 0xff;
        bwtCurrentMergedPointer = bwtMergedPointers[mergedPointer >>> 8];

        if (blockRandomised) {
            if (--randomCount == 0) {
                nextDecodedByte ^= 1;
                randomIndex = (randomIndex + 1) % 512;
                randomCount = Bzip2Rand.rNums(randomIndex);
            }
        }
        bwtBytesDecoded++;

        return nextDecodedByte;
    }
373072
public static String decompressFromBase64String(String compressed) throws IOException {
        return decompressString(Base64.decode(compressed.getBytes(StandardCharsets.UTF_8)));
    }
483892
public static void decompress(File source, File target) throws IOException {
        ZipInputStream zipIn = new ZipInputStream(new BufferedInputStream(new FileInputStream(source), BUFFER));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(target));
        zipIn.getNextEntry();
        byte data[] = new byte[BUFFER];

        int count = 0;
        while ((count = zipIn.read(data, 0, BUFFER)) != -1) {
            bos.write(data, 0, count);
        }
        bos.close();
        zipIn.close();
    }
58573
function(w) {
    w &= 0xffff;
    if(zip_outoff + zip_outcnt < zip_OUTBUFSIZ - 2) {
	zip_outbuf[zip_outoff + zip_outcnt++] = (w & 0xff);
	zip_outbuf[zip_outoff + zip_outcnt++] = (w >>> 8);
    } else {
	zip_put_byte(w & 0xff);
	zip_put_byte(w >>> 8);
    }
}
1328541
public boolean shouldGzip(String contentType) {
    if(gzipList == null || gzipList.isEmpty()) {
      return true;
    } else {
      return gzipList.contains(contentType) || gzipList.contains(contentType.replaceAll("/[^/]+\\Z", "/*")) || gzipList.contains(contentType.replaceAll("\\A[^/]+/", "*/"));
    }
  }
453713
def _check_gzipped_input(in_file, data):
    
    grabix = config_utils.get_program("grabix", data["config"])
    is_bgzip = subprocess.check_output([grabix, "check", in_file])
    if is_bgzip.strip() == "yes":
        return False, False
    else:
        return True, True
1098743
function shouldCompressGzip(req) {
  const headers = req.headers;

  return headers && headers['accept-encoding'] &&
    headers['accept-encoding']
      .split(',')
      .some(el => ['*', 'compress', 'gzip', 'deflate'].indexOf(el.trim()) !== -1)
  ;
}
361702
def gzip_encode(data):
    
    if not gzip:
        raise NotImplementedError
    f = StringIO.StringIO()
    gzf = gzip.GzipFile(mode="wb", fileobj=f, compresslevel=1)
    gzf.write(data)
    gzf.close()
    encoded = f.getvalue()
    f.close()
    return encoded
851294
static byte[] unzipForHeader( byte[] bs, int chkSize ) {

    ByteArrayInputStream bais = new ByteArrayInputStream(bs);
    ZipInputStream zis = new ZipInputStream(bais);

    InputStream is = zis;

    // Now read from the compressed stream
    int off = 0;

    try {
      while( off < bs.length ) {
        int len = 0;
        len = is.read(bs, off, bs.length - off);
        if( len < 0 )
          break;
        off += len;
        if( off == bs.length ) { // Dataset is uncompressing alot! Need more space...
          if( bs.length >= chkSize )
            break; // Already got enough
          bs = Arrays.copyOf(bs, bs.length * 2);
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    try {
      is.close();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return bs;
  }
306481
private static byte[] decode(String s, int options)
	{
		byte[] bytes;
		try
		{
			bytes = s.getBytes(PREFERRED_ENCODING);
		}
		catch (java.io.UnsupportedEncodingException uee)
		{
			bytes = s.getBytes(); // Uses native encoding
			// CHECKME: Is this correct? I think it should be a warning instead of an error since nothing
			// is re-thrown. I do think that *some* sort of logging is in order here especially since UTF-8 should
			// always be available on all platforms. If it's not, then all bets are off on your runtime env. - Kevin Wall
		}

		// Decode
		bytes = decode(bytes, 0, bytes.length, options);

		// Check to see if it's gzip-compressed
		// GZIP Magic Two-Byte Number: 0x8b1f (35615)
		if (bytes != null && bytes.length >= 4)
		{

			int head = ((int) bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00);
			if (java.util.zip.GZIPInputStream.GZIP_MAGIC == head)
			{
				java.io.ByteArrayInputStream bais = null;
				java.util.zip.GZIPInputStream gzis = null;
				java.io.ByteArrayOutputStream baos = null;
				byte[] buffer = new byte[2048];
				int length = 0;

				try
				{
					baos = new java.io.ByteArrayOutputStream();
					bais = new java.io.ByteArrayInputStream(bytes);
					gzis = new java.util.zip.GZIPInputStream(bais);

					while ((length = gzis.read(buffer)) >= 0)
					{
						baos.write(buffer, 0, length);
					} // end while: reading input

					// No error? Get new bytes.
					bytes = baos.toByteArray();

				} // end try
				catch (java.io.IOException e)
				{
					// Just return originally-decoded bytes
				} // end catch
				finally
				{
					try
					{
						baos.close();
					}
					catch (Exception e)
					{
					}
					try
					{
						gzis.close();
					}
					catch (Exception e)
					{
					}
					try
					{
						bais.close();
					}
					catch (Exception e)
					{
					}
				} // end finally

			} // end if: gzipped
		} // end if: bytes.length >= 2

		return bytes;
	}
516252
static void lowLevelUncompressBytes(
      final byte[] byteArray,          // output
      final int numBytesToDecode,      // input (but refers to the output)
      final short[] decodingTable,     // input
      final int[] compressedWords,     // input
      final long numCompressedWords) { // input

    int byteIndex = 0;
    int nextWordIndex = 0;
    long bitBuf = 0;
    int bufBits = 0;

    assert (byteArray != null);
    assert (decodingTable != null);
    assert (compressedWords != null);

    for (byteIndex = 0; byteIndex < numBytesToDecode; byteIndex++) {
      //MAYBE_FILL_BITBUF(compressedWords,wordIndex,12); // ensure 12 bits in bit buffer
      if (bufBits < 12) { // Prepare for a 12-bit peek into the bitstream.
        bitBuf |= ((compressedWords[nextWordIndex++] & 0XFFFF_FFFFL) << bufBits);
        bufBits += 32;
      }

      // These 12 bits will include an entire Huffman codeword.
      final int peek12 = (int) (bitBuf & 0XFFFL);
      final int lookup = decodingTable[peek12] & 0XFFFF;
      final int codeWordLength = lookup >>> 8;
      final byte decodedByte = (byte) (lookup & 0XFF);
      byteArray[byteIndex] = decodedByte;
      bitBuf >>>= codeWordLength;
      bufBits -= codeWordLength;
    }

    // Buffer over-run should be impossible unless there is a bug.
    // However, we might as well check here.
    assert (nextWordIndex <= numCompressedWords);
  }
95087
function decompressValue(value) {
  if (value === 0)
    return 0;

  value--;

  let exp = value % 10;

  value = (value - exp) / 10;

  let n;
  if (exp < 9) {
    const last = value % 9;
    value = (value - last) / 9;
    n = value * 10 + last + 1;
  } else {
    n = value + 1;
  }

  while (exp > 0) {
    n *= 10;
    exp--;
  }

  return n;
}
1280289
private boolean isMessageCompressed() {
        String contentEncoding = m_request.getHeader(HttpDefs.CONTENT_ENCODING);
        if (contentEncoding != null) {
            if (!contentEncoding.equalsIgnoreCase("gzip")) {
                throw new IllegalArgumentException("Unsupported Content-Encoding: " + contentEncoding);
            }
            return true;
        }
        return false;
    }