method

bun.Archive.extract

path: string,
): Promise<number>;

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 are overwritten.

On Linux and macOS, nothing is written through a symlink in the target directory that is absolute or leads out of it. The promise rejects when a file entry needs such a symlink, unless options.glob is set, which skips the entry. The code of the error is "EXDEV", and its path is the path of the entry relative to the target directory.

@param path

The directory path to extract to

@param options

Optional extraction options

@returns

A promise that resolves with the number of entries extracted (files, directories, and symlinks)

Extract all entries:

const archive = new Bun.Archive(tarballBytes);
const count = await archive.extract("./extracted");
console.log(`Extracted ${count} entries`);