cups-printer
Version:
A package to print documents using CUPS Printer Server in Linux
25 lines • 698 B
JavaScript
import { access, writeFile } from 'fs/promises';
import { randomUUID } from 'crypto';
import { tmpdir } from 'os';
import { join } from 'path';
export async function tmpFile(data, prefix, ext) {
while (true) {
// Build path
let name = (prefix ?? '') + randomUUID();
if (typeof ext === 'string') {
name += '.';
name += ext.replace(/^\./gi, '');
}
const path = join(tmpdir(), name);
try {
// Check existence
await access(path);
}
catch {
// Write file
await writeFile(path, data);
return path;
}
}
}
//# sourceMappingURL=tmp-file.js.map