How to use tempfile - 10 common examples

To help you get started, we’ve selected a few tempfile 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 radiovisual / timecard / test / clockout.js View on Github external
test.beforeEach('cleanup tempfile', async t => {
		// Create a blank timecard on the disk so that the operations
		// that require a timecard file can find one.
		const temppath = tempfile('.json');
		tempfiles.push(temppath);
		t.context.timecard = new Timecard({prompt: false, filepath: temppath});
		await t.context.timecard.create();
});
github radiovisual / timecard / test / clockin.js View on Github external
test.beforeEach('cleanup tempfile', async t => {
		// Create a blank timecard on the disk so that the operations
		// that require a timecard file can find one.
		const temppath = tempfile('.json');
		tempfiles.push(temppath);
		t.context.timecard = new Timecard({prompt: false, filepath: temppath});
		await t.context.timecard.create();
});
github sindresorhus / alfy / test / cache.js View on Github external
test('versioned data', t => {
	const cache = tempfile();

	const alfy = createAlfy({cache, version: '1.0.0'});
	alfy.cache.set('foo', 'bar');

	const alfy2 = createAlfy({cache, version: '1.0.0'});
	t.is(alfy2.cache.get('foo'), 'bar');

	const alfy3 = createAlfy({cache, version: '1.0.1'});
	t.falsy(alfy3.cache.get('foo'));
});
github sindresorhus / execa / test / stream.js View on Github external
test('pass `stdout` to a file descriptor', async t => {
	const file = tempfile('.txt');
	await execa('test/fixtures/noop', ['foo bar'], {stdout: fs.openSync(file, 'w')});
	t.is(fs.readFileSync(file, 'utf8'), 'foo bar\n');
});
github mathphreak / ReliefValve / test / size.js View on Github external
import test from 'ava';
import fs from 'fs.extra';
import tempfile from 'tempfile';

import loadGameSize from '../src/steps/size';

const gamePath = tempfile('');

let totalSize = 0;

function makeFile(path, mbSize) {
  const fileSize = mbSize * 1024 * 1024;
  totalSize += fileSize;
  fs.writeFileSync(path, new Buffer(fileSize));
}

test.before('setup for sizeSteps', () => {
  fs.mkdirpSync(`${gamePath}/Sub`);
  makeFile(`${gamePath}/Test1`, 3);
  makeFile(`${gamePath}/Test2`, 6);
  makeFile(`${gamePath}/Sub/Test3`, 14);
  makeFile(`${gamePath}/Sub/Test4`, 21);
});
github algolia / shipjs / packages / shipjs / src / step / prepare / updateChangelog.js View on Github external
templateContext,
    gitRawCommitsOpts
  ).on('error', reject);

  const readStream = fs.createReadStream(args.infile).on('error', reject);
  if (args.sameFile) {
    if (args.append) {
      changelogStream
        .pipe(
          fs.createWriteStream(args.outfile, {
            flags: 'a',
          })
        )
        .on('finish', resolve);
    } else {
      const tmp = tempfile();

      changelogStream
        .pipe(addStream(readStream))
        .pipe(fs.createWriteStream(tmp))
        .on('finish', () => {
          fs.createReadStream(tmp)
            .pipe(fs.createWriteStream(args.outfile))
            .on('finish', resolve);
        });
    }
  } else {
    let outStream;
    if (args.outfile) {
      outStream = fs.createWriteStream(args.outfile);
    } else {
      outStream = process.stdout;
github motivast / motimize / src / web / middlewares / handlers / image.js View on Github external
function handleBase64(fileBase64) {
  let tmp = tempfile();

  fs.writeFileSync(tmp, fileBase64, "base64");

  checkMimeType(tmp);

  return { filename: "", path: tmp };
}
github motivast / motimize / src / worker / optimizer / optimize.js View on Github external
function downloadImage(image) {
  let url = config.get("url");
  let tmp = tempfile();
  let stream = fs.createWriteStream(tmp);

  let getParams = {
    uri: url + "/image/" + image.id + "/download"
  };

  return new Promise((resolve, reject) => {
    request
      .get(getParams)
      .on("error", err => reject(err))
      .pipe(stream)
      .on("finish", () => resolve(tmp));
  });
}
github motivast / motimize / src / web / middlewares / handlers / image.js View on Github external
async function handleUrl(fileUrl) {
  let tmp = tempfile();

  let parsed = url.parse(fileUrl);
  let filename = path.basename(parsed.pathname);

  let downloaded = await download(fileUrl);

  fs.writeFileSync(tmp, downloaded);

  checkMimeType(tmp);

  return { filename: filename, path: tmp };
}
github geut / chan / src / cli / lib / open-in-editor.js View on Github external
import tempfile from 'tempfile';
import pify from 'pify';

const tmpFile = tempfile('.md');
const readFile = pify(require('fs').readFile);
const editor = pify(require('editor'));

export default function openInEditor({ group = null, silence = true }) {
    return editor(tmpFile)
        .then(() => {
            return readFile(tmpFile, 'utf8');
        })
        .then((data) => {
            if (data.length === 0) {
                throw new Error(`The file is empty '${tmpFile}'`);
            }

            if (group) {
                return `[${group}] ${data}`;
            }

tempfile

Get a random temporary file path

MIT
Latest version published 1 year ago

Package Health Score

70 / 100
Full package analysis

Popular tempfile functions