@since 0.0.1
@author Igor Ivanovic
@method Request#_compress

@description
Compress output
@return object
193159
function Request__compress(response) {
        var accept = this.getRequestHeader('Accept-Encoding'),
            isForCompress = (Type.isString(response) || response instanceof Buffer) && !this.isCompressed,
            that = this;

        if (this.isRendered) {
            // we have multiple recursion in parse for catching
            return false;
        }


        if (isForCompress && !!this.isCompressionEnabled && Type.isString(accept)) {
            if (!this.hasHeader('Vary')) {
                this.addHeader('Vary', 'Accept-Encoding');
            }
            if (accept.indexOf('gzip') > -1) {
                return new Promise(function (resolve, reject) {
                    zlib.gzip(response, function (err, data) {
                        if (err) {
                            return reject(err);
                        }
                        that.isCompressed = true;
                        that.addHeader('Content-Encoding', 'gzip');
                        resolve(data);
                    });
                });
            } else if (accept.indexOf('deflate') > -1) {
                return new Promise(function (resolve, reject) {
                    zlib.deflate(response, function (err, data) {
                        if (err) {
                            return reject(err);
                        }
                        that.isCompressed = true;
                        that.addHeader('Content-Encoding', 'deflate');
                        resolve(data);
                    });
                });
            }
        }

        return response;
    }
458691
function getCompressedStream(req, res) {
  var encoding = req.headers['accept-encoding'] || '';
  var stream;
  var contentEncodingHeader = res.getHeader('Content-Encoding');
  if ((contentEncodingHeader === 'gzip') || /\bgzip\b/.test(encoding)) {
    if (!contentEncodingHeader) {
      res.setHeader('Content-Encoding', 'gzip');
    }
    stream = zlib.createGzip();
    stream.pipe(res);
  } else if ((contentEncodingHeader === 'deflate') ||
      /\bdeflate\b/.test(encoding)) {
    if (!contentEncodingHeader) {
      res.setHeader('Content-Encoding', 'deflate');
    }
    stream = zlib.createDeflate();
    stream.pipe(res);
  }
  return stream;
}
1199976
function compress(data) {
    var HLOG = 16;
    var HSIZE = (1 << HLOG);
    var LZF_MAX_OFF = (1 << 13);
    var LZF_MAX_REF = ((1 << 8) + (1 << 3));
    var LZF_MAX_LIT = (1 <<  5);

    function FRST(data, p) {
        return (((data[p]) << 8) | data[p+1]);
    }

    function NEXT(v, data, p) {
        return (((v) << 8) | data[p+2]);
    }

    function IDX(h) {
        return (((h * 0x1e35a7bd) >> (32 - HLOG - 8)) & (HSIZE - 1));
    }

    var input = new Uint8Array(data);
    var output = [];
    var htab = new Uint32Array(HSIZE);

    var in_end = input.length, ip = 0, hval = FRST(input, ip);
    var op = 1, lit = 0; /* start run */

    while (ip < in_end - 2) {
        hval = NEXT(hval, data, ip);
        var hslot = IDX(hval);
        var ref = htab[hslot];
        htab[hslot] = ip;

        var off;

        if (ref < ip /* the next test will actually take care of this, but this is faster */
            && (off = ip - ref - 1) < LZF_MAX_OFF
            && ref > 0
            && input[ref + 2] == input[ip + 2]
            && input[ref + 1] == input[ip + 1]
            && input[ref] == input[ip]
        ) {
            /* match found at *ref++ */
            var len = 2;
            var maxlen = in_end - ip - len;
            maxlen = maxlen > LZF_MAX_REF ? LZF_MAX_REF : maxlen;

            output[op - lit - 1] = (lit - 1) & 255; /* stop run */
            if (lit == 0) {
                op -= 1; /* undo run if length is zero */
            }

            do {
                len++;
            }
            while (len < maxlen && input[ref + len] == input[ip + len]);

            len -= 2; /* len is now #octets - 1 */
            ip++;

            if (len < 7) {
                output[op++] = ((off >> 8) + (len << 5)) & 255;
            } else {
                output[op++] = ((off >> 8) + (7 << 5)) & 255;
                output[op++] = (len - 7) & 255;
            }

            output[op++] = off & 255;

            lit = 0; op++; /* start run */

            ip += len + 1;

            if (ip >= in_end - 2) {
                break;
            }

            --ip;
            --ip;
            hval = FRST(input, ip);

            hval = NEXT(hval, input, ip);
            htab[IDX(hval)] = ip++;

            hval = NEXT(hval, input, ip);
            htab[IDX(hval)] = ip++;
        } else {
            lit++;
            output[op++] = input[ip++];

            if (lit == LZF_MAX_LIT) {
                output[op - lit - 1] = (lit - 1) & 255; /* stop run */
                lit = 0; op++; /* start run */
            }
        }
    }

    while (ip < in_end) {
        lit++;
        output[op++] = input[ip++];

        if (lit == LZF_MAX_LIT) {
            output[op - lit - 1] = (lit - 1) & 255; /* stop run */
            lit = 0; op++; /* start run */
        }
    }

    if (lit != 0) {
        output[op - lit - 1] = (lit - 1) & 255; /* stop run */
    }

    // Return a Buffer if it exists (say in node), otherwise just
    // use a normal Uint8Array.
    if (typeof Buffer !== 'undefined') {
        return new Buffer(output);
    } else {
        var res = new Uint8Array(output.length);
        res.set(output);
        return res;
    }
}
1081004
protected function compress($code) {
        $compressor = new Compressor();
        $result = $compressor->setCode($code)
                             ->compress()
                             ->getCompressedCode();
        return $result;
    }
