const require_rolldown_runtime = require("./rolldown-runtime-D_mwlA32.cjs");
let fs_promises = require("fs/promises");
fs_promises = require_rolldown_runtime.__toESM(fs_promises, 1);
let path = require("path");
path = require_rolldown_runtime.__toESM(path, 1);
let os = require("os");
os = require_rolldown_runtime.__toESM(os, 1);
//#region src/util/secureTempFiles.ts
const SECURE_FILE_OPTIONS = {
	encoding: "utf8",
	flag: "wx",
	mode: 384
};
function isSimpleLeafName(value) {
	return value.length > 0 && value !== "." && value !== ".." && path.default.basename(value) === value;
}
async function createSecureTempDirectory(prefix) {
	if (!isSimpleLeafName(prefix)) throw new Error("Secure temporary directory prefixes must be simple leaf names");
	const directory = await fs_promises.default.mkdtemp(path.default.join(os.default.tmpdir(), prefix));
	if (process.platform !== "win32") await fs_promises.default.chmod(directory, 448);
	return directory;
}
async function writeSecureTempFile(directory, filename, contents) {
	if (!isSimpleLeafName(filename)) throw new Error("Secure temporary file names must be simple leaf names");
	const filePath = path.default.join(directory, filename);
	await fs_promises.default.writeFile(filePath, contents, SECURE_FILE_OPTIONS);
	return filePath;
}
async function removeSecureTempDirectory(directory) {
	await fs_promises.default.rm(directory, {
		force: true,
		recursive: true
	});
}
//#endregion
Object.defineProperty(exports, "createSecureTempDirectory", {
	enumerable: true,
	get: function() {
		return createSecureTempDirectory;
	}
});
Object.defineProperty(exports, "removeSecureTempDirectory", {
	enumerable: true,
	get: function() {
		return removeSecureTempDirectory;
	}
});
Object.defineProperty(exports, "writeSecureTempFile", {
	enumerable: true,
	get: function() {
		return writeSecureTempFile;
	}
});

//# sourceMappingURL=secureTempFiles-CgQrWvRe.cjs.map