Skip to content

Archive Module

Functions for creating and extracting archive files.

Extracts contents from an archive file.

archive.extract(
archive = ctx.path("deps/library.tar.gz"),
type = "AUTO",
destination_folder = ctx.path("vendor/library"),
paths = glob(["src/**"]),
)
ParameterTypeDescription
archivepathPath to the archive file
typestringArchive type: AUTO, JAR, ZIP, TAR, TAR_GZ, TAR_XZ, TAR_BZ2
destination_folderpathWhere to extract (defaults to archive’s directory)
pathsglobOptional filter for which files to extract
ExtensionType
.zipZIP
.jarJAR
.tarTAR
.tgz, .tar.gzTAR_GZ
.tar.xzTAR_XZ
.tar.bz2TAR_BZ2

Creates an archive from files in the working directory.

archive.create(
archive = ctx.path("output/release.tar.gz"),
files = glob(["dist/**", "README.md"]),
)
ParameterTypeDescription
archivepathOutput path for the archive
filesglobFiles to include (defaults to all files)

The archive type is inferred from the file extension.

Extract a third-party library during transformation:

def _extract_deps(ctx):
archive.extract(
archive = ctx.path("third_party/protobuf.tar.gz"),
destination_folder = ctx.path("third_party/protobuf"),
)
# Remove the archive after extraction
ctx.remove(glob(["third_party/*.tar.gz"]))

Create a distributable archive:

def _create_release(ctx):
archive.create(
archive = ctx.path("release.zip"),
files = glob([
"bin/**",
"lib/**",
"LICENSE",
"README.md",
]),
)

Extract only specific files from a large archive:

archive.extract(
archive = ctx.path("sdk.zip"),
paths = glob(["headers/**/*.h", "lib/*.a"]),
destination_folder = ctx.path("vendor/sdk"),
)
  • The AUTO type detection relies on file extensions
  • Original file paths are preserved when creating archives
  • Extraction creates directories as needed