Helper function to compress an image with several compressors.

    In case the compressors do not improve the filesize or in case the resulting
    image is not equivalent to the source, then the output will be a copy of the
    input.
507533
def _compress_with(input_filename, output_filename, compressors):
    
    with _temporary_filenames(len(compressors)) as temp_filenames:
        results = []
        for compressor, temp_filename in zip(compressors, temp_filenames):
            results.append(_process(compressor, input_filename, temp_filename))
        best_result = min(results)
        os.rename(best_result.filename, output_filename)

        best_compressor = best_result.compressor
        if best_result.size >= os.path.getsize(input_filename):
            best_compressor = None

        if (best_compressor is not None and
                not _images_are_equal(input_filename, output_filename)):
            logging.info('Compressor "%s" generated an invalid image for "%s"',
                         best_compressor, input_filename)
            best_compressor = None

        if best_compressor is None:
            shutil.copy(input_filename, output_filename)

    logging.info('%s: best compressor for "%s"', best_compressor,
                 input_filename)
717764
function compressRun() {
    if (runLen > 1 && offset) {
      let ri = bi - runLen;
      diff[ri] = [offset, runLen];
      for (ri++; ri < bi; ri++) {
        delete diff[ri];
      }
    }
  }
446774
def convert(f, output=sys.stdout):
    

    r = f.read(11)
    if r == 'compressed\n':
        png(output, *decompress(f))
    else:
        png(output, *glue(f, r))
222004
def _compress_for_repeater(max_vol, plan, **kwargs):
    
    max_vol = float(max_vol)
    mode = kwargs.get('mode', 'transfer')
    if mode == 'distribute':   # combine target volumes into single aspirate
        return _compress_for_distribute(max_vol, plan, **kwargs)
    if mode == 'consolidate':  # combine target volumes into multiple aspirates
        return _compress_for_consolidate(max_vol, plan, **kwargs)
    else:
        return plan
101619
def decompress(chunks, compression):
    

    if compression not in SUPPORTED_COMPRESSIONS:
        raise TypeError('Unsupported compression type: %s' % (compression,))

    de_compressor = DECOMPRESSOR_FACTORIES[compression]()
    try:
        for chunk in chunks:
            try:
                yield de_compressor.decompress(chunk)
            except OSError as err:
                # BZ2Decompressor: invalid data stream
                raise DecompressError(err) from None

        # BZ2Decompressor does not support flush() method.
        if hasattr(de_compressor, 'flush'):
            yield de_compressor.flush()

    except zlib.error as err:
        raise DecompressError(err) from None
252834
def gzip_compress(data):
    
    buf = BytesIO()
    with gzip.GzipFile(fileobj=buf, mode='wb') as fd:
        fd.write(data)
    return buf.getvalue()
733270
def inline_compress_chunk(chunk, level=1):
    
    b = cStringIO.StringIO()
    g = gzip.GzipFile(fileobj=b, mode='wb', compresslevel=level)
    g.write(chunk)
    g.close()
    cc = b.getvalue()
    b.close()
    return cc
1269641
function decompress(compressedSize, b) {
	"use strict";
	var n = 0,
		r = 0,
		f = 0,
		s = 8,
		p = s,
		i = 0;
	var dst = new Buffer(compressedSize);
	var d = 12;
	var aa = new Int32Array(256);
	while (s < dst.length) {
		if (!i) {
			f = b[d++];
			i = 1;
		}
		if (f & i) {
			r = aa[b[d++]];
			dst[s++] = dst[r++];
			dst[s++] = dst[r++];
			n = 0xff & b[d++];
			for (var m = 0; m < n; m++) {
				dst[s + m] = dst[r + m];
			}
		} else {
			dst[s++] = b[d++];
		}
		while (p < (s - 1)) {
			aa[dst[p] ^ dst[p + 1]] = p++;
		}
		if (f & i) {
			p = (s += n);
		}
		i *= 2;
		if (i === 256) {
			i = 0;
		}
	}
	return dst;
}
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;
  }
797053
void compressOffsetArray(int i0) {
		int i_ = i0;
		while (m_offsetPts.get(i_).m_prev < i_)
			i_ = m_offsetPts.get(i_).m_prev;

		int j = 0, i = i_;

		do {
			GraphicPoint pt = m_offsetPts.get(i);
			m_offsetPts.set(j, pt);
			i = pt.m_next;
			j++;
		} while (i != i_);

		m_offsetPts.set(j, m_offsetPts.get(0)); // duplicate closing point

		m_offsetPtCount = j + 1;
	}
1159784
def _compress_obj(obj, level):
    
    return zlib.compress(pickle.dumps(obj, protocol=2), level)
541176
def _compress(compress):
    '''
    
    '''
    if compress in ('bz2', 'bzip2', 'j'):
        compression = 'j'
        ext = 'bz2'
    elif compress in ('gz', 'gzip', 'z'):
        compression = 'z'
        ext = 'gz'
    elif compress in ('xz', 'a', 'J'):
        compression = 'J'
        ext = 'xz'

    return compression, ext
