How to use fs-temp - 10 common examples

To help you get started, we’ve selected a few fs-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 tessel / t2-cli / lib / install / rust.js View on Github external
return new Promise((resolve) => {
    var dir = fsTemp.template('t2-sdk-%s').mkdirSync();
    resolve({
      path: dir,
      cleanup: () => {
        try {
          fs.removeSync(dir);
        } catch (e) {
          // If the folder no longer exists, or if the remove operation throws
          // some error, this is non-fatal to the user (the data will just
          // exist until the temp folder is cleaned) and so we swallow any
          // errors.
        }
      }
    });
  });
}
github tessel / t2-cli / lib / tessel / deployment / python.js View on Github external
exportables.tarBundle = function(opts) {
  var cwd = process.cwd();
  var target = opts.target || cwd;
  var relative = path.relative(cwd, target);
  var globRoot = relative || target;
  var packer = tar.Pack({
    noProprietary: true
  });
  var buffers = [];
  var tempBundleDir = fsTemp.mkdirSync();

  var includeRules = glob.rules(target, '.tesselinclude').concat(lists.includes);
  var includeFiles = glob.files(globRoot, includeRules);
  var includeNegateRules = includeRules.reduce((rules, pattern) => {
    if (pattern.startsWith('!')) {
      rules.push(pattern.slice(1));
    }
    return rules;
  }, []);

  if (fs.existsSync(path.join(target, 'setup.py'))) {
    // TODO:
    // Create a cross-compilation server for compiling?
  }

  // For now, stay out of that path.
github tessel / t2-cli / lib / tessel / deployment / javascript.js View on Github external
/* istanbul ignore else */
      if (exportables.minimatch(details.modulePath, rule, matchOptions)) {
        details.ignored = true;
        details.resolved = false;
      }
    });
  });

  log.info('Building project.');


  // Both the --slim and --full paths will use a copy of the
  // project to bundle. This allows us to be destructive
  // with the files, but without directly tampering with the
  // project files themselves.
  var tempBundleDir = fsTemp.mkdirSync();

  if (options.slim) {
    return new Promise((resolve, reject) => {
      var absRoot = path.resolve(globRoot);
      // Setup for detecting "overlooked" assets (files, directories, etc.)
      var common = [
        'node_modules', 'package.json',
        '.tesselinclude', '.tesselignore',
        options.resolvedEntryPoint
      ];
      // These will be compared against the dependency graph
      var assets = fs.readdirSync(globRoot)
        .filter(entry => (common.indexOf(entry) === -1))
        .map(entry => path.join(globRoot, entry));

      // Initialize a project for dependency graphing
github LinusU / node-appdmg / test / bin.js View on Github external
it('should create dmg file', function () {
    this.timeout(60000)

    const source = path.join(__dirname, 'assets', 'appdmg.json')
    const targetDir = temp.mkdirSync()
    const targetPath = path.join(targetDir, 'Test.dmg')

    const res = spawnSync(bin, [ source, targetPath ])

    fs.unlinkSync(targetPath)
    fs.rmdirSync(targetDir)

    assert.ok(bufferContains(res.stderr, targetPath))
  })
})
github koajs / multer / test / disk-storage.js View on Github external
it("should report error when directory doesn't exist", done => {
    const directory = path.join(temp.mkdirSync(), 'ghost');
    function dest($0, $1, cb) {
      cb(null, directory);
    }

    const storage = multer.diskStorage({ destination: dest });
    const upload = multer({ storage });
    const parser = upload.single('tiny0');
    const form = new FormData();

    form.append('tiny0', util.file('tiny0.dat'));

    util.submitForm(parser, form, (err, req) => {
      assert.equal(err.code, 'ENOENT');
      assert.equal(path.dirname(err.path), directory);

      done();
github fox1t / fastify-multer / test / disk-storage.ts View on Github external
it("should report error when directory doesn't exist", function(done) {
    const directory = path.join(temp.mkdirSync(), 'ghost')
    function dest($0, $1, cb) {
      cb(null, directory)
    }

    const storage = multer.diskStorage({ destination: dest })
    const localUpload = multer({ storage: storage })
    const parser = localUpload.single('tiny0')
    const form = new FormData()

    form.append('tiny0', file('tiny0.dat'))

    submitForm(parser, form, function(err, req) {
      assert.equal(err.code, 'ENOENT')
      assert.equal(path.dirname(err.path), directory)

      done()
github fox1t / fastify-multer / test / unicode.ts View on Github external
beforeEach(function(done) {
    temp.mkdir(function(err, p) {
      if (err) {
        return done(err)
      }

      const storage = multer.diskStorage({
        destination: p,
        filename: function(req, f, cb) {
          cb(null, f.originalname)
        },
      })

      uploadDir = p
      upload = multer({ storage: storage })
      done()
    })
  })
github koajs / multer / test / unicode.js View on Github external
beforeEach(done => {
    temp.mkdir((err, path) => {
      if (err) return done(err);

      const storage = multer.diskStorage({
        destination: path,
        filename: (req, file, cb) => {
          cb(null, file.originalname);
        }
      });

      uploadDir = path;
      upload = multer({ storage });
      done();
    });
  });
github fox1t / fastify-multer / test / functionality.ts View on Github external
function makeStandardEnv(cb) {
    temp.mkdir(function(err, uploadDir) {
      if (err) {
        return cb(err)
      }

      cleanup.push(uploadDir)

      const storage = multer.diskStorage({
        destination: uploadDir,
        filename: generateFilename,
      })

      cb(null, {
        upload: multer({ storage: storage }),
        uploadDir: uploadDir,
        form: new FormData(),
      })
github koajs / multer / test / disk-storage.js View on Github external
beforeEach(done => {
    temp.mkdir((err, path) => {
      if (err) return done(err);

      uploadDir = path;
      upload = multer({ dest: path });
      done();
    });
  });

fs-temp

`fs-temp` is a quick and simple way to create temporary files and directories.

MIT
Latest version published 3 years ago

Package Health Score

47 / 100
Full package analysis