"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_primordials_error = require('../primordials/error.js');
const require_primordials_string = require('../primordials/string.js');
const require_node_path = require('../node/path.js');
let node_fs = require("node:fs");

//#region src/archives/_internal.ts
/**
* @file Private internals for `archives/*` modules — defaults, lazy module
*   accessors (adm-zip, tar-fs, node:path), shared pre-extraction validators
*   (`assertArchiveExists`, `validatePathWithinBase`).
*/
const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024;
const DEFAULT_MAX_TOTAL_SIZE = 1024 * 1024 * 1024;
const DEFAULT_MAX_ENTRIES = 1e5;
let _AdmZip;
let _tarFs;
/**
* Assert that an archive file exists on disk before handing it to the
* underlying extractor. Normalizes the "missing archive" surface across all
* three extractors (zip/tar/tar.gz): each now throws a Node-style `ENOENT`
* error with the archive path. Without this preflight, `zip` goes through
* adm-zip and surfaces as `"Invalid filename"`, while `tar`/`tar.gz` surface
* the raw Node `ENOENT` — inconsistent, and adm-zip's message didn't include
* the path.
*
* @private
*
* @throws Error with `code: 'ENOENT'` if archivePath doesn't exist.
*/
function assertArchiveExists(archivePath) {
	if (!(0, node_fs.existsSync)(archivePath)) {
		const err = new require_primordials_error.ErrorCtor(`ENOENT: no such file or directory, open '${archivePath}'`);
		err.code = "ENOENT";
		err.path = archivePath;
		throw err;
	}
}
/*@__NO_SIDE_EFFECTS__*/
function getAdmZip() {
	if (_AdmZip === void 0) _AdmZip = /*@__PURE__*/ require("../external/adm-zip.js");
	return _AdmZip;
}
/*@__NO_SIDE_EFFECTS__*/
function getTarFs() {
	if (_tarFs === void 0) _tarFs = /*@__PURE__*/ require("../external/tar-fs.js");
	return _tarFs;
}
/**
* Validate that a resolved path is within the target directory. Prevents path
* traversal attacks.
*
* @private
*
* @param targetPath - The resolved path to validate.
* @param baseDir - The base directory that should contain the path.
* @param entryName - Original entry name for error reporting.
*
* @throws Error if path is outside the base directory
*/
function validatePathWithinBase(targetPath, baseDir, entryName) {
	const path = /* @__PURE__ */ require_node_path.getNodePath();
	const resolvedTarget = path.resolve(targetPath);
	const resolvedBase = path.resolve(baseDir);
	if (!require_primordials_string.StringPrototypeStartsWith(resolvedTarget, resolvedBase + path.sep) && resolvedTarget !== resolvedBase) throw new require_primordials_error.ErrorCtor(`Path traversal attempt detected: entry "${entryName}" would extract to "${resolvedTarget}" outside target directory "${resolvedBase}"`);
}

//#endregion
exports.DEFAULT_MAX_ENTRIES = DEFAULT_MAX_ENTRIES;
exports.DEFAULT_MAX_FILE_SIZE = DEFAULT_MAX_FILE_SIZE;
exports.DEFAULT_MAX_TOTAL_SIZE = DEFAULT_MAX_TOTAL_SIZE;
exports.assertArchiveExists = assertArchiveExists;
exports.getAdmZip = getAdmZip;
exports.getPath = require_node_path.getNodePath;
exports.getTarFs = getTarFs;
exports.validatePathWithinBase = validatePathWithinBase;