本文整理汇总了TypeScript中tmp.file函数的典型用法代码示例。如果您正苦于以下问题:TypeScript file函数的具体用法?TypeScript file怎么用?TypeScript file使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了file函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
tmp.file({prefix: 'nez', postfix: '.p4d'}, function(p4d_err,p4d_tempfile,fd) {
if(p4d_err) {
console.log(p4d_err);
return;
}
tmp.file({prefix: 'nez'}, function(src_err,src_tempfile,fd) {
if(src_err) {
console.log(src_err);
return;
}
var dest_file = src_tempfile + '_rev.txt'
var exec_command = nez_command + ' -p ' + p4d_tempfile + ' -t json -i ' + src_tempfile + ' > ' + dest_file;
console.log(exec_command);
createFileAndExec(src_tempfile, req.body.source, p4d_tempfile, req.body.p4d, exec_command, function(stdout) {
var data = fs.readFileSync(dest_file);
if(data.length > 0) {
var sendData:any = /(^{$|\n{\n)[\S\s]*/m.exec(data.toString());
if(sendData){
var j = { source: sendData[0], runnable: true };
} else {
var j = { source: data.toString(), runnable: false };
}
genResponse(res, j);
} else {
var msg = "エラー訂正候補を出せませんでした";
var error_j = { source: msg, runnable: false };
genResponse(res, error_j);
}
});
});
});
示例2: reject
.then(inStream => {
tmp.file((err, tmpPath, fd, cleanupCallback) => {
if (err) {
return reject(err);
}
log(`[INFO] Downloading to ${tmpPath}...`);
const outStream = fs.createWriteStream(null, { fd: fd });
outStream.once('error', err => reject(err));
inStream.once('error', err => reject(err));
outStream.once('finish', () => {
// At this point, the asset has finished downloading.
log(`[INFO] Download complete!`);
log(`[INFO] Decompressing...`);
return decompress(tmpPath, installDirectory)
.then(files => {
log(`[INFO] Done! ${files.length} files unpacked.`);
return resolve(true);
})
.catch(err => {
log(`[ERROR] ${err}`);
return reject(err);
});
});
inStream.pipe(outStream);
});
})
示例3: _tempFileCreated
return new Promise<string>((resolve, reject) => {
tmp.file({ prefix: 'vscode-restclient-', postfix: ".http" }, function _tempFileCreated(err, tmpFilePath, fd) {
if (err) {
reject(err);
return;
}
let output = `${request.method.toUpperCase()} ${request.url}${EOL}`;
if (request.headers) {
for (let header in request.headers) {
if (request.headers.hasOwnProperty(header)) {
let value = request.headers[header];
output += `${header}: ${value}${EOL}`;
}
}
}
if (request.body) {
output += `${EOL}${request.body}`;
}
fs.writeFile(tmpFilePath, output, error => {
reject(error);
return;
});
resolve(tmpFilePath);
});
});
示例4: async
return new Promise<void>((resolve, reject) => {
tmp.file({postfix: '.vsix'}, async (err, vsixPath, fd, cleanupCallback) => {
if (err) {
reject(new Error('Failed to create vsix file'));
return;
}
// Place in try/catch as the .catch call catches a rejection in downloadFileToDestination
// then the .catch call will return a resolved promise
// Thusly, the .catch call must also throw, as a return would simply return an unused promise
// instead of returning early from this function scope
let config: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration();
let originalProxySupport: string = config.inspect<string>('http.proxySupport').globalValue;
while (true) { // Might need to try again with a different http.proxySupport setting.
try {
await util.downloadFileToDestination(buildInfo.downloadUrl, vsixPath);
} catch {
// Try again with the proxySupport to "off".
if (originalProxySupport !== config.inspect<string>('http.proxySupport').globalValue) {
config.update('http.proxySupport', originalProxySupport, true); // Reset the http.proxySupport.
reject(new Error('Failed to download VSIX package with proxySupport off')); // Changing the proxySupport didn't help.
return;
}
if (config.get('http.proxySupport') !== "off" && originalProxySupport !== "off") {
config.update('http.proxySupport', "off", true);
continue;
}
reject(new Error('Failed to download VSIX package'));
return;
}
if (originalProxySupport !== config.inspect<string>('http.proxySupport').globalValue) {
config.update('http.proxySupport', originalProxySupport, true); // Reset the http.proxySupport.
telemetry.logLanguageServerEvent('installVsix', { 'error': "Success with proxySupport off", 'success': 'true' });
}
break;
}
try {
await installVsix(vsixPath);
} catch (error) {
reject(error);
return;
}
clearInterval(insiderUpdateTimer);
const message: string =
`The C/C++ Extension has been updated to version ${buildInfo.name}. Please reload the window for the changes to take effect.`;
util.promptReloadWindow(message);
telemetry.logLanguageServerEvent('installVsix', { 'success': 'true' });
resolve();
});
}).catch(error => {
示例5: reject
return new Promise<string>((resolve, reject) => {
tmp.file(
{mode: 0b111000000, prefix: opt.prefix, postfix: opt.postfix},
(err, fpath, fd) => {
if (err) {
reject(err);
return;
}
try {
const ostream = fs.createWriteStream(fpath, {fd});
const req = https.get(url, res => {
if (res.statusCode !== 200) {
reject(new Error('Non-200 response when downloading new CMake installer'));
return;
}
let totalSize: number = 0;
try {
totalSize = parseInt(res.headers['content-length'] || '0');
} catch (e) {
// Do nothing. Oh well.
}
let prevDownloaded = 0;
let totalDownloaded = 0;
res.on('data', data => {
totalDownloaded = totalDownloaded + data.length;
if (totalSize !== 0) {
const diffPercent = 100 * (totalDownloaded - prevDownloaded) / totalSize;
const totalPercent = 100 * totalDownloaded / totalSize;
if (diffPercent > 1) {
pr.report({
increment: diffPercent,
message: `${totalPercent.toFixed(0)}%`,
});
prevDownloaded = totalDownloaded;
}
}
});
res.pipe(ostream);
res.on('end', () => {
log.info(`Downloaded ${url} to ${fpath}`);
resolve(fpath);
});
});
req.on('error', e => reject(e));
} catch (e) { reject(e); }
},
);
});
示例6: reject
repo.downloadAsset(foundAsset, (err, inStream) => {
if (err) {
return reject(err);
}
tmp.file((err, tmpPath, fd, cleanupCallback) => {
if (err) {
return reject(err);
}
console.log(`[OmniSharp] Downloading to ${tmpPath}...`);
const outStream = fs.createWriteStream(null, { fd: fd });
outStream.once('error', err => reject(err));
inStream.once('error', err => reject(err));
outStream.once('finish', () => {
// At this point, the asset has finished downloading.
console.log(`[OmniSharp] Download complete!`);
let decompress = new Decompress()
.src(tmpPath)
.dest(DefaultInstallLocation);
if (path.extname(foundAsset.name).toLowerCase() === '.zip') {
decompress = decompress.use(Decompress.zip());
console.log(`[OmniSharp] Unzipping...`);
}
else {
decompress = decompress.use(Decompress.targz());
console.log(`[OmniSharp] Untaring...`);
}
decompress.run((err, files) => {
if (err) {
return reject(err);
}
console.log(`[OmniSharp] Done! ${files.length} files unpacked.`)
return resolve(true);
});
});
inStream.pipe(outStream);
});
});
示例7: installFailed
.then((res) => {
loader.update('Saving installer...');
tmp.file((err, path, fd, cleanupCallback) => {
if (err) {
console.error(err);
installFailed();
return;
}
fs.write(fd, res.data, 0, 'utf8', (err) => {
if (err) {
console.error(err);
installFailed();
return;
}
console.log(`written to: ${path}`);
loader.update('Running installer...', true);
this.Runner.runCommandAsync('python', path)
.then((out) => {
console.log(out);
remote.dialog.showMessageBox({
type: 'info',
title: 'Installation successful',
message: 'PIP was successfully installed.',
buttons: ['OK']
});
}, (out) => {
console.error('Failed...', out);
installFailed();
})
.finally(() => {
loader.done();
cleanupCallback();
this.$state.reload();
});
});
});
}, (res) => {
示例8: download
return download(SERVER_ARCHIVE, proxy, strictSSL).then(is => {
tmp.file((err, tmpPath, fd, cleanupCallback) => {
const out = fs.createWriteStream(null, { fd: fd });
// handle errors
out.once('error', err => {
closeDownloadProgressItem();
reject(err);
});
is.once('error', err => {
closeDownloadProgressItem();
reject(err);
});
out.once('finish', () => {
decompress(tmpPath, SERVER_FOLDER).then(files => {
closeDownloadProgressItem();
return resolve(true);
}).catch(err => {
closeDownloadProgressItem();
return reject(err);
});
});
is.pipe(out);
});
}).catch(err => {
示例9:
const [path, cleanup] = await new Promise<[string, any]>((res, rej) => {
tmp.file((e, path, fd, cleanup) => {
if (e) return rej(e);
res([path, cleanup]);
});
});