Skip to content
Snippets Groups Projects
Commit dd9f32e0 authored by William Walker's avatar William Walker
Browse files

feat: Add gzip compression utility function

parent 4db1cf9f
No related tags found
No related merge requests found
/*
* Designed and developed in 2022-2024 by William Walker (wnwalker@ucsc.edu)
* Copyright 2022-2024 The Regents of the University of California. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package edu.ucsc.its.temerity
import org.koin.dsl.module
import java.io.ByteArrayOutputStream
import java.nio.charset.StandardCharsets.UTF_8
import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream
internal fun gzip(content: String): ByteArray {
val bos = ByteArrayOutputStream()
GZIPOutputStream(bos).bufferedWriter(UTF_8).use { it.write(content) }
return bos.toByteArray()
}
internal fun ungzip(content: ByteArray): String =
GZIPInputStream(content.inputStream()).bufferedReader(UTF_8).use { it.readText() }
internal fun jvmGzipCompressionModule() = module {
factory { (uncompressedContent: String) -> gzip(uncompressedContent) }
factory { (compressedContent: ByteArray) -> ungzip(compressedContent) }
}
......@@ -20,4 +20,9 @@ package edu.ucsc.its.temerity.extensions.log
import kotlinx.io.files.FileSystem
import kotlinx.io.files.SystemFileSystem
internal actual fun platformModule() = module {
factory { Java.create() }
includes(jvmGzipCompressionModule())
}
internal actual fun fileSystem(): FileSystem = SystemFileSystem
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment