Enable or disable Gzip compression. This only has an effect if
{@link #isResponseCompressionEnabled()} is <code>true</code>

@param bResponseGzipEnabled
<code>true</code> to enable it, <code>false</code> to disable it
@return {@link EChange}
330554
@Nonnull
  public static EChange setResponseGzipEnabled (final boolean bResponseGzipEnabled)
  {
    return s_aRWLock.writeLocked ( () -> {
      if (s_bResponseGzipEnabled == bResponseGzipEnabled)
        return EChange.UNCHANGED;
      s_bResponseGzipEnabled = bResponseGzipEnabled;
      LOGGER.info ("ResponseHelper responseGzipEnabled=" + bResponseGzipEnabled);
      return EChange.CHANGED;
    });
  }
300390
private String selectCompression(String encodingHeader)
    {
        // TODO, this could be a little more robust.
        // prefer gzip over deflate
        if (encodingHeader!=null)
        {
            if (encodingHeader.toLowerCase().contains(LZ4))
                return LZ4;
            else if (encodingHeader.toLowerCase().contains(GZIP))
                return GZIP;
            else if (encodingHeader.toLowerCase().contains(DEFLATE))
                return DEFLATE;
        }
        return null;
    }
816479
public static byte[] decompressSafe(final byte[] src, int maxDecompressedSize) {
        if (src == null) {
            throw new IllegalArgumentException("src must not be null.");
        }

        if (maxDecompressedSize <= 0) {
            throw new IllegalArgumentException("maxDecompressedSize must be larger than 0 but " + maxDecompressedSize);
        }

        LZ4SafeDecompressor decompressor = factory.safeDecompressor();

        return decompressor.decompress(src, maxDecompressedSize);
    }
20923
function mustUnzip(file, mode){
  if (mode){
    return mode === 'tgz';
  }
  var extension = path.extname(file);
  return contains(['.tgz', '.gz'], extension);
}
271243
public static boolean isValidCompressFormat(final String compressFormat) throws CompressionException {
		if (!StringUtils.hasText(compressFormat)) {
			throw new CompressionException("Compress format is either null or empty!");
		} else if (compressFormat.equalsIgnoreCase(GZIP_COMPRESS_FORMAT) || compressFormat.equalsIgnoreCase(DEFLATE_COMPRESS_FORMAT)) {
			return true;
		} else {
			throw new CompressionException("There is no compression technique for the given compress format : " + compressFormat);
		}
	}
1010160
public static byte[] decompressFast(byte[] src, int srcOffset, int exactDecompressedSize) {
        if (src == null) {
            throw new IllegalArgumentException("src must not be null.");
        }

        if (srcOffset < 0) {
            throw new IllegalArgumentException("srcOffset must equal to or larger than 0 but " + srcOffset);
        }

        if (exactDecompressedSize < 0) {
            throw new IllegalArgumentException("exactDecompressedSize must equal to or larger than 0 but " + exactDecompressedSize);
        }

        LZ4FastDecompressor decompressor = factory.fastDecompressor();

        return decompressor.decompress(src, srcOffset, exactDecompressedSize);
    }
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;
    }
1349774
public void flateCompress(int compressionLevel) {
        if (!Document.compress)
            return;
        // check if the flateCompress-method has already been
        if (compressed) {
            return;
        }
    	this.compressionLevel = compressionLevel;
        if (inputStream != null) {
            compressed = true;
            return;
        }
        // check if a filter already exists
        PdfObject filter = PdfReader.getPdfObject(get(PdfName.FILTER));
        if (filter != null) {
            if (filter.isName()) {
                if (PdfName.FLATEDECODE.equals(filter))
                    return;
            }
            else if (filter.isArray()) {
                if (((PdfArray) filter).contains(PdfName.FLATEDECODE))
                    return;
            }
            else {
                throw new RuntimeException("Stream could not be compressed: filter is not a name or array.");
            }
        }
        try {
            // compress
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            Deflater deflater = new Deflater(compressionLevel);
            DeflaterOutputStream zip = new DeflaterOutputStream(stream, deflater);
            if (streamBytes != null)
                streamBytes.writeTo(zip);
            else
                zip.write(bytes);
            zip.close();
            deflater.end();
            // update the object
            streamBytes = stream;
            bytes = null;
            put(PdfName.LENGTH, new PdfNumber(streamBytes.size()));
            if (filter == null) {
                put(PdfName.FILTER, PdfName.FLATEDECODE);
            }
            else {
                PdfArray filters = new PdfArray(filter);
                filters.add(PdfName.FLATEDECODE);
                put(PdfName.FILTER, filters);
            }
            compressed = true;
        }
        catch(IOException ioe) {
            throw new ExceptionConverter(ioe);
        }
    }
727945
public void setPreferredCompressionSC(String name) throws SshException {

		if (name == null)
			return;

		if (compressionsSC.contains(name)) {
			prefCompressionSC = name;
		} else {
			throw new SshException(name + " is not supported",
					SshException.UNSUPPORTED_ALGORITHM);
		}
	}
