star

Package VersionHex Docs

Gleam bindings for Erlang's erl_tar to create, extract, and list tar archives with optional gzip compression.

gleam add star

Creating an archive

Use the builder to stage entries, then write to a file:

import star

pub fn main() {
  let assert Ok(Nil) =
    star.new()
    |> star.add_file(at: "hello.txt", containing: <<"hi":utf8>>)
    |> star.add_disk_path(from: "README.md")
    |> star.add_disk_mapped(at: "bin/tool", from: "build/tool")
    |> star.build_file(at: "release.tar.gz", compression: star.Gzip)
}

Extracting an archive

star.extract(
  from: star.FromFile("release.tar.gz"),
  to: "/tmp/release",
  compression: star.Gzip,
  filter: star.AllEntries,
  on_conflict: star.Overwrite,
)

Extract into memory instead:

let assert Ok(entries) =
  star.extract_memory(
    from: star.FromFile("release.tar.gz"),
    compression: star.Gzip,
    filter: star.Only(["README.md", "bin/tool"]),
  )

Listing an archive

let assert Ok(headers) =
  star.list(
    from: star.FromFile("release.tar.gz"),
    compression: star.Gzip,
    filter: star.AllEntries,
  )