05nelsonm / kmp-tor-binary

Apache License 2.0
5 stars 2 forks source link

Create `binary-core-api` module #135

Closed 05nelsonm closed 9 months ago

05nelsonm commented 9 months ago

Need to expose some things w/o exposing binary-core's API such as File system exceptions.

05nelsonm commented 9 months ago

Adding the blocked label until #137 is completed which will add the exceptions needed to binary-core

05nelsonm commented 9 months ago

This should also contain an Installer interface and the aliases for tor, geoip and geoip6 so that kmp-tor only needs to depend on binary-api and binary-core. Library consumer can then update binary w/o the need to update kmp-tor as well as using their own tor resources if they wish.

public abstract class Installer<P: Paths>(public val installationDir: String) {

    @Throws(IOException::class)
    public abstract fun install(): P

    public abstract class Paths private constructor() {

        public class Tor(
            @JvmField
            public val tor: String,
            @JvmField
            public val geoip: String,
            @JvmField
            public val geoip6: String,
        ): Paths()
    }
}

For kmp-tor can then do something like

public class KmpTorDirs(
    @JvmField
    public val workDir: File,
    @JvmField
    public val cacheDir: File,
    private val installerProvider: (installationDirPath: String) -> Installer<Installer.Paths.Tor>
) {

    @JvmField
    public val installationDir: File = workDir.resolve(".kmptor")

    @get:JvmName("installer")
    public val installer: Installer<Installer.Paths.Tor> by lazy {
        installerProvider(installationDir.path)
    }
}