io.justdevit.kotlin.boost.compression.String.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of boost-commons Show documentation
Show all versions of boost-commons Show documentation
Library to boost working with Kotlin/JVM projects.
The newest version!
package io.justdevit.kotlin.boost.compression
import java.io.ByteArrayOutputStream
import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream
/**
* Compresses a string using GZIP-compression.
*
* @return The compressed string.
*/
fun String.compress(): String {
val bos = ByteArrayOutputStream()
GZIPOutputStream(bos).bufferedWriter().use { it.write(this) }
return bos.toByteArray().decodeToString()
}
/**
* Decompresses a GZIP-compressed string.
*
* @return The decompressed string.
*/
fun String.decompress(): String = GZIPInputStream(this.byteInputStream()).bufferedReader().use { it.readText() }
© 2015 - 2025 Weber Informatics LLC | Privacy Policy