I'm trying to download and decompress a gzip file ...
# multiplatform
g
I'm trying to download and decompress a gzip file via Ktor + Okio, but apparently that's only available for Android, so I can't import GzipSource (for example) in the shared KMM module. Is there any other way to do that without having to use expect/actual to provide separate Android and iOS implementations?
This is how I did on Android, but that requires
<http://java.io|java.io>.*
classes:
Copy code
private val client = HttpClient {
        install(HttpTimeout) {
            requestTimeoutMillis = 30_000
            connectTimeoutMillis = 30_000
            socketTimeoutMillis = 30_000
        }
    }

    @Suppress("BlockingMethodInNonBlockingContext")
    actual suspend fun downloadAndDecompressGzipFile(url: String, destination: Path) {
        val response = client.get(url)
        val inputStream = BufferedInputStream(InputSource(GZIPInputStream(response.bodyAsChannel().toInputStream())).byteStream)
        val outputStream = BufferedOutputStream(FileOutputStream(destination.toFile()))
        inputStream.copyTo(outputStream)
        outputStream.flush()
        outputStream.close()
        inputStream.close()
    }
j
KorIO supports gzip.
g
Thanks, that worked!
Copy code
suspend fun downloadAndDecompressGzipFile(url: String, destination: Path) {
        httpClient.readBytes(url)
            .uncompress(GZIPNoCrc)
            .writeToFile(getFullPathWithFileName(destination))
    }

    private fun getFullPathWithFileName(path: Path): String {
        return path.segments.joinToString("/")
    }
Now I'm trying to untar a file, but I couldn't find anything about this in KorIO 🤔
j
Sorry, I'm not aware of a multiplatform tar implementation.