1331978
public static function zip()
    {
        $args = func_get_args();
        $originalArr = $args[0];

        array_shift($args);

        $array = [];

        foreach ($originalArr as $key => $value) {
            $array[$key] = [$value];

            foreach ($args as $k => $v) {
                $array[$key][] = current($args[$k]);

                if (next($args[$k]) === false && $args[$k] !== [null]) {
                    $args[$k] = [null];
                }
            }
        }

        return $array;
    }
925108
function _compress(command, outputFile) {
    return qexec(command)
        .then(function () {
            return outputFile.loadSize();
        })
        .fail(function (err) {
            // Before using of 'advpng' a raw file has to be copied
            // This algorithm can not compress a file and write a result to another file
            return qfs.exists(outputFile.name)
                .then(function (exists) {
                    if (exists) {
                        outputFile.remove();
                    }

                    throw err;
                });
        });
}
1352204
private function getCompressionMethod($method)
    {
        $compression_method = $this->getCompressionManager()->getCompressionAlgorithm($method);
        Assertion::notNull($compression_method, sprintf('Compression method "%s" not supported', $method));

        return $compression_method;
    }
1123042
function makeRequest () {
    request = self.request.apply(null, args);
    requestMiddleware.use(request);
    request.on("response", function (response) {
      var contentEncoding, gzipper;

      //Only cache successful responses
      if (response.statusCode >= 200 && response.statusCode < 300) {
        response.on('error', function (error) {
          self.handleError(error);
        });
        fs.writeFile(self.cacheDirectory + key + ".json", JSON.stringify(response.headers), function (error) {
          if (error) self.handleError(error);
        });

        responseWriter = fs.createWriteStream(self.cacheDirectory + key);

        responseWriter.on('error', function (error) {
          self.handleError(error);
        });

        contentEncoding = response.headers['content-encoding'] || '';
        contentEncoding = contentEncoding.trim().toLowerCase();

        if (contentEncoding === 'gzip') {
          response.on('error', function (error) {
            responseWriter.end();
          });
          response.pipe(responseWriter);
        } else {
          gzipper = zlib.createGzip();
          response.on('error', function (error) {
            gzipper.end();
          });
          gzipper.on('error', function (error) {
            self.handleError(error);
            responseWriter.end();
          });
          responseWriter.on('error', function (error) {
            response.unpipe(gzipper);
            gzipper.end();
          });
          response.pipe(gzipper).pipe(responseWriter);
        }
      }
    });
    self.emit("request", args[0]);
  }
