"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../_virtual/_rolldown/runtime.js');
const require_primordials_error = require('../primordials/error.js');
const require_primordials_string = require('../primordials/string.js');
const require_primordials_object = require('../primordials/object.js');
let node_path = require("node:path");
node_path = require_runtime.__toESM(node_path);

//#region src/compression/_internal.ts
/**
* @file Private internals for `compression/*` modules — `resolveFileArgs`
*   disambiguates the `(src, dest, options?)` vs `(src, options)` calling
*   shape, and `stripExt` removes a trailing extension when it matches one of a
*   caller-supplied set. Both are shared by the brotli and gzip leaves and have
*   no callers outside this directory.
*/
/**
* Strip the trailing extension from a filename when it matches one of `exts`.
* Returns the input unchanged when the trailing extname isn't in the set.
* Case-insensitive on the extension — preserves the rest of the path's casing.
*
* The `exts` set decides what counts. Pass `BROTLI_EXTS` / `GZIP_EXTS` for the
* canonical compression sets, or your own set for custom classifiers.
*
* Generic — it does NOT know that `.tgz` is short for `.tar.gz`. Callers that
* need that convention compose this with their own follow-up (see
* `decompressGzipFile` for the canonical example).
*/
function stripExt(filePath, exts) {
	const ext = node_path.default.extname(filePath);
	if (!exts.has(require_primordials_string.StringPrototypeToLowerCase(ext))) return filePath;
	return filePath.slice(0, -ext.length);
}
/**
* Disambiguate the `(src, dest, options?)` and `(src, options)` call shapes.
* Returns the resolved destPath, options, and inPlace flag. Validates that the
* explicit destPath is not the same as srcPath, since same-path streams would
* deadlock on read.
*/
function resolveFileArgs(fnName, srcPath, destOrOptions, maybeOptions, computeInPlaceDest) {
	if (typeof destOrOptions === "string") {
		if (srcPath === destOrOptions) throw new require_primordials_error.ErrorCtor(`${fnName}: srcPath and destPath must differ; got ${srcPath}`);
		return require_primordials_object.ObjectFreeze({
			__proto__: null,
			destPath: destOrOptions,
			options: maybeOptions,
			inPlace: false
		});
	}
	if (destOrOptions?.inPlace) return require_primordials_object.ObjectFreeze({
		__proto__: null,
		destPath: computeInPlaceDest(srcPath),
		options: destOrOptions,
		inPlace: true
	});
	throw new require_primordials_error.ErrorCtor(`${fnName}: missing destPath; pass an explicit destination or { inPlace: true }`);
}

//#endregion
exports.resolveFileArgs = resolveFileArgs;
exports.stripExt = stripExt;