/** This contains sample routines to gzip compress and gunzip decompress in memory, that is, without writing a file. It leverages Java's ByteArrayInputStream and ByteArrayOutput stream. */ /** Convert a string into a Java array of bytes. The inverse function is gunzipBytesToString. */ gzipStringToBytes[str is isString, encoding="UTF-8"] := { baos = newJava["java.io.ByteArrayOutputStream"] gz = gzip[baos] w = new Writer[gz, encoding] w.print[str] w.close[] return baos.toByteArray[] } /** Uncompresses a gzipped Java array of bytes into a string, such as that provided by the gzipStringToBytes function. */ gunzipBytesToString[bytes, encoding="UTF-8"] := { bais = newJava["java.io.ByteArrayInputStream", [bytes]] ugz = gunzip[bais] return read[ugz, encoding] }