How to use the graceful-fs.readFile 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 MobileChromeApps / mobile-chrome-apps / node_modules / cordova / node_modules / npm / lib / install.js View on Github external
var t = tree[k]
          , u = url.parse(t.from)
          , w = t.what.split("@")
        if (u && u.protocol) w[1] = t.from
        return w
      }).reduce(function (set, k) {
        var rangeDescriptor = semver.valid(k[1], true) &&
                              semver.gte(k[1], "0.1.0", true)
                            ? "~" : ""
        set[k[0]] = rangeDescriptor + k[1]
        return set
      }, {})

  // don't use readJson, because we don't want to do all the other
  // tricky npm-specific stuff that's in there.
  fs.readFile(saveTarget, function (er, data) {
    // ignore errors here, just don't save it.
    try {
      data = JSON.parse(data.toString("utf8"))
    } catch (ex) {
      er = ex
    }

    if (er) {
      return cb(null, installed, tree, pretty)
    }

    var deps = npm.config.get("save-optional") ? "optionalDependencies"
             : npm.config.get("save-dev") ? "devDependencies"
             : "dependencies"

    if (saveBundle) {
github JudgeGirl / JudgeNode / lib / components / ProblemManager.js View on Github external
var sourceList = function(pid, callback) {
    var source_list_path = config.JUDGE.testdata.path + "/" + pid + "/source.lst";
    fs.readFile(source_list_path, 'utf8', function(err, buf_data) {
        var source_list = [];
        if (!err)
            source_list = buf_data.toString().split('\n');
        for (var i = 0; i < source_list.length; i++) {
            if (source_list[i].trim().length == 0) {
                source_list.splice(i, 1);
                i--;
            }
        }
        callback(source_list);
    });
};
var testdataList = function(pid, callback) {
github facebook / react / npm-jsx_whitespace_transformer / run.js View on Github external
finder.on('match', function(pathStr, stat) {
    fs.readFile(pathStr, 'utf8', function(err, data) {
      if (err) {
        err.message = err.message + ' (' + pathStr + ')';
        throw err;
      }

      if (/@jsx React\.DOM/.test(data)) {
        numTransforms++;
        _printProgress();

        var transformedData;
        try {
          transformedData = _transformSource(data);
        } catch (e) {
          e.message = e.message + ' (' + pathStr + ')';
          throw e;
        }
github jonschlinkert / stream-loader / contents.js View on Github external
return through.obj(function (file, enc, cb) {
    if (file.isDirectory()) {
      return cb(null, file);
    }

    if (options.buffer !== false) {
      return fs.readFile(file.path, function (err, data) {
        if (err) return cb(err);

        file.contents = data;
        return cb(null, file);
      });
    }

    try {
      file.contents = fs.createReadStream(file.path);
      return cb(null, file);
    } catch (err) {
      return cb(err);
    }
  });
};
github ether / etherpad-lite / src / static / js / pluginfw / read-installed.js View on Github external
function readJson(file, callback) {
  fs.readFile(file, function(er, buf) {
    if(er) {
      callback(er);
      return;
    }
    try {
      callback( null, JSON.parse(buf.toString()) )
    } catch(er) {
      callback(er)
    }
  })
}
github NuSkooler / enigma-bbs / core / servers / content / web.js View on Github external
respondWithError(resp, code, bodyText, title) {
        const customErrorPage = paths.join(Config().contentServers.web.staticRoot, `${code}.html`);

        fs.readFile(customErrorPage, 'utf8', (err, data) => {
            resp.writeHead(code, { 'Content-Type' : 'text/html' } );

            if(err) {
                return resp.end(`
                    
                        
                        
                        <title>${title}</title>
                        
                        
                        
                            <article>
                                <h2>${bodyText}</h2>
                            </article>
                        
                    `
github krakenjs / makara / lib / view / js.js View on Github external
return function onLoad(name, context, callback) {
        var locals, view;

        locals = context.get('context');
        view = res.resolve(name, locals && (locals.contentLocality || locals.locality));

        if (!view.file) {
            callback(new Error('Could not load template ' + name));
            return;
        }

        fs.readFile(view.file, 'utf8', callback);
    };
};
github gameclosure / devkit / src / reinstall / index.js View on Github external
var f = ff(this, function () {
		fs.readFile('./manifest.json', 'utf8', f());
	}, function (manifest) {
		var shortName = JSON.parse(manifest).shortName;
github davidhealey / waistline / node_modules / npm / lib / install.js View on Github external
var rv = {}
      Object.keys(data).forEach(function (key) {
        rv[key] = data[key]
      })
      rv.dependencies = {}
      Object.keys(wrap).forEach(function (key) {
        log.verbose("from wrap", [key, wrap[key]])
        rv.dependencies[key] = readWrap(wrap[key])
      })
      log.verbose("readDependencies returned deps", rv.dependencies)
      return cb(null, rv, wrap)
    }

    var wrapfile = path.resolve(where, "npm-shrinkwrap.json")

    fs.readFile(wrapfile, "utf8", function (er, wrapjson) {
      if (er) return cb(null, data, null)

      log.verbose("readDependencies", "npm-shrinkwrap.json is overriding dependencies")
      var newwrap
      try {
        newwrap = JSON.parse(wrapjson)
      } catch (ex) {
        return cb(ex)
      }

      log.info("shrinkwrap", "file %j", wrapfile)
      var rv = {}
      Object.keys(data).forEach(function (key) {
        rv[key] = data[key]
      })
      rv.dependencies = {}
github marklagendijk / WinLess / WinLess / node_modules / npm / lib / install.js View on Github external
var rv = {}
      Object.keys(data).forEach(function (key) {
        rv[key] = data[key]
      })
      rv.dependencies = {}
      Object.keys(wrap).forEach(function (key) {
        log.verbose("from wrap", [key, wrap[key]])
        rv.dependencies[key] = readWrap(wrap[key])
      })
      log.verbose("readDependencies returned deps", rv.dependencies)
      return cb(null, rv, wrap)
    }

    var wrapfile = path.resolve(where, "npm-shrinkwrap.json")

    fs.readFile(wrapfile, "utf8", function (er, wrapjson) {
      if (er) {
        log.verbose("readDependencies", "using package.json deps")
        return cb(null, data, null)
      }

      try {
        var newwrap = JSON.parse(wrapjson)
      } catch (ex) {
        return cb(ex)
      }

      log.info("shrinkwrap", "file %j", wrapfile)
      var rv = {}
      Object.keys(data).forEach(function (key) {
        rv[key] = data[key]
      })