"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_primordials_error = require('../primordials/error.js');
const require_node_path = require('../node/path.js');
const require_archives_detect = require('./detect.js');
const require_archives_tar = require('./tar.js');
const require_archives_zip = require('./zip.js');

//#region src/archives/extract.ts
/**
* @file `extractArchive` — format-detecting dispatcher that routes to
*   `extractTar` / `extractTarGz` / `extractZip`.
*/
/**
* Extract an archive to a directory. Automatically detects format from file
* extension.
*
* @example
*   ;```typescript
*   await extractArchive('/tmp/package.tar.gz', '/tmp/output')
*   await extractArchive('/tmp/release.zip', '/tmp/output', { strip: 1 })
*   ```
*
* @param archivePath - Path to archive file.
* @param outputDir - Directory to extract to.
* @param options - Extraction options.
*
* @throws Error if archive format is not supported
*/
async function extractArchive(archivePath, outputDir, options = {}) {
	const format = require_archives_detect.detectArchiveFormat(archivePath);
	if (!format) {
		const ext = (/* @__PURE__ */ require_node_path.getNodePath()).extname(archivePath).toLowerCase();
		throw new require_primordials_error.ErrorCtor(`Unsupported archive format${ext ? ` (extension: ${ext})` : ""}: ${archivePath}. Supported formats: .zip, .tar, .tar.gz, .tgz`);
	}
	switch (format) {
		case "zip": return await require_archives_zip.extractZip(archivePath, outputDir, options);
		case "tar": return await require_archives_tar.extractTar(archivePath, outputDir, options);
		case "tar.gz":
		case "tgz": return await require_archives_tar.extractTarGz(archivePath, outputDir, options);
	}
}

//#endregion
exports.extractArchive = extractArchive;