本文整理汇总了TypeScript中temp-file.TmpDir.getTempFile方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TmpDir.getTempFile方法的具体用法?TypeScript TmpDir.getTempFile怎么用?TypeScript TmpDir.getTempFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类temp-file.TmpDir
的用法示例。
在下文中一共展示了TmpDir.getTempFile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: transformBackgroundFileIfNeed
export async function transformBackgroundFileIfNeed(file: string, tmpDir: TmpDir): Promise<string> {
if (file.endsWith(".tiff") || file.endsWith(".TIFF")) {
return file
}
const retinaFile = file.replace(/\.([a-z]+)$/, "@2x.$1")
if (await exists(retinaFile)) {
const tiffFile = await tmpDir.getTempFile({suffix: ".tiff"})
await exec("tiffutil", ["-cathidpicheck", file, retinaFile, "-out", tiffFile])
return tiffFile
}
return file
}
示例2: downloadCertificate
export async function downloadCertificate(urlOrBase64: string, tmpDir: TmpDir, currentDir: string): Promise<string> {
urlOrBase64 = urlOrBase64.trim()
let file: string | null = null
if ((urlOrBase64.length > 3 && urlOrBase64[1] === ":") || urlOrBase64.startsWith("/") || urlOrBase64.startsWith(".")) {
file = urlOrBase64
}
else if (urlOrBase64.startsWith("file://")) {
file = urlOrBase64.substring("file://".length)
}
else if (urlOrBase64.startsWith("~/")) {
file = path.join(homedir(), urlOrBase64.substring("~/".length))
}
else {
const isUrl = urlOrBase64.startsWith("https://")
if (isUrl || urlOrBase64.length > 2048 || urlOrBase64.endsWith("=")) {
const tempFile = await tmpDir.getTempFile({suffix: ".p12"})
if (isUrl) {
await download(urlOrBase64, tempFile)
}
else {
await outputFile(tempFile, Buffer.from(urlOrBase64, "base64"))
}
return tempFile
}
else {
file = urlOrBase64
}
}
file = path.resolve(currentDir, file)
const stat = await statOrNull(file)
if (stat == null) {
throw new InvalidConfigurationError(`${file} doesn't exist`)
}
else if (!stat.isFile()) {
throw new InvalidConfigurationError(`${file} not a file`)
}
else {
return file
}
}
示例3: tar
export async function tar(compression: CompressionLevel | any | any, format: string, outFile: string, dirToArchive: string, isMacApp: boolean, tempDirManager: TmpDir): Promise<void> {
const tarFile = await tempDirManager.getTempFile({suffix: ".tar"})
const tarArgs = debug7zArgs("a")
tarArgs.push(tarFile)
tarArgs.push(path.basename(dirToArchive))
await Promise.all([
exec(path7za, tarArgs, {cwd: path.dirname(dirToArchive)}),
// remove file before - 7z doesn't overwrite file, but update
unlinkIfExists(outFile),
])
if (!isMacApp) {
await exec(path7za, ["rn", tarFile, path.basename(dirToArchive), path.basename(outFile, `.${format}`)])
}
if (format === "tar.lz") {
// noinspection SpellCheckingInspection
let lzipPath = "lzip"
if (process.platform === "darwin") {
lzipPath = path.join(await getLinuxToolsPath(), "bin", lzipPath)
}
await exec(lzipPath, [compression === "store" ? "-1" : "-9", "--keep" /* keep (don't delete) input files */, tarFile])
// bloody lzip creates file in the same dir where input file with postfix `.lz`, option --output doesn't work
await move(`${tarFile}.lz`, outFile)
return
}
const args = compute7zCompressArgs(format === "tar.xz" ? "xz" : (format === "tar.bz2" ? "bzip2" : "gzip"), {
isRegularFile: true,
method: "DEFAULT",
compression,
})
args.push(outFile, tarFile)
await exec(path7za, args, {
cwd: path.dirname(dirToArchive),
}, debug7z.enabled)
}
示例4: async
test.ifAll.ifDevOrLinuxCi("download to nonexistent dir", async () => {
const tempFile = await tmpDir.getTempFile()
await httpExecutor.download("https://drive.google.com/uc?export=download&id=0Bz3JwZ-jqfRONTkzTGlsMkM2TlE", tempFile)
await assertThat(tempFile).isFile()
})