Initial commit
This commit is contained in:
1
ktor-client-brotli/.gitignore
vendored
Normal file
1
ktor-client-brotli/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
||||
12
ktor-client-brotli/build.gradle.kts
Normal file
12
ktor-client-brotli/build.gradle.kts
Normal file
@@ -0,0 +1,12 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
}
|
||||
|
||||
sourceSets.all {
|
||||
java.srcDir("src/$name/kotlin")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.ktor.client.encoding)
|
||||
implementation(libs.brotli)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package io.ktor.client.plugins.compression
|
||||
|
||||
import io.ktor.utils.io.*
|
||||
import io.ktor.utils.io.jvm.javaio.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import org.brotli.dec.BrotliInputStream
|
||||
|
||||
internal object BrotliEncoder : ContentEncoder {
|
||||
override val name: String = "br"
|
||||
|
||||
override fun CoroutineScope.encode(source: ByteReadChannel) =
|
||||
error("BrotliOutputStream not available (https://github.com/google/brotli/issues/715)")
|
||||
|
||||
override fun CoroutineScope.decode(source: ByteReadChannel): ByteReadChannel =
|
||||
BrotliInputStream(source.toInputStream()).toByteReadChannel()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package io.ktor.client.plugins.compression
|
||||
|
||||
fun ContentEncoding.Config.brotli(quality: Float? = null) {
|
||||
customEncoder(BrotliEncoder, quality)
|
||||
}
|
||||
Reference in New Issue
Block a user