How to use the graceful-fs.openSync function in graceful-fs

To help you get started, we’ve selected a few graceful-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 Kode / khamake / node_modules / fs-extra / lib / util / utimes.js View on Github external
function hasMillisRes () {
  // 550 millis past UNIX epoch
  var d = new Date(550)
  var tmpfile = path.join(require('os').tmpdir(), 'millis-test')
  fs.writeFileSync(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141')
  var fd = fs.openSync(tmpfile, 'r+')
  fs.futimesSync(fd, d, d)
  fs.closeSync(fd)
  return fs.statSync(tmpfile).mtime > 0
}
github graalvm / graaljs / deps / npm / node_modules / node-gyp / lib / configure.js View on Github external
function findAccessibleSync (logprefix, dir, candidates) {
  for (var next = 0; next < candidates.length; next++) {
    var candidate = path.resolve(dir, candidates[next])
    try {
      var fd = fs.openSync(candidate, 'r')
    } catch (e) {
      // this candidate was not found or not readable, do nothing
      log.silly(logprefix, 'Could not open %s: %s', candidate, e.message)
      continue
    }
    fs.closeSync(fd)
    log.silly(logprefix, 'Found readable %s', candidate)
    return candidate
  }

  return undefined
}
github Rich-Harris / sander / index.js View on Github external
throw err;
				}
			}

			if ( alreadyExists ) {
				// attempt the operation = that way, we get the intended error message
				fs.openSync( src, flags, options.mode );
			}
		}

		if ( isSync ) {
			if ( shouldCreateDirs ) {
				mkdirp.sync( path.dirname( src ) );
			}

			return fs.openSync( src, flags, options.mode );
		}

		return new Promise( function ( fulfil, reject ) {
			if ( shouldCreateDirs ) {
				mkdirp( path.dirname( src ), function ( err, result ) {
					if ( err ) {
						reject( err );
					} else {
						open();
					}
				});
			} else {
				open();
			}

			function open () {
github depjs / dep / node_modules / node-gyp / lib / configure.js View on Github external
function findAccessibleSync (logprefix, dir, candidates) {
  for (var next = 0; next < candidates.length; next++) {
    var candidate = path.resolve(dir, candidates[next])
    try {
      var fd = fs.openSync(candidate, 'r')
    } catch (e) {
      // this candidate was not found or not readable, do nothing
      log.silly(logprefix, 'Could not open %s: %s', candidate, e.message)
      continue
    }
    fs.closeSync(fd)
    log.silly(logprefix, 'Found readable %s', candidate)
    return candidate
  }

  return undefined
}
github alan-ai / alan-sdk-reactnative / testtools / node_modules / fs-extra / lib / copy-sync / copy-sync.js View on Github external
function copyFileFallback (srcStat, src, dest, opts) {
  const BUF_LENGTH = 64 * 1024
  const _buff = require('../util/buffer')(BUF_LENGTH)

  const fdr = fs.openSync(src, 'r')
  const fdw = fs.openSync(dest, 'w', srcStat.mode)
  let pos = 0

  while (pos < srcStat.size) {
    const bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
    fs.writeSync(fdw, _buff, 0, bytesRead)
    pos += bytesRead
  }

  if (opts.preserveTimestamps) fs.futimesSync(fdw, srcStat.atime, srcStat.mtime)

  fs.closeSync(fdr)
  fs.closeSync(fdw)
}
github alan-ai / alan-sdk-reactnative / testtools / node_modules / fs-extra / lib / copy-sync / copy-sync.js View on Github external
function copyFileFallback (srcStat, src, dest, opts) {
  const BUF_LENGTH = 64 * 1024
  const _buff = require('../util/buffer')(BUF_LENGTH)

  const fdr = fs.openSync(src, 'r')
  const fdw = fs.openSync(dest, 'w', srcStat.mode)
  let pos = 0

  while (pos < srcStat.size) {
    const bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
    fs.writeSync(fdw, _buff, 0, bytesRead)
    pos += bytesRead
  }

  if (opts.preserveTimestamps) fs.futimesSync(fdw, srcStat.atime, srcStat.mtime)

  fs.closeSync(fdr)
  fs.closeSync(fdw)
}
github gulpjs / vinyl-fs / test / dest-modes.js View on Github external
var file = new File({
      base: inputBase,
      path: inputPath,
      contents: new Buffer(contents),
      stat: {
        mode: expectedMode,
      },
    });

    function assert() {
      expect(statMode(outputPath)).toEqual(expectedMode);
    }

    fs.mkdirSync(outputBase);
    fs.closeSync(fs.openSync(outputPath, 'w'));
    fs.chmodSync(outputPath, startMode);

    pipe([
      from.obj([file]),
      vfs.dest(outputBase, { cwd: __dirname }),
      concat(assert),
    ], done);
  });
github gulpjs / vinyl-fs / test / file-operations.js View on Github external
}

    var fchmodSpy = expect.spyOn(fs, 'fchmod').andCallThrough();

    var mode = applyUmask('777');

    var file = new File({
      base: outputBase,
      path: outputPath,
      contents: null,
      stat: {
        mode: mode,
      },
    });

    var fd = fs.openSync(outputPath, 'w+');

    updateMetadata(fd, file, function() {
      expect(fchmodSpy.calls.length).toEqual(1);
      var stats = fs.fstatSync(fd);
      expect(file.stat.mode).toEqual(stats.mode);

      fs.close(fd, done);
    });
  });
github generate / generate / test / app.dest.js View on Github external
base: inputBase,
      cwd: __dirname,
      path: inputPath,
      contents: expectedContents,
      stat: {
        mode: expectedMode
      }
    });

    var onEnd = function() {
      assert.equal(masked(fs.lstatSync(expectedPath).mode), expectedMode);
      cb();
    };

    fs.mkdirSync(expectedBase);
    fs.closeSync(fs.openSync(expectedPath, 'w'));
    fs.chmodSync(expectedPath, startMode);

    var stream = app.dest('actual/', { cwd: __dirname });
    stream.on('end', onEnd);
    stream.write(expectedFile);
    stream.end();
  });
github tidys / CocosCreatorPlugins / packages / excel-killer / node_modules / fs-extra / lib / copy-sync / copy-sync.js View on Github external
function copyFileFallback (srcStat, src, dest, opts) {
  const BUF_LENGTH = 64 * 1024
  const _buff = require('../util/buffer')(BUF_LENGTH)

  const fdr = fs.openSync(src, 'r')
  const fdw = fs.openSync(dest, 'w', srcStat.mode)
  let bytesRead = 1
  let pos = 0

  while (bytesRead > 0) {
    bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
    fs.writeSync(fdw, _buff, 0, bytesRead)
    pos += bytesRead
  }

  if (opts.preserveTimestamps) fs.futimesSync(fdw, srcStat.atime, srcStat.mtime)

  fs.closeSync(fdr)
  fs.closeSync(fdw)
}