Uncompress a string value that was compressed using GZIP.
544212
public static String uncompress(String compressedValue) throws IOException {
        if (compressedValue == null)
            return null;

        ByteArrayInputStream in = new ByteArrayInputStream(compressedValue.getBytes("ISO-8859-1"));
        GZIPInputStream gzip = null;
        Reader reader = null;
        try {
            String value = "";
            gzip = new GZIPInputStream(in);
            reader = new InputStreamReader(gzip, "ISO-8859-1");
            int i;
            while ((i = reader.read()) != -1)
                value += (char) i;
            return value;
        }
        finally {
            if (gzip != null)
                gzip.close();
            if (reader != null)
                reader.close();
        }
    }
787319
function compressValue(value) {
  if (value === 0)
    return 0;

  let exp = 0;
  while (value % 10 === 0 && exp < 9) {
    value /= 10;
    exp++;
  }

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

  return 10 + 10 * (value - 1);
}
604801
def slugify(value, separator="-"):
    """"""
    if not isinstance(value, str):
        raise ValueError("value must be a Unicode string")
    value = _NOT_WORD_RE.sub(" ", value)
    value = unicodedata.normalize("NFKD", value)
    value = value.encode("ascii", "ignore")
    value = value.decode("ascii")
    value = value.strip().lower()
    value = re.sub(fr"[{separator}_\s]+", separator, value)
    return value
1057674
def from_bytes(self, string):
        """"""
        msg = srsly.msgpack_loads(gzip.decompress(string))
        self.attrs = msg["attrs"]
        self.strings = set(msg["strings"])
        lengths = numpy.fromstring(msg["lengths"], dtype="int32")
        flat_spaces = numpy.fromstring(msg["spaces"], dtype=bool)
        flat_tokens = numpy.fromstring(msg["tokens"], dtype="uint64")
        shape = (flat_tokens.size // len(self.attrs), len(self.attrs))
        flat_tokens = flat_tokens.reshape(shape)
        flat_spaces = flat_spaces.reshape((flat_spaces.size, 1))
        self.tokens = NumpyOps().unflatten(flat_tokens, lengths)
        self.spaces = NumpyOps().unflatten(flat_spaces, lengths)
        for tokens in self.tokens:
            assert len(tokens.shape) == 2, tokens.shape
        return self
418765
function unPrefix(s, prefix) {
  s = str(s);
  if (!prefix) return s;
  if (s.slice(0, prefix.length) === prefix) return s.slice(prefix.length);
  return s;
}
475965
private static String compress(String str) throws EncoderException {
	ByteArrayOutputStream rstBao = null;
	GZIPOutputStream zos = null;
    try {
    	rstBao = new ByteArrayOutputStream();
    	zos = new GZIPOutputStream(rstBao);
    	zos.write(str.getBytes());
    	IOUtils.closeQuietly(zos);
	    
    	byte[] bytes = rstBao.toByteArray();
    	return Base64.encodeBase64String(bytes);
    } catch(Exception e){
    	throw new EncoderException("Molfile could not be compressed. " + str);
   } finally{
	   IOUtils.closeQuietly(zos);
   }
	  
  }
842582
public void compress ()
    {
        for (Iterator<int[]> itr = values().iterator(); itr.hasNext(); ) {
            if (itr.next()[0] == 0) {
                itr.remove();
            }
        }
    }
1264917
def removeSpacePadding(str, blocksize=AES_blocksize):
    '' 
    pad_len = 0    
    for char in str[::-1]: # str[::-1] reverses string
        if char == ' ':
            pad_len += 1
        else:
            break

    str = str[:-pad_len]
   
    return str
1129691
def decompress(self, value):
        
        if hasattr(value, "select_related"):
            keywords = [a.keyword for a in value.select_related("keyword")]
            if keywords:
                keywords = [(str(k.id), k.title) for k in keywords]
                self._ids, words = list(zip(*keywords))
                return (",".join(self._ids), ", ".join(words))
        return ("", "")
75639
def unescape(s):
    """"""
    s = bytearray(s)
    i = 0
    while i < len(s):
        if s[i] == ord('%'):
            hex_bytes = bytes(s[i+1:i+3])
            value = int(hex_bytes.decode('ascii'), 16)
            s[i:i+3] = [value]
        i += 1
    return bytes(s)
1055572
def uncompress_files(original, destination):
    
    with zipfile.ZipFile(original) as zips:
        extract_path = os.path.join(destination)
        zips.extractall(extract_path)
1228505
public static String uncompressString(byte[] input, int offset, int length)
            throws IOException
    {
        try {
            return uncompressString(input, offset, length, "UTF-8");
        }
        catch (UnsupportedEncodingException e) {
            throw new IllegalStateException("UTF-8 decoder is not found");
        }
    }
716583
public static byte[] decompress(byte[] value, int prefix) throws CorruptEncodingException {
        Inflater inflater = cLocalInflater.get();
        if (inflater == null) {
            cLocalInflater.set(inflater = new Inflater());
        }

        ByteArrayOutputStream bos = new ByteArrayOutputStream(value.length * 2);

        try {
            bos.write(value, 0, prefix);
            InflaterOutputStream ios = new InflaterOutputStream(bos, inflater);
            ios.write(value, prefix, value.length - prefix);
            ios.close();
            return bos.toByteArray();
        } catch (ZipException e) {
            // Assume it wasn't compressed.
            return value;
        } catch (IOException e) {
            throw new CorruptEncodingException(e);
        } finally {
            inflater.reset();
        }
    }
1008038
function gzip(input, options) {
  options = options || {};
  options.gzip = true;
  return deflate(input, options);
}
572817
def _unpack(self, content):
        """"""
        if self.compressor:
            try:
                content = self.compressor.decompress(content)
            except CompressError:
                pass
        if self.serializer:
            content = self.serializer.deserialize(content)
        return content
583209
@SneakyThrows(IOException.class)
    public static String compressToBase64(final String string) {
        Preconditions.checkNotNull(string, "string");
        @Cleanup
        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        @Cleanup
        final OutputStream base64OutputStream = Base64.getEncoder().wrap(byteArrayOutputStream);
        @Cleanup
        final GZIPOutputStream gzipOutputStream = new GZIPOutputStream(base64OutputStream);
        gzipOutputStream.write(string.getBytes(UTF_8));
        gzipOutputStream.close();
        return byteArrayOutputStream.toString(UTF_8.name());
    }
629670
def gzip(self, data, truncate=True):
        '''
        
        '''
        # Entropy is a simple ratio of: <zlib compressed size> / <original
        # size>
        e = float(float(len(zlib.compress(str2bytes(data), 9))) / float(len(data)))

        if truncate and e > 1.0:
            e = 1.0

        return e