How to use the temp.path function in temp

To help you get started, we’ve selected a few temp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github joehewitt / nerve / lib / BlogRouter.js View on Github external
res.sendSafely(_.bind(function(cb) {
                var urlPath = req.params[0].split('/');
                if (urlPath.length > 1 && urlPath[0] == imagesDirName) {
                    var imageFileName = urlPath[1];
                    // var imageSize = urlPath[2];
                    // var imagePath = path.join(blog.contentPaths[0].path, imagesDirName,
                                                // imageFileName);
                    var imageSize = null;//urlPath[2];
                    var imagePath = path.join(blog.contentPaths[0].path, imagesDirName,
                                              urlPath.slice(1).join('/'));
                    if (!imageSize) {
                        cb(0, {path: imagePath});
                    } else {
                        var temp = require('temp');
                        var tempPath = temp.path({suffix: path.extname(imagePath)});
                        
                        var options = {
                            srcPath: imagePath,
                            dstPath: tempPath
                        };

                        var m = /^\s*(\d*)x(\d*)\s*$/.exec(imageSize);
                        if (m) {
                            if (m[1]) {
                                options.width = parseInt(m[1]);
                            }
                            if (m[2]) {
                                options.height = parseInt(m[2]);
                            }
                        }
                        if (options.width && options.height) {
github danvk / source-map-explorer / src / cli.ts View on Github external
async function writeHtmlToTempFile(html?: string): Promise {
  if (!html) {
    return;
  }

  try {
    const tempFile = temp.path({ prefix: 'sme-result-', suffix: '.html' });
    fs.writeFileSync(tempFile, html);

    const childProcess = await open(tempFile);

    if (childProcess.stderr) {
      // Catch error output from child process
      childProcess.stderr.once('data', (error: Buffer) => {
        logError({ code: 'CannotOpenTempFile', tempFile, error });
      });
    }
  } catch (error) {
    throw new AppError({ code: 'CannotCreateTempFile' }, error);
  }
}
github mrkmg / node-generate-release / test / specs / run-git-flow.spec.ts View on Github external
beforeEach(() => {
        startingDir = process.cwd();
        tempDir = path();
        setupGitFlowTestRepo(tempDir);
    });
github gemini-testing / gemini-gui / lib / app.js View on Github external
_buildDiffFile(failureReport) {
        const diffPath = temp.path({dir: this.diffDir, suffix: '.png'});
        return Promise.resolve(failureReport.saveDiffTo(diffPath))
            .thenReturn(diffPath);
    }
github appcelerator / node-appc / forge-tools / i18n / index.js View on Github external
function downloadI18NZip(url, callback) {
	var tempName = temp.path({ suffix: '.zip' }),
		tempStream = fs.createWriteStream(tempName),
		req = request({
			url: url
		});

	req.pipe(tempStream);

	req.on('error', function (err) {
		afs.exists(tempName) && fs.unlinkSync(tempName);
		console.error('\n' + __('Failed to download zip file: %s', err.toString()) + '\n');
		process.exit(1);
	});

	req.on('response', function (req) {
		if (req.statusCode >= 400) {
			console.error('\n' + __('Request failed with HTTP status code %s %s', req.statusCode, http.STATUS_CODES[req.statusCode] || '') + '\n');
github danvk / source-map-explorer / index.js View on Github external
function writeToHtml(html) {
  const tempName = temp.path({ suffix: '.html' });

  fs.writeFileSync(tempName, html);

  open(tempName, { wait: false }).catch(error => {
    console.error('Unable to open web browser. ' + error);
    console.error(
      'Either run with --html, --json or --tsv, or view HTML for the visualization at:'
    );
    console.error(tempName);
  });
}
github garris / BackstopJS / core / util / extendConfig.js View on Github external
function comparePaths (config) {
  config.comparePath = path.join(config.backstop, 'compare/output');
  config.tempCompareConfigFileName = temp.path({ suffix: '.json' });
}
github SRA-SiliconValley / jalangi / src / js / jalangi.js View on Github external
function getInstOutputFile(filePath) {
    if (filePath) {
        return path.resolve(filePath);
    } else {
        return temp.path({suffix: '.js'});
    }
}
github NativeScript / nativescript-cli / lib / common / mobile / mobile-helper.ts View on Github external
public async getDeviceFileContent(device: Mobile.IDevice, deviceFilePath: string, projectData: IProjectData): Promise {
		temp.track();
		const uniqueFilePath = temp.path({ suffix: ".tmp" });
		const platform = device.deviceInfo.platform.toLowerCase();
		try {
			await device.fileSystem.getFile(deviceFilePath, projectData.projectIdentifiers[platform], uniqueFilePath);
		} catch (e) {
			return null;
		}

		if (this.$fs.exists(uniqueFilePath)) {
			const text = this.$fs.readText(uniqueFilePath);
			shell.rm(uniqueFilePath);
			return text;
		}

		return null;
	}
}
github mortie / mmpc-media-streamer / js / torrent-player.js View on Github external
TorrentFile.prototype.makeFile = function() {
	this.path = temp.path({dir: "tmp", suffix: this.extension});
	if (this.file) {
		this.writeStream = fs.createWriteStream(this.path);
		this.readStream.pipe(this.writeStream);
	}
};
TorrentFile.prototype.cleanup = function() {