"use strict";
/* Socket Lib - Built with esbuild */
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var internal_exports = {};
__export(internal_exports, {
  DEFAULT_MAX_ENTRIES: () => DEFAULT_MAX_ENTRIES,
  DEFAULT_MAX_FILE_SIZE: () => DEFAULT_MAX_FILE_SIZE,
  DEFAULT_MAX_TOTAL_SIZE: () => DEFAULT_MAX_TOTAL_SIZE,
  assertArchiveExists: () => assertArchiveExists,
  getAdmZip: () => getAdmZip,
  getPath: () => import_path2.getNodePath,
  getTarFs: () => getTarFs,
  validatePathWithinBase: () => validatePathWithinBase
});
module.exports = __toCommonJS(internal_exports);
var import_node_fs = require("node:fs");
var import_error = require("../primordials/error");
var import_string = require("../primordials/string");
var import_path = require("../node/path");
var import_path2 = require("../node/path");
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;
function assertArchiveExists(archivePath) {
  if (!(0, import_node_fs.existsSync)(archivePath)) {
    const err = new import_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 = require("../external/adm-zip.js");
  }
  return _AdmZip;
}
// @__NO_SIDE_EFFECTS__
function getTarFs() {
  if (_tarFs === void 0) {
    _tarFs = require("../external/tar-fs.js");
  }
  return _tarFs;
}
function validatePathWithinBase(targetPath, baseDir, entryName) {
  const path = (0, import_path.getNodePath)();
  const resolvedTarget = path.resolve(targetPath);
  const resolvedBase = path.resolve(baseDir);
  if (!(0, import_string.StringPrototypeStartsWith)(resolvedTarget, resolvedBase + path.sep) && resolvedTarget !== resolvedBase) {
    throw new import_error.ErrorCtor(
      `Path traversal attempt detected: entry "${entryName}" would extract to "${resolvedTarget}" outside target directory "${resolvedBase}"`
    );
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  DEFAULT_MAX_ENTRIES,
  DEFAULT_MAX_FILE_SIZE,
  DEFAULT_MAX_TOTAL_SIZE,
  assertArchiveExists,
  getAdmZip,
  getPath,
  getTarFs,
  validatePathWithinBase
});