285477
function _reduceImageOptimFunc(prev, next) {
        return prev.then(function (res) {
            return Q.all(next.map(function (filename) {
                return modes[mode](new File(filename), algorithms, opts);
            }))
            .then(function (stepRes) {
                return res.concat(stepRes);
            });
        });
    }
1128199
function compression (options) {
  var opts = options || {}

  // options
  var filter = opts.filter || shouldCompress
  var threshold = bytes.parse(opts.threshold)

  if (threshold == null) {
    threshold = 1024
  }

  return function compression (req, res, next) {
    var ended = false
    var length
    var listeners = []
    var stream

    var _end = res.end
    var _on = res.on
    var _write = res.write

    // flush
    res.flush = function flush () {
      if (stream) {
        stream.flush()
      }
    }

    // proxy

    res.write = function write (chunk, encoding) {
      if (ended) {
        return false
      }

      if (!this._header) {
        this._implicitHeader()
      }

      return stream
        ? stream.write(toBuffer(chunk, encoding))
        : _write.call(this, chunk, encoding)
    }

    res.end = function end (chunk, encoding) {
      if (ended) {
        return false
      }

      if (!this._header) {
        // estimate the length
        if (!this.getHeader('Content-Length')) {
          length = chunkLength(chunk, encoding)
        }

        this._implicitHeader()
      }

      if (!stream) {
        return _end.call(this, chunk, encoding)
      }

      // mark ended
      ended = true

      // write Buffer for Node.js 0.8
      return chunk
        ? stream.end(toBuffer(chunk, encoding))
        : stream.end()
    }

    res.on = function on (type, listener) {
      if (!listeners || type !== 'drain') {
        return _on.call(this, type, listener)
      }

      if (stream) {
        return stream.on(type, listener)
      }

      // buffer listeners for future stream
      listeners.push([type, listener])

      return this
    }

    function nocompress (msg) {
      debug('no compression: %s', msg)
      addListeners(res, _on, listeners)
      listeners = null
    }

    onHeaders(res, function onResponseHeaders () {
      // determine if request is filtered
      if (!filter(req, res)) {
        nocompress('filtered')
        return
      }

      // determine if the entity should be transformed
      if (!shouldTransform(req, res)) {
        nocompress('no transform')
        return
      }

      // vary
      vary(res, 'Accept-Encoding')

      // content-length below threshold
      if (Number(res.getHeader('Content-Length')) < threshold || length < threshold) {
        nocompress('size below threshold')
        return
      }

      var encoding = res.getHeader('Content-Encoding') || 'identity'

      // already encoded
      if (encoding !== 'identity') {
        nocompress('already encoded')
        return
      }

      // head
      if (req.method === 'HEAD') {
        nocompress('HEAD request')
        return
      }

      // compression method
      var accept = accepts(req)
      var method = accept.encoding(['gzip', 'deflate', 'identity'])

      // we really don't prefer deflate
      if (method === 'deflate' && accept.encoding(['gzip'])) {
        method = accept.encoding(['gzip', 'identity'])
      }

      // negotiation failed
      if (!method || method === 'identity') {
        nocompress('not acceptable')
        return
      }

      // compression stream
      debug('%s compression', method)
      stream = method === 'gzip'
        ? zlib.createGzip(opts)
        : zlib.createDeflate(opts)

      // add buffered listeners to stream
      addListeners(stream, stream.on, listeners)

      // header fields
      res.setHeader('Content-Encoding', method)
      res.removeHeader('Content-Length')

      // compression
      stream.on('data', function onStreamData (chunk) {
        if (_write.call(res, chunk) === false) {
          stream.pause()
        }
      })

      stream.on('end', function onStreamEnd () {
        _end.call(res)
      })

      _on.call(res, 'drain', function onResponseDrain () {
        stream.resume()
      })
    })

    next()
  }
}
564007
public static BufferedImage compression(BufferedImage src, int widthScale, int heightScale) {
        int oldWidth = src.getWidth();
        int oldHeight = src.getHeight();
        int width = oldWidth / widthScale + ((oldWidth % widthScale) > 0 ? 1 : 0);
        int height = oldHeight / heightScale + ((oldHeight % heightScale) > 0 ? 1 : 0);

        BufferedImage dest = new BufferedImage(width, height, src.getType());

        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                int rgb = src.getRGB(x * widthScale, y * heightScale);
                dest.setRGB(x, y, rgb);
            }
        }

        return dest;
    }
962876
def xz_compress_stream(src):
    
    compressor = lzma.LZMACompressor(
        check=lzma.CHECK_CRC64,
        filters=[
            {"id": lzma.FILTER_X86},
            {"id": lzma.FILTER_LZMA2,
             "preset": lzma.PRESET_DEFAULT},
        ])
    for block in src:
        encoded = compressor.compress(block)
        if encoded:
            yield encoded
    yield compressor.flush()
551671
function compress2(target, a, b, c) {
                        if (!canCompress(a)) {
                            return;
                        }
                        if (!canCompress(b)) {
                            return;
                        }
                        if (!canCompress(c)) {
                            return;
                        }
                        // Compress
                        styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c];
                        delete styles[a];
                        delete styles[b];
                        delete styles[c];
                    }