Extract the archive contents to a directory on disk.
Creates the target directory and any necessary parent directories if they don't exist. Existing files will be overwritten.
method
Extract the archive contents to a directory on disk.
Creates the target directory and any necessary parent directories if they don't exist. Existing files will be overwritten.
The directory path to extract to
Optional extraction options
A promise that resolves with the number of entries extracted (files, directories, and symlinks)
Extract all entries:
const archive = Bun.Archive.from(tarballBytes);
const count = await archive.extract("./extracted");
console.log(`Extracted ${count} entries`);
Options for extracting archive contents.
Glob pattern(s) to filter which entries are extracted. Uses the same syntax as Bun.Glob, including support for wildcards (*, **), character classes ([abc]), alternation ({a,b}), and negation (!pattern).
Patterns are matched against archive entry paths normalized to use forward slashes (/), regardless of the host operating system. Always write patterns using / as the separator.
!): Entries matching these patterns will be excluded. Negative patterns are applied after positive patterns.If not specified, all entries are extracted.
// Extract only TypeScript files
await archive.extract("./out", { glob: "**" + "/*.ts" });
// Extract files from multiple directories
await archive.extract("./out", { glob: ["src/**", "lib/**"] });
// Exclude node_modules using negative pattern
await archive.extract("./out", { glob: ["**", "!node_modules/**"] });
// Extract source files but exclude tests
await archive.extract("./out", { glob: ["src/**", "!**" + "/*.test.ts"] });