當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript tmp.file函數代碼示例

本文整理匯總了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);
         }
     });
   });
 });
開發者ID:nikuuchi,項目名稱:nez-web,代碼行數:31,代碼來源:post.ts

示例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);
     });
 })
開發者ID:Firaenix,項目名稱:omnisharp-vscode,代碼行數:33,代碼來源:download.ts

示例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);
     });
 });
開發者ID:Huachao,項目名稱:vscode-restclient,代碼行數:25,代碼來源:historyController.ts

示例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 => {
開發者ID:swyphcosmo,項目名稱:vscode-cpptools,代碼行數:50,代碼來源:extension.ts

示例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); }
        },
    );
  });
開發者ID:vector-of-bool,項目名稱:vscode-cmake-tools,代碼行數:50,代碼來源:cm-upgrade.ts

示例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);
                });
            });
開發者ID:Jeffiy,項目名稱:omnisharp-vscode,代碼行數:49,代碼來源:omnisharpDownload.ts

示例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) => {
開發者ID:rose-m,項目名稱:oSeed,代碼行數:40,代碼來源:ctrl.ts

示例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 => {
開發者ID:silverbulleters,項目名稱:vsc-spellchecker,代碼行數:24,代碼來源:downloadManager.ts

示例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]);
		});
	});
開發者ID:ha-dai,項目名稱:Misskey,代碼行數:6,代碼來源:upload-from-url.ts


注:本文中的tmp.file函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。