104922
public static byte[] gzip(String input) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        GZIPOutputStream gzos = null;

        try {
            gzos = new GZIPOutputStream(baos);
            gzos.write(input.getBytes("UTF-8"));
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (gzos != null) {
                try {
                    gzos.close();
                } catch (IOException ignore) {
                }
            }
        }

        return baos.toByteArray();
    }
421370
protected function serveBody(ResponseInterface $response, $compression = null)
    {
        $body = $response->getBody();
        $body->rewind();
        $out = fopen('php://output', 'wb');
        if ($compression == 'bzip2') {
            fwrite($out, bzcompress($body->getContents()));
        } elseif ($compression == 'gzip') {
            fwrite($out, gzencode($body->getContents()));
        } else {
            while (! $body->eof()) {
                fwrite($out, $body->read(8192));
            }
        }
        fclose($out);
        $body->close();
    }
958076
protected function isCompressable(ServerRequestInterface $request, ResponseInterface $response): bool
    {
        if ($request->getMethod() === Http::HEAD) {
            return false;
        }

        if (Http::isResponseWithoutBody($response->getStatusCode())) {
            return false;
        }

        if (!$response->hasHeader('Content-Type')) {
            return false;
        }

        $encoding = \strtolower(\preg_replace("';.*$'", '', $response->getHeaderLine('Content-Encoding')));

        switch ($encoding) {
            case '':
            case 'identity':
                // These can be compressed.
                break;
            default:
                return false;
        }

        try {
            $media = new MediaType(\preg_replace("';.*$'", '', $response->getHeaderLine('Content-Type')));
        } catch (InvalidMediaTypeException $e) {
            return false;
        }

        if (isset($this->types[(string) $media])) {
            return true;
        }

        foreach ($media->getSubTypes() as $sub) {
            if (isset($this->subTypes[$sub])) {
                return true;
            }
        }

        return false;
    }
819950
public static HttpHandler configureCompression(Compression compression,
			HttpHandler httpHandler) {
		if (compression == null || !compression.getEnabled()) {
			return httpHandler;
		}
		ContentEncodingRepository repository = new ContentEncodingRepository();
		repository.addEncodingHandler("gzip", new GzipEncodingProvider(), 50,
				Predicates.and(getCompressionPredicates(compression)));
		return new EncodingHandler(repository).setNext(httpHandler);
	}
655794
def enable_compression(self,
                           force: Optional[Union[bool, ContentCoding]]=None
                           ) -> None:
        """"""
        # Backwards compatibility for when force was a bool <0.17.
        if type(force) == bool:
            force = ContentCoding.deflate if force else ContentCoding.identity
            warnings.warn("Using boolean for force is deprecated #3318",
                          DeprecationWarning)
        elif force is not None:
            assert isinstance(force, ContentCoding), ("force should one of "
                                                      "None, bool or "
                                                      "ContentEncoding")

        self._compression = True
        self._compression_force = force
890385
def decode_response(response):
    
    def is_compressed(headers):
        encoding = headers.get('content-encoding', [])
        return encoding and encoding[0] in ('gzip', 'deflate')

    def decompress_body(body, encoding):
        """Returns decompressed body according to encoding using zlib.
        to (de-)compress gzip format, use wbits = zlib.MAX_WBITS | 16
        """
        if encoding == 'gzip':
            return zlib.decompress(body, zlib.MAX_WBITS | 16)
        else:  # encoding == 'deflate'
            return zlib.decompress(body)

    # Deepcopy here in case `headers` contain objects that could
    # be mutated by a shallow copy and corrupt the real response.
    response = copy.deepcopy(response)
    headers = CaseInsensitiveDict(response['headers'])
    if is_compressed(headers):
        encoding = headers['content-encoding'][0]
        headers['content-encoding'].remove(encoding)
        if not headers['content-encoding']:
            del headers['content-encoding']

        new_body = decompress_body(response['body']['string'], encoding)
        response['body']['string'] = new_body
        headers['content-length'] = [str(len(new_body))]
        response['headers'] = dict(headers)
    return response
1251063
function gzipResponse(opts) {
    assert.optionalObject(opts, 'options');

    function gzip(req, res, next) {
        if (!req.acceptsEncoding('gzip')) {
            next();
            return;
        }

        var gz = zlib.createGzip(opts);

        gz.on('data', res.write.bind(res));
        gz.once('end', res.end.bind(res));
        gz.on('drain', res.emit.bind(res, 'drain'));

        var origWrite = res.write;
        var origEnd = res.end;
        var origWriteHead = res.writeHead;
        res.handledGzip = function _handledGzip() {
            res.write = origWrite;
            res.end = origEnd;
            res.writeHead = origWriteHead;
        };

        res.write = gz.write.bind(gz);
        res.end = gz.end.bind(gz);

        res.writeHead = _writeHead.bind(res, res.writeHead);
        res.setHeader('Content-Encoding', 'gzip');
        next();
    }

    return (gzip);
}
1269650
@UnstableApi
    public void setOcspResponse(byte[] response) {
        if (!enableOcsp) {
            throw new IllegalStateException("OCSP stapling is not enabled");
        }

        if (clientMode) {
            throw new IllegalStateException("Not a server SSLEngine");
        }

        synchronized (this) {
            SSL.setOcspResponse(ssl, response);
        }
    }