Skip to content

Commit

Permalink
[skip ci] Encoding
Browse files Browse the repository at this point in the history
* Experiments with deflating with zlib
  • Loading branch information
petertrr committed Jan 13, 2022
1 parent 90c019b commit e9b9ff8
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {
alias(libs.plugins.versions.plugin)
alias(libs.plugins.talaiot.base)
alias(libs.plugins.liquibase.gradle)
id("com.louiscad.complete-kotlin") version "1.1.0"
}

val profile = properties.getOrDefault("save.profile", "dev") as String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,44 @@ package org.cqfn.save.agent.utils
import okio.FileNotFoundException
import okio.FileSystem
import okio.Path.Companion.toPath
import platform.zlib.*

import kotlinx.cinterop.UByteVar
import kotlinx.cinterop.allocArray
import kotlinx.cinterop.cValuesOf
import kotlinx.cinterop.cstr
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.pointed
import kotlinx.cinterop.ptr
import kotlinx.cinterop.readBytes
import kotlinx.cinterop.reinterpret
import kotlinx.cinterop.value

/**
* @param s
* @return
*/
fun deflate(s: String): ByteArray = memScoped {
// val defstream: z_stream = z_stream()
// defstream.zalloc = Z_NULL
// defstream.zfree = Z_NULL
// defstream.avail_in = s.length.toUInt() // size of input
// defstream.next_in = UByteVarOf<UByte>(s.cstr.ptr.rawValue).ptr
// defstream.avail_in = s.length.toUInt() // size of input
val out = allocArray<UByteVar>(s.length)
// defstream.next_out = UByteVarOf<UByte>(out.rawValue).ptr
// deflateInit(defstream.ptr, Z_BEST_COMPRESSION)
// platform.zlib.deflate(defstream.ptr, Z_FINISH)
// deflateEnd(defstream.ptr)
val destLen = cValuesOf(s.length).ptr
compress(
out,
destLen.reinterpret(),
s.cstr.ptr.reinterpret(),
s.length.toULong()
)
return@memScoped out.readBytes(destLen.pointed.value)
}

/**
* Read file as a list of strings
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.cqfn.save.utils

/**
* @param default
* @return
*/
fun String?.ifNullOrEmpty(default: () -> String) = (this ?: "").ifBlank(default)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.cqfn.save.orchestrator.filters

import org.springframework.web.server.ServerWebExchange
import org.springframework.web.server.WebFilter
import org.springframework.web.server.WebFilterChain
import reactor.core.publisher.Mono

class GzipDecodingFilter : WebFilter {
override fun filter(exchange: ServerWebExchange, chain: WebFilterChain): Mono<Void> {
TODO("Not yet implemented")
}
}

0 comments on commit e9b9ff8

Please sign in to comment.