Anyone have a project using Apple's Compression fr...
# multiplatform
s
Anyone have a project using Apple's Compression framework, or for that matter any Apple framework that isn't "platform.Foundation"? I'm specifically looking for how to add a dependency on an Apple framework so that an
import platform.Compression
statement can work, not a third-party cocoapod, so I can import it and use it in KMP code. I'm still searching around but so far not having much luck. Thanks in advance for any info...
m
Hi again 🙂 What a coincidence, I'm trying to figure out the exact same thing. I basically want to write lines to a gzip compressed file. The JVM/Android code looks like this:
Copy code
actual class CompressedLineWriter actual constructor(filePath: String) {
    private val writer = PrintWriter(GZIPOutputStream(File(filePath).outputStream()))

    actual fun writeLine(line: String) {
        writer.println(line)
    }

    actual fun close() {
        writer.close()
    }
}
I guess on iOS I could achieve the same thing with the Compression Framework [1]. But just like you I am unable to access it with Kotlin. One reason for this could be that it might be a Swift-only framework, but Kotlin only supports Objective-C frameworks. I might be able to implement my use case with
platform.zlib
, but that will involve a lot of pointer handling and manual memory management that I'm really not looking forward to. [1] https://developer.apple.com/documentation/accelerate/compressing_and_decompressing_files_with_swift_stream_compression
s
I'm looking at doc for Compression and it has an objective C API so the lib is somewhere in the Apple SDK. Rummaging in
.konan/kotlin-native-prebuilt-windows-x86_64-1.6.10\konan\platformDef\ios_arm64
there are a bunch of .def files but Compression isn't one of them. So now I'm looking in the Apple SDK to find if there is a libcompression file someplace - search hits have shown references to this but I haven't found it yet. If I can find that and the associated headers I can do my own cinterop setup. Also have a "wild hare" chase 🙂 in mind, considering porting pieces of jzlib project (java ZLib) to KMP, will see where that goes. Also in case its useful, if you haven't already check out https://github.com/korlibs/korio, they have a KMP port of compression too. Their Zip file support is insufficient for me, and their port of Compression uses a lot of other stuff in their library, and I haven't used it so don't know how good it is, but its there 🙂
m
Thanks @Skolson5903, I’ll have a look. Not sure if it helps but I have found some symbols from the compression framework in
platform.darwin
, for example
import platform.darwin.compression_stream_process
and a bunch of other symbols which are available since iOS 9.0. Everything available since iOS 13 (like
OutputFilter
) however is missing. Maybe those are Swift-specific blob shrug
s
Thanks for finding the darwin stuff, I didn't even know to look in there. I'm gonna try it out...