complements the compressBuffer function in CacheClient
178105
def decompressBuffer(buffer):
    ""
    zbuf = cStringIO.StringIO(buffer)
    zfile = gzip.GzipFile(fileobj=zbuf)
    deflated = zfile.read()
    zfile.close()
    return deflated
1174352
function encodeBuffer(buf, options, cb) {
  if (typeof options === 'function') {
    cb = options;
    options = {};
  }

  try {
    buf = bufferUtils.toArrayLike(buf);

    if (!options.hasOwnProperty('width') || !options.hasOwnProperty('height')) {
      return cb(new Error('Provide width & height of the buffer'));
    }

    if (_hasWorker.hasWorker) {
      const wr = require('webworkify')(_encodeWorker2.default);

      wr.onmessage = ({ data: msg }) => {
        const err = msg.err ? new Error(msg.err) : undefined;
        cb(err, msg.result);
      };

      const msg = {
        buf: buf,
        options: options
      };

      if (options.transferable) {
        wr.postMessage(msg, [buf]);
      } else {
        wr.postMessage(msg);
      }
    } else {
      (0, _encode2.default)(buf, options, cb);
    }
  } catch (err) {
    cb(err);
  }
}
786295
function(buffer) {
      if (buffer && self._sounds.length > 0) {
        cache[self._src] = buffer;
        loadSound(self, buffer);
      } else {
        error();
      }
    }
687007
def FlushCache(self):
    """"""
    self._cache = b''
    self._cache_start_offset = None
    self._cache_end_offset = None
    self._ResetDecompressorState()
420654
private ByteBuffer encodeAndAllocateBuffer(String key) {
        if (key == null) {
            return ByteBuffer.wrap(EMPTY);
        }

        CharsetEncoder encoder = CharsetUtil.encoder(charset);
        ByteBuffer buffer = ByteBuffer.allocate((int) (encoder.maxBytesPerChar() * key.length()));

        ByteBuf byteBuf = Unpooled.wrappedBuffer(buffer);
        byteBuf.clear();
        encode(key, byteBuf);
        buffer.limit(byteBuf.writerIndex());

        return buffer;
    }
1293101
function cache(db, defaults, callback) {
    var cached = new EventEmitter()
        , args = parse(db, defaults, callback) // Arguments ~_~

    callback = args[2]
    defaults = extend({}, defaultOptions, args[1])
    db = args[0]

    var cache = LRUCache(defaults)
        , readStream = LevelReadStream(db, cache, args[1])

    extend(cached, {
        put: put
        , del: del
        , get: get
        , batch: batch
        , isOpen: value(true)
        , isClosed: value(false)
        , open: open
        , close: close
        , writeStream: LevelWriteStream(cached)
        , readStream: readStream
        , keyStream: keyStream
        , valueStream: valueStream
    })

    process.nextTick(function () {
        callback && callback(cached)
        cached.emit("ready")
    })

    return cached

    function put(key, value, options, callback) {
        var _callback = cb(options, callback)
            , _options = getOptions(defaults, options)
            , _key = toKeyBuffer(key, _options)

        cache.set(_key, value)

        if (db) {
            db.put(key, value, _options, _callback || emit)
        }

        cached.emit("put", key, value)
        _callback && _callback(null)
    }

    function del(key, options, callback) {
        var _callback = cb(options, callback)
            , _options = getOptions(defaults, options)
            , _key = toKeyBuffer(key, _options)

        cache.del(_key)

        if (db) {
            db.del(key, _options, _callback || emit)
        }

        cached.emit("del", key)
        _callback && _callback(null)
    }

    function get(key, options, callback) {
        var _callback = cb(options, callback)
            , _options = getOptions(defaults, options)
            , _key = toKeyBuffer(key, _options)
            , value = cache.get(_key)

        if (_callback && value !== undefined &&
            _options.cache !== false
        ) {
            return _callback(null, value)
        }

        if (db && _callback) {
            return db.get(key, _options, _callback || emit)
        }

        return value
    }

    function batch(arr, options, callback) {
        var _callback = cb(options, callback)
            , _options = getOptions(defaults, options)

        arr.forEach(function (item) {
            var key = toKeyBuffer(item.key, _options)
                , value = item.value
                , type = item.type

            if (type === "put") {
                cache.set(key, value)
            } else if (type === "del") {
                cache.del(key)
            }
        })

        if (db) {
            db.batch(arr, _options, _callback || emit)
        }

        cached.emit("batch", arr)
        _callback && _callback(null)
    }

    function valueStream(options) {
        return readStream(extend(options || {}, {
            keys: false
            , values: true
        }))
    }

    function keyStream(options) {
        return readStream(extend(options || {}, {
            keys: true
            , values: false
        }))
    }

    function open(callback) {
        callback && callback()
    }

    function close(callback) {
        cache.reset()
        cached.emit("closed")
        callback && callback()
    }

    function emit(err) {
        if (err) {
            return cached.emit("error", err)
        }
    }
}
1052747
protected boolean fillByteCache(WsByteBuffer buff) {
        if (this.bytePosition < this.byteLimit) {
            return false;
        }

        int size = buff.remaining();
        if (size > this.byteCacheSize) {
            // truncate to just fill up the cache
            size = this.byteCacheSize;
        }
        this.bytePosition = 0;
        this.byteLimit = size;
        if (0 == this.byteLimit) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "fillByteCache: no data");
            }
            return false;
        }
        if (HeaderStorage.NOTSET != this.headerChangeLimit && -1 != this.parseIndex
            && -1 == this.parseBuffersStartPos[this.parseIndex]) {
            // first occurrance of this buffer and we're keeping track of changes
            this.parseBuffersStartPos[this.parseIndex] = buff.position();
        }
        buff.get(this.byteCache, this.bytePosition, this.byteLimit);

        return true;
    }
