@@ -7,6 +7,44 @@ package org.cqfn.save.agent.utils
77import okio.FileNotFoundException
88import okio.FileSystem
99import 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
0 commit comments