How to use the fs.statSync function in fs

To help you get started, we’ve selected a few fs 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 thlorenz / flush-all / test / flush-all.js View on Github external
var stat;
  var pid = process.pid;
  var mapFile = '/tmp/perf-' + pid + '.map';

  t.ok(fs.existsSync(mapFile), 'map file exists')

  stat = fs.statSync(mapFile);

  var firstSize = stat.size;
  // Linux flushes too aggressively 
  if (os.platform() === 'darwin') 
    t.equal(firstSize, 0, 'and on darwin its size is 0 since it has not been flushed yet')

  flushAll();

  stat = fs.statSync(mapFile);
  // The below by itself is not really a proof since just calling 'flushAll' causes more JIT code to be generated which by 
  // itself would increase the map file size.
  // However since Linux flushes more aggressively this is as good as we can do there.
  // On darwin, we can show that before flushAll nothing got flushed and afterwards it did which is the 
  // actual proof that this works.
  t.ok(stat.size > firstSize, 'after I flush all, the map file size is larger than before and non-zero since has been flushed')

  console.log('size before flushAll()', firstSize);
  console.log('size after  flushAll()', stat.size);
  t.end()
})
github hex7c0 / mongodb-restore / test / z_clear.js View on Github external
fs.readdirSync(path).forEach(function(first) { // database

        var database = path + first;
        assert.equal(fs.statSync(database).isDirectory(), true);
        var metadata = '';
        var collections = fs.readdirSync(database);
        if (fs.existsSync(database + '/.metadata') === true) {
          metadata = database + '/.metadata/';
          delete collections[collections.indexOf('.metadata')]; // undefined is not a dir
        }
        collections.forEach(function(second) { // collection

          var collection = database + '/' + second;
          if (fs.statSync(collection).isDirectory() === false) {
            return;
          }
          fs.readdirSync(collection).forEach(function(third) { // document

            var document = collection + '/' + third;
            if (next !== undefined) {
github jameswlane / status-board / src / item-manager.ts View on Github external
items.forEach((itemName: any) => {
        let item = path.join(itemDir, itemName);
        const stat = fs.statSync(item);
        if (stat.isDirectory()) {
          // /job/job1/job1.js
          item = path.join(item, itemName + extension);
        }

        if (path.extname(item) === extension) {
          if (fs.existsSync(item)) {
            selectedItems.push(item);
          }
        }
      });
github yahoo / elide-js / spec / testing-tools / mock-server.js View on Github external
function deleteObject(request, response) {
  var filePath;

  filePath = fileForUrl(request.url, false);
  try {
    fs.statSync(filePath);
  } catch (e) {
    debugDelete('file for url', request.url, 'does not exist');
    respondWith(response, 403, JSON.stringify({error: 'Invalid request'}));
    return;
  }

  respondWith(response, 204, '');
}
github appcelerator / titanium_mobile / iphone / cli / commands / _build.js View on Github external
fs.readdirSync(resourcesDir).forEach(function (filename) {
			var lcaseFilename = filename.toLowerCase(),
				isDir = fs.statSync(path.join(resourcesDir, filename)).isDirectory();

			if (this.blacklistDirectories.indexOf(lcaseFilename) !== -1) {
				if (isDir) {
					logger.error(__('Found blacklisted directory in the Resources directory') + '\n');
					logger.error(__('The directory "%s" is a reserved word.', filename));
					logger.error(__('You must rename this directory to something else.') + '\n');
				} else {
					logger.error(__('Found blacklisted file in the Resources directory') + '\n');
					logger.error(__('The file "%s" is a reserved word.', filename));
					logger.error(__('You must rename this file to something else.') + '\n');
				}
				process.exit(1);
			} else if (this.graylistDirectories.indexOf(lcaseFilename) !== -1) {
				if (isDir) {
					logger.warn(__('Found graylisted directory in the Resources directory'));
					logger.warn(__('The directory "%s" is potentially a reserved word.', filename));
github perfectsense / brightspot-styleguide / js / handlebars.js View on Github external
function compile (path) {
  if (!compiledTemplates[path]) {
    compiledTemplates[path] = {
      time: fs.statSync(path).mtime.getTime(),
      template: handlebars.compile(fs.readFileSync(path, 'utf8'))
    }
  } else {
    const newTime = fs.statSync(path).mtime.getTime()

    if (compiledTemplates[path].time !== newTime) {
      compiledTemplates[path] = {
        time: newTime,
        template: handlebars.compile(fs.readFileSync(path, 'utf8'))
      }
    }
  }

  return compiledTemplates[path].template
}
github vwxyutarooo / gulp-web-starter / tools / gulp / functions.js View on Github external
return fs.readdirSync(dir).filter((file) => {
    return fs.statSync(path.join(dir, file)).isDirectory();
  });
}
github Halliwood / ts2lua / src / index.ts View on Github external
function readDir(dirPath: string, collectOrTranslate: boolean) {
  let files = fs.readdirSync(dirPath);
  for(let i = 0, len = files.length; i < len; i++) {
    let filename = files[i];
    let filePath = path.join(dirPath, filename);
    let fileStat = fs.statSync(filePath);
    if(fileStat.isFile()) {
      let fileExt = path.extname(filename).toLowerCase();
      if('.ts' == fileExt) {
        if(collectOrTranslate) {
          collectClass(filePath);
        } else {
          doTranslateFile(filePath);
        }
      }
    } else {
      readDir(filePath, collectOrTranslate);
    }
  }
}
github shekit / peeqo-robot / cordova / platforms / browser / cordova / node_modules / shelljs / build / output.js View on Github external
function checkPath(path) {
  return fs.existsSync(path) && !fs.statSync(path).isDirectory();
}
github jackfranklin / react-training-workshop / webpack.dev.js View on Github external
return fs.readdirSync(srcpath).filter(function(file) {
    return fs.statSync(path.join(srcpath, file)).isFile() &&
      file.indexOf('.js') > -1;
  });
};

fs

This package name is not currently in use, but was formerly occupied by another package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it.

ISC
Latest version published 8 years ago

Package Health Score

67 / 100
Full package analysis