1129254
function makeCacheable(rawFunction) {
    var lastArguments;
    var currentArguments;
    var lastResult;
    var cacheFunction = function () {
        currentArguments = arguments;
        if (lastArguments == undefined || Array.prototype.some.call(lastArguments, function (value, index) {
            return value != currentArguments[index];
        })) {
            lastResult = rawFunction.apply(null, currentArguments);
            lastArguments = currentArguments;
        }
        return lastResult;
    };
    return cacheFunction;
}
325476
def _write_cache(self, lines, append=False):
        """"""
        mode = 'at' if append else 'wt'
        with open(self.filepath, mode, encoding='utf8') as fh:
            fh.writelines(line + '\n' for line in lines)
133286
function encodeParams(cache, API_URL, params) {
  var obj = {}, v;
  for (var k in params) {
    if (!params.hasOwnProperty(k)) continue;
    v = obj[k] = encode(cache, API_URL, params[k]);
    if (!v) return;
  }
  return obj;
}
436069
private static synchronized Object getFromCache(Cache cache,
            byte[] encoding) {
        Object key = new Cache.EqualByteArray(encoding);
        Object value = cache.get(key);
        return value;
    }
460662
function decompressSessionData(objData) {
    let amorphicOptions = AmorphicContext.amorphicOptions;
    if (amorphicOptions.compressSession && objData.data) {
        let buffer = new Buffer(objData.data);

        return zlib.inflateSync(buffer);
    }

    return objData;
}
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;
}
674285
function LZ4_compress (input, options) {
	var output = []
	var encoder = new Encoder(options)

	encoder.on('data', function (chunk) {
		output.push(chunk)
	})

	encoder.end(input)

	return Buffer.concat(output)
}
1204559
function putCache() {
      return new Promise(function(resolve, reject) {
        // make the cache key
        let key = getKey();

        // adapt the image
        adapt(function(err, stdout, stderr) {
          if (err) {
            return reject(err);
          }

          // convert the new image stream to buffer
          stream2buffer(stdout, function(err, buffer) {
            if (err) {
              return reject(err);
            }

            if (!buffer || !buffer.length) {
              return resolve(buffer);
            }

            // put the buffer in the cache
            put(key, buffer, function(err, data) {
              if (err) {
                log(`Cache set failure: ${err instanceof Error ? err.message : err}`);
              }

              // return the buffer
              resolve(buffer);
            });
          });
        });
      });
    }
910394
function responseToBuffer(clientResponse, callback) {
    var buffer = { 
        url: clientResponse.url,
        method: clientResponse.method,
        statusCode: clientResponse.statusCode,
        headers: { },
        data: [ ]
    };
    Object.keys(clientResponse.headers).forEach(function (k) {
        buffer.headers[k] = clientResponse.headers[k];
    });
    clientResponse.on('data', function (chunk) {
        buffer.data.push(chunk);
        // @TODO If data gets too big, callback(null)
    });
    clientResponse.on('end', function () {
        // @TODO Dispose of clientResponse and remove listeners?
        callback(buffer);
    });
    clientResponse.on('close', function () {
        // @TODO Dispose of clientResponse and remove listeners?
        callback(null);
    });
}
1096704
def _mk_cache_fn(vcf_fn, array_type, region=None, cachedir=None,
                 compress=False):
    """"""

    # ensure cache dir exists
    if cachedir is None:
        # use the VCF file name as the base for a directory name
        cachedir = vcf_fn + config.CACHEDIR_SUFFIX
    if not os.path.exists(cachedir):
        # ensure cache dir exists
        os.makedirs(cachedir)
    else:
        assert os.path.isdir(cachedir), \
            'unexpected error, cache directory is not a directory: %r' \
            % cachedir

    # handle compression
    if compress:
        suffix = 'npz'
    else:
        suffix = 'npy'

    # handle region
    if region is None:
        # loading the whole genome (i.e., all variants)
        cache_fn = os.path.join(cachedir, '%s.%s' % (array_type, suffix))
    else:
        # loading a specific region
        region = region.replace(':', '__').replace('-', '_')
        cache_fn = os.path.join(cachedir, '%s.%s.%s' % (array_type, region,
                                                        suffix))
    return cache_fn