Skip to content

Commit a546232

Browse files
committed
[skip ci] Encoding
* Experiments with deflating with zlib
1 parent 90c019b commit a546232

File tree

3 files changed

+57
-0
lines changed
  • save-agent/src/linuxX64Main/kotlin/org/cqfn/save/agent/utils
  • save-cloud-common/src/commonMain/kotlin/org/cqfn/save/utils
  • save-orchestrator/src/main/kotlin/org/cqfn/save/orchestrator/filters

3 files changed

+57
-0
lines changed

save-agent/src/linuxX64Main/kotlin/org/cqfn/save/agent/utils/FileUtils.kt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,44 @@ package org.cqfn.save.agent.utils
77
import okio.FileNotFoundException
88
import okio.FileSystem
99
import okio.Path.Companion.toPath
10+
import platform.zlib.*
11+
12+
import kotlinx.cinterop.UByteVar
13+
import kotlinx.cinterop.allocArray
14+
import kotlinx.cinterop.cValuesOf
15+
import kotlinx.cinterop.cstr
16+
import kotlinx.cinterop.memScoped
17+
import kotlinx.cinterop.pointed
18+
import kotlinx.cinterop.ptr
19+
import kotlinx.cinterop.readBytes
20+
import kotlinx.cinterop.reinterpret
21+
import kotlinx.cinterop.value
22+
23+
/**
24+
* @param s
25+
* @return
26+
*/
27+
fun deflate(s: String): ByteArray = memScoped {
28+
// val defstream: z_stream = z_stream()
29+
// defstream.zalloc = Z_NULL
30+
// defstream.zfree = Z_NULL
31+
// defstream.avail_in = s.length.toUInt() // size of input
32+
// defstream.next_in = UByteVarOf<UByte>(s.cstr.ptr.rawValue).ptr
33+
// defstream.avail_in = s.length.toUInt() // size of input
34+
val out = allocArray<UByteVar>(s.length)
35+
// defstream.next_out = UByteVarOf<UByte>(out.rawValue).ptr
36+
// deflateInit(defstream.ptr, Z_BEST_COMPRESSION)
37+
// platform.zlib.deflate(defstream.ptr, Z_FINISH)
38+
// deflateEnd(defstream.ptr)
39+
val destLen = cValuesOf(s.length).ptr
40+
compress(
41+
out,
42+
destLen.reinterpret(),
43+
s.cstr.ptr.reinterpret(),
44+
s.length.toULong()
45+
)
46+
return@memScoped out.readBytes(destLen.pointed.value)
47+
}
1048

1149
/**
1250
* Read file as a list of strings
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.cqfn.save.utils
2+
3+
/**
4+
* @param default
5+
* @return
6+
*/
7+
fun String?.ifNullOrEmpty(default: () -> String) = (this ?: "").ifBlank(default)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.cqfn.save.orchestrator.filters
2+
3+
import org.springframework.web.server.ServerWebExchange
4+
import org.springframework.web.server.WebFilter
5+
import org.springframework.web.server.WebFilterChain
6+
import reactor.core.publisher.Mono
7+
8+
class GzipDecodingFilter : WebFilter {
9+
override fun filter(exchange: ServerWebExchange, chain: WebFilterChain): Mono<Void> {
10+
TODO("Not yet implemented")
11+
}
12+
}

0 commit comments

Comments
 (0)