257765
public function compress()
    {
        $this->archivePath = $this->compressedArchivePath . $this->buildArchiveFilename();

        $archive = $this->processor->getCompressionCommand($this->archivePath, $this->outputPath);

        $this->filesystem->mkdir($this->compressedArchivePath);
        $this->filesystem->mkdir($this->outputPath);
        $this->execute($archive);

        if ($this->splitter !== null) {
            $this->split();
        }
    }
1208845
public function setCompression(bool $active = true, int $level = -1)
  {
    if ($active) {
      # Extract Accept-Encoding request header (from Apache)
      $acceptEncoding = getAllheaders()['Accept-Encoding'] ?? '';

      # If the Client support GZip/Deflate Compression - do it!
      if (strpos($acceptEncoding, 'gzip') !== FALSE) {
        ini_set("zlib.output_compression", 2048); // Compression block size
        ini_set("zlib.output_compression_level", -1); // -1=Auto, 0=None, 9=Max
      } else {
        ini_set("zlib.output_compression_level", 0); // -1=Auto, 0=None, 9=Max
      }
    } else {
      ini_set("zlib.output_compression_level", 0); // -1=Auto, 0=None, 9=Max
    }

    return $this;
  }
1236436
function _compressOther(json, aKeys) {
    var oKeys,
      aKey,
      str,
      nLenKeys,
      nIndex,
      obj;
    aKeys = _getKeys(json, aKeys);
    aKeys = unique(aKeys);
    oKeys = _biDimensionalArrayToObject(aKeys);

    str = JSON.stringify(json);
    nLenKeys = aKeys.length;

    for (nIndex = 0; nIndex < nLenKeys; nIndex++) {
      aKey = aKeys[nIndex];
      str = str.replace(new RegExp(escapeRegExp('"' + aKey[1] + '"'), 'g'), '"' + aKey[0] + '"');
    }
    obj = JSON.parse(str);
    obj._ = oKeys;
    return obj;
  }
722012
public static function CompressEncode ($string, $encode = null) {
		if ($encode === null) {
			return static::Compress($string);
		}
		if (is_callable($encode)) {
			return $encode(static::Compress($string));
		}
		$encode_func_list = static::GetEncodeFunction();
		if (!isset($encode_func_list[$encode][static::ENCODE])) {
			return static::Compress($string);
		}
		return $encode_func_list[$encode][static::ENCODE](static::Compress($string));
	}
750154
def _compress(self, data, operation):
        
        # The 'algorithm' for working out how big to make this buffer is from
        # the Brotli source code, brotlimodule.cc.
        original_output_size = int(
            math.ceil(len(data) + (len(data) >> 2) + 10240)
        )
        available_out = ffi.new("size_t *")
        available_out[0] = original_output_size
        output_buffer = ffi.new("uint8_t []", available_out[0])
        ptr_to_output_buffer = ffi.new("uint8_t **", output_buffer)
        input_size = ffi.new("size_t *", len(data))
        input_buffer = ffi.new("uint8_t []", data)
        ptr_to_input_buffer = ffi.new("uint8_t **", input_buffer)

        rc = lib.BrotliEncoderCompressStream(
            self._encoder,
            operation,
            input_size,
            ptr_to_input_buffer,
            available_out,
            ptr_to_output_buffer,
            ffi.NULL
        )
        if rc != lib.BROTLI_TRUE:  # pragma: no cover
            raise Error("Error encountered compressing data.")

        assert not input_size[0]

        size_of_output = original_output_size - available_out[0]
        return ffi.buffer(output_buffer, size_of_output)[:]
