MCPcopy Create free account
hub / github.com/denoland/std / makeTempFileSync

Function makeTempFileSync

fs/unstable_make_temp_file.ts:111–156  ·  view source on GitHub ↗
(options?: MakeTempOptions)

Source from the content-addressed store, hash-verified

109 * @returns The file path to the temporary file.
110 */
111export function makeTempFileSync(options?: MakeTempOptions): string {
112 if (isDeno) {
113 return Deno.makeTempFileSync({ ...options });
114 } else {
115 const {
116 dir,
117 prefix,
118 suffix,
119 } = options ?? {};
120
121 try {
122 const { tmpdir } = getNodeOs();
123 const { join } = getNodePath();
124
125 let tempFilePath;
126 if (!options) {
127 tempFilePath = join(tmpdir(), randomId());
128 writeTextFileSync(tempFilePath, "", { mode: 0o600 });
129 return tempFilePath;
130 }
131
132 tempFilePath = tmpdir();
133 if (dir != null) {
134 tempFilePath = typeof dir === "string" ? dir : ".";
135 if (tempFilePath === "") {
136 tempFilePath = ".";
137 }
138 }
139
140 if (prefix != null && typeof prefix === "string") {
141 tempFilePath = join(tempFilePath, prefix + randomId());
142 } else {
143 tempFilePath = join(tempFilePath, randomId());
144 }
145
146 if (suffix != null && typeof suffix === "string") {
147 tempFilePath += suffix;
148 }
149
150 writeTextFileSync(tempFilePath, "", { mode: 0o600 });
151 return tempFilePath;
152 } catch (error) {
153 throw mapError(error);
154 }
155 }
156}

Calls 6

getNodeOsFunction · 0.90
getNodePathFunction · 0.90
randomIdFunction · 0.90
writeTextFileSyncFunction · 0.90
mapErrorFunction · 0.90
joinFunction · 0.50

Tested by

no test coverage detected