Packages

fnord

0.9.32

AI code archaeology

Current section

Files

Jump to
fnord lib util temp.ex
Raw

lib/util/temp.ex

defmodule Util.Temp do
@spec with_tmp(binary, (binary -> any)) :: any
def with_tmp(contents, fun) do
case Briefly.create() do
{:ok, path} ->
try do
case File.write(path, contents) do
:ok ->
fun.(path)
{:error, reason} ->
{:error, reason}
end
after
# Best-effort cleanup
_ = File.rm(path)
end
{:error, reason} ->
{:error, reason}
end
end
end