1226600
private function fileCompress()
    {
        if ($this->file && $this->file->getTmp()) {
            $compression = $this->file->getCompression();
            if ($compression && in_array($compression, ['tar.gz', 'tar.bz2', 'zip'])) {
                // Discern new tmp file name (with compression applied).
                $target   = $this->fileGenerateTmp($compression);
                $fileName = $this->getFileName();
                try {
                    switch ($compression) {
                        case 'tar.gz':
                            $phar = new \PharData($target);
                            $phar->addFile($this->file->getTmp(), $fileName);
                            $phar->compress(\Phar::GZ, $compression);
                            $target = $phar->getRealPath();
                            break;

                        case 'tar.bz2':
                            $phar = new \PharData($target);
                            $phar->addFile($this->file->getTmp(), $fileName);
                            $phar->compress(\Phar::BZ2, $compression);
                            $target = $phar->getRealPath();
                            break;

                        default:
                        case 'zip':
                            $zip = new \ZipArchive();
                            if (true !== $zip->open($target, \ZipArchive::CREATE)) {
                                throw new ContactClientException(
                                    'Cound not open zip '.$target,
                                    Codes::HTTP_INTERNAL_SERVER_ERROR,
                                    null,
                                    Stat::TYPE_ERROR,
                                    false
                                );
                            }
                            $zip->addFile($this->file->getTmp(), $fileName);
                            $zip->close();
                            break;
                    }
                    $this->file->setTmp($target);
                    $this->setLogs($target, 'fileCompressed');
                } catch (\Exception $e) {
                    throw new ContactClientException(
                        'Could not create compressed file '.$target,
                        Codes::HTTP_INTERNAL_SERVER_ERROR,
                        $e,
                        Stat::TYPE_ERROR,
                        false
                    );
                }
            } else {
                $this->setLogs(false, 'fileCompressed');
            }
        }

        return $this;
    }
52605
public function compress()
    {
        if (!$this->collection->schema) {
            $this->compressed =& $this->data;

            return;
        }
        if ($this->state !== 'compressed' && $this->collection) {
            $this->compressed = $this->applyCompression($this->data);
            $this->asDotSyntax();
            $this->state = 'compressed';
        }
    }
1363722
public function send( $compression = NULL, $sendLengthHeader = TRUE, $exit = FALSE )
	{
		$response	= clone( $this->response );
		$length		= strlen( $response->getBody() );

		/*  --  COMPRESSION  --  */
		if( $compression )
		{
			$compressor	= new Net_HTTP_Response_Compressor;
			$compressor->compressResponse( $response, $compression, $sendLengthHeader );
			$lengthNow	= strlen( $response->getBody() );
			$ratio		= round( $lengthNow / $length * 100 );
		}

		/*  --  HTTP BASIC INFORMATION  --  */
		$status	= $response->getStatus();
		header( $response->getProtocol().'/'.$response->getVersion().' '.$status );
		header( 'Status: '.$status );

		/*  --  HTTP HEADER FIELDS  --  */
		foreach( $response->getHeaders() as $header )
			header( $header->toString(), false );

		/*  --  SEND BODY  --  */
		print( $response->getBody() );
		flush();
		if( $exit )
			exit;
		return strlen( $response->getBody() );
	}
1248691
def compress(func):
    """"""
    def wrapper(*args, **kwargs):
        """Wrapper that take one function and return the compressed result."""
        ret = func(*args, **kwargs)
        logger.debug('Receive {} {} request with header: {}'.format(
            request.method,
            request.url,
            ['{}: {}'.format(h, request.headers.get(h)) for h in request.headers.keys()]
        ))
        if 'deflate' in request.headers.get('Accept-Encoding', ''):
            response.headers['Content-Encoding'] = 'deflate'
            ret = deflate_compress(ret)
        else:
            response.headers['Content-Encoding'] = 'identity'
        return ret

    def deflate_compress(data, compress_level=6):
        """Compress given data using the DEFLATE algorithm"""
        # Init compression
        zobj = zlib.compressobj(compress_level,
                                zlib.DEFLATED,
                                zlib.MAX_WBITS,
                                zlib.DEF_MEM_LEVEL,
                                zlib.Z_DEFAULT_STRATEGY)

        # Return compressed object
        return zobj.compress(b(data)) + zobj.flush()

    return wrapper