src/Pure/General/zstd.scala
author wenzelm
Fri, 21 Oct 2022 13:15:24 +0200
changeset 76349 b4daf7577ca0
parent 76348 a15f16e8ad18
child 76353 3698d0f3da18
permissions -rw-r--r--
clarified Zstd.init(): avoid accidential com.github.luben.zstd.util.Native.load() operation;

/*  Title:      Pure/General/xz.scala
    Author:     Makarius

Support for Zstd data compression.
*/

package isabelle


object Zstd {
  def init(): Unit = init_jni

  private lazy val init_jni: Unit = {
    require(!com.github.luben.zstd.util.Native.isLoaded(),
      "Zstd library already initialized by other means than isabelle.Zstd.init()")

    val lib_dir = Path.explode("$ISABELLE_ZSTD_HOME/" + Platform.jvm_platform)
    val lib_file =
      File.find_files(lib_dir.file) match {
        case List(file) => file
        case _ => error("Exactly one file expected in directory " + lib_dir.expand)
      }
    System.load(File.platform_path(lib_file.getAbsolutePath))

    com.github.luben.zstd.util.Native.assumeLoaded()
    assert(com.github.luben.zstd.util.Native.isLoaded())
    Class.forName("com.github.luben.zstd.Zstd")
  }
}