#!/usr/bin/env node
import path from "path";
import os from "os";
import fsPromises from "fs/promises";
//#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.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 fsPromises.mkdtemp(path.join(os.tmpdir(), prefix));
	if (process.platform !== "win32") await fsPromises.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.join(directory, filename);
	await fsPromises.writeFile(filePath, contents, SECURE_FILE_OPTIONS);
	return filePath;
}
async function removeSecureTempDirectory(directory) {
	await fsPromises.rm(directory, {
		force: true,
		recursive: true
	});
}
//#endregion
export { removeSecureTempDirectory as n, writeSecureTempFile as r, createSecureTempDirectory as t };

//# sourceMappingURL=secureTempFiles-Gyzt-GYv.js.map