View Source Briefly Usage Guide

Mix.install([
  {:briefly, "~> 0.5.0"}
])

Temporary Files

Use Briefly to create a temporary file:

{:ok, path} = Briefly.create()

Then you can write to the path and read the contents of the file:

File.write!(path, "My temp file contents")
File.read!(path)

When this process exits, the file at path is removed.

Temporary Directories

Briefly can also create a temporary directory:

{:ok, dir} = Briefly.create(type: :directory)

You can use File.stat/1 to check the type:

File.stat!(dir).type

Write to a file in the directory:

dir |> Path.join("test.txt") |> File.write!("Some Text")
dir |> Path.join("test.txt") |> File.read!()

When this process exits, the directory at dir and the files within are removed.

Cleanup

You can always cleanup any temporary paths already created:

Briefly.cleanup()