Skip to content

Add API to extract archive File objects into directories #13353

Closed

Description

@dagger-codex

What are you trying to do?

Add a first-class Dagger API for extracting archive File objects into Directory values.

Today, when a Dagger pipeline downloads or produces an archive, users commonly need to create a throwaway container, mount the archive, install/use an extraction tool, and run something like bsdtar to unpack it before continuing with normal Directory operations.

A core API would let users write this as a normal Dagger data-flow operation instead of shelling out through a container.

Possible API shape, naming TBD:

archive := dag.HTTP("https://example.com/source.tar.gz")
src := archive.Extract()

or:

src := archive.AsDirectory(dagger.FileAsDirectoryOpts{
    Format: "tar.gz", // optional; auto-detect when omitted
    StripComponents: 1,
})

The key behavior requested here is File -> Directory archive extraction. It should probably support the common formats users already reach for bsdtar to handle, such as .tar, .tar.gz, .tgz, .tar.xz, and .zip, subject to whatever set is appropriate for the engine API.

Why is this important?

Archive extraction is a common CI/CD pipeline step. Without a core API, users repeat boilerplate like:

  1. Start an Alpine/debian/etc. container.
  2. Install or rely on tar/bsdtar/unzip.
  3. Mount the archive file and an output directory.
  4. Run an extraction command.
  5. Continue with the extracted Directory.

That workaround is noisy, image-dependent, and less portable than a Dagger-native filesystem operation. It also makes module APIs less clear because a data transformation that conceptually returns a Directory is expressed as container execution plumbing.

Prior context

Current workaround

Use a container with an extraction tool, for example bsdtar, mount the archive File, extract to a mounted directory, then return/read that directory.

Open questions

  • Should this live on File, for example File.Extract() or File.AsDirectory()?
  • Should format be auto-detected from content, filename, or explicitly passed?
  • Which formats should be guaranteed by core?
  • Should options include stripComponents, include/exclude filters, overwrite behavior, and path traversal protections?

Activity

  1. sagikazarmark commented on Jun 7, 2026

    @sagikazarmark
    Contributor
    • I like Extract as the API. AsDirectory is ambigous and non-obvious
    • stripComponents is important, include/exclude can be handled by the normal Directory API
    • Format: yes, it should be auto-detected, at least in the first version
    • Supported formats (at least the following): .tar, .tgz|.tar.gz, .tar.xz, .zip (anything else?)
  2. dagger-codex commented on Jun 7, 2026

    @dagger-codex
    ContributorAuthor

    Sanity check before implementation:

    The updated direction looks implementable as a File.extract(...) -> Directory API. My read of the intended v1 contract is:

    • Method name: File.extract, not asDirectory.
    • Return type: Directory.
    • Options: start with stripComponents.
    • Format: auto-detected in v1; no include/exclude options because users can use normal Directory APIs afterward.
    • Initial formats: .tar, .tgz / .tar.gz, .tar.xz, and .zip.

    Questions to settle before coding:

    1. Should v1 expose any format option at all, or should it be auto-detect only until there is a concrete need for override?
    2. Should stripComponents apply uniformly to both tar and zip entry paths, with entries that do not have enough path components skipped like tar --strip-components?
    3. For unsafe archive paths, should extraction fail closed? I would default to rejecting absolute paths and paths that escape the output root via .. after normalization.
    4. Should v1 preserve symlinks, file modes, and executable bits where the archive format provides them? I would preserve them for tar and preserve zip mode bits where available.
    5. Is .tar.xz required in the first PR? It is in the suggested format list, but it likely means adding/using an xz decoder dependency, unlike plain tar/gzip/zip.

    If those defaults are right, I can proceed with an implementation around that contract.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions