diff --git a/lib/kino.ex b/lib/kino.ex index 4be46246..a3e244d6 100644 --- a/lib/kino.ex +++ b/lib/kino.ex @@ -516,4 +516,16 @@ defmodule Kino do def interrupt!(variant, message) when variant in [:normal, :error] and is_binary(message) do raise Kino.InterruptError, variant: variant, message: message end + + @doc """ + Returns a temporary directory that gets removed when the runtime + terminates. + """ + @spec tmp_dir() :: String.t() | nil + def tmp_dir() do + case Kino.Bridge.get_tmp_dir() do + {:ok, path} -> path + {:error, _} -> nil + end + end end diff --git a/lib/kino/bridge.ex b/lib/kino/bridge.ex index ced289d2..2f3f478b 100644 --- a/lib/kino/bridge.ex +++ b/lib/kino/bridge.ex @@ -202,6 +202,14 @@ defmodule Kino.Bridge do with {:ok, reply} <- io_request(:livebook_get_app_info), do: reply end + @doc """ + Returns a temporary directory tied to the current runtime. + """ + @spec get_tmp_dir() :: {:ok, String.t()} | {:error, request_error() | :not_available} + def get_tmp_dir() do + with {:ok, reply} <- io_request(:livebook_get_tmp_dir), do: reply + end + @doc """ Checks if the caller is running within Livebook context (group leader). """