TODO-LATER; - Consider caching `getFileContent` - Possible in dev? - For sure in prod?
185125
async function getFileContent(filePath) {
    try {
        const fileContent = await fs.readFile(filePath);
        return fileContent;
    }
    catch(err) {
        if( err.code === 'ENOENT' ) {
            return null;
        }
        throw err;
    }
}
179223
function contentsSync(file, options) {
  if (!utils.isObject(file)) {
    throw new TypeError('expected file to be an object');
  }

  try {
    // ideally we want to stat the real, initial filepath
    file.stat = fs.lstatSync(file.history[0]);
  } catch (err) {
    try {
      // if that doesn't work, try again
      file.stat = fs.lstatSync(file.path);
    } catch (err) {
      file.stat = new fs.Stats();
    }
  }

  utils.syncContents(file, options);
  return file;
}
773538
public function getFileContents()
        {
            if ($this->fileContentsCache === null && $filePath = $this->getFile()) {

                // Return null if the file doesn't actually exist - this may
                // happen in cases where the filename is provided as, for
                // example, 'Unknown'
                if (!File::exists($filePath)) {
                    return null;
                }

                $this->fileContentsCache = File::read($filePath);
            }

            return $this->fileContentsCache;
        }
713349
function fetchFromCache(options, opts, cb) {
  // look for existing cached resource
  if (indirFiles.length > 0) {
    var etag;
    var regexp = '^' + opts.prefix +
                 '([A-Za-z0-9]+={0,2})' + // base64 encoded
                 opts.suffix + '$';
    var regex = new RegExp(regexp);
    var i;
    for (i = 0; i < indirFiles.length; i++) {
      var file = regex.exec(indirFiles[i]);
      if (file) {
        etag = new Buffer(file[1], 'base64').toString();
        break;
      }
    }

    if (etag) {
      try {
        var headOpts = JSON.parse(JSON.stringify(options)); // clone options
        headOpts.headers = { 'If-None-Match': etag };
        request.head(headOpts, function(err, res, body) {
          if (err) {
            logger.error(err);
            cb();
            // not fatal; continue
          } else if (res.statusCode === 304) {
            var filename = path.join(opts.outdir, indirFiles[i]);
            fs.copy(path.join(opts.indir, indirFiles[i]),
                    filename,
                    { preserveTimestamps: true },
                    function(err) {
                      if (err) {
                        throw (err);
                      }
                      var body = decryptData(fs.readFileSync(filename));
                      logger.info('Using cached copy of %s', indirFiles[i]);
                      var result = {
                        file: filename,
                        contents: body };
                      cb(null, result);
                    });
          } else {
            cb();
          }
        });
      } catch (e) {
        logger.error(e);
        cb();
        // not fatal; continue
      }
    } else {
      cb();
    }
  } else {
    cb();
  }
}
743494
def get_file_contents(self, file_key):
		'''
		'''
		#does not work
		self._raise_unimplemented_error()
		
		uri = '/'.join([self.api_uri,
						self.files_suffix,
						file_key,
						self.file_contents_suffix,
						])
		return self._req('get', uri)
698641
function cache(item, options) {
    var dir_path = pathutils.join([
        item.conf.cache.base_path,
        pathutils.getHashPath(item.source),
    ]);

    var meta_path = pathutils.join([dir_path, "meta"]);
    var source_path = pathutils.join([dir_path, "source"]);

    if (item.source_type === "file" && !item.conf.cache.copy_source_file) {
        source_path = item.source;
    }

    var target_path = pathutils.join([dir_path, 'targets', pathutils.getOptionsPath(options)]);

    /*
     * lock the files in sequence, not in parallel
     * otherwise a deadlock with other request may occur
     */
    var promise = lock(source_path).then(function(l) {
        logging.debug(item.id, "Locked: source file");
        item.locks.source = l;
        return lock(meta_path);
    }).then(function(l) {
        logging.debug(item.id, "Locked: metadata");
        item.locks.meta = l;
        return lock(target_path);
    }).then(function(l) {
        logging.debug(item.id, "Locked: target file");
        item.locks.target = l;
        return item;
    }).
    then(function(item) {
        return meta_data_still_fresh(item);
    }).
    then(function(item) {
        //meta data is still fresh
        logging.debug(item.id, "Metadata is still fresh");

        return item;
    }, function(item) {
        //meta_data is stale or doesn't exist
        logging.debug(item.id, "Metadata is stale");
        //clear the item directory and download a new version of the source
        var source_promise = fsutils.cleardir(dir_path).
        then(function() {
            logging.debug(item.id, "Item directory cleared");
            logging.debug(item.id, "Requesting source", item.source);
            return source(item);
        }, function(err) {
            // clearing the directory failed.
            // maybe it didn't exists, which would be ok
            if (err.code === "ENOENT") {
                logging.debug(item.id, "Requesting source", item.source);
                return source(item);
            } else {
                //no, it failed for some other reason
                item.error = err;
                throw item;
            }
        }).
        then(function(success) {
            //download succeeded
            logging.debug(item.id, "Source file ready");
            stats.download_success();
            //now only read metadata, don't evaluate headers or else
            //things with max-age=0 will always fail
            return read_meta_data(item);
        }, function(error) {
            logging.debug(item.id, "Acquiring source failed", error);
            stats.download_failure();
            throw item;
        });

        return source_promise;
    }).
    then(function(item) {
        //at this point the item is definitely fresh
        return get_target_file(item);
    }).
    then(function(item) {
        //the target has also been found. all done! \o/
        item.locks.meta();
        logging.debug(item.id, "Released lock: metadata");
        if (typeof item.locks.source === "function") {
            item.locks.source();
            logging.debug(item.id, "Released lock: source file");
        } else {
            //
        }

        register_for_gc(item);
        return item;
    },function(item) {
        item.locks.meta();
        logging.debug(item.id, "Released lock: metadata");
        item.locks.source();
        logging.debug(item.id, "Released lock: source file");
        item.locks.target();
        logging.debug(item.id, "Released lock: target file");

        register_for_gc(item);
        throw item;
    });

    return promise;
}
686133
static function GetFileContent($filename,&$error = null,&$error_str = null){
		$error = false;
		$error_str = "";

		$out = "";
		
		settype($filename,"string");

		if(!is_file($filename)){
			$error = true;
			$error_str = "$filename is not a file";
			return null;		
		}

		$filesize = filesize($filename);
		if($filesize==0){ return ""; }

		$f = fopen($filename,"r");
		if(!$f){
			$error = false;
			$error_str = "can't open file $filename for writing";
			return $out;
		}
		$out = fread($f,$filesize);
		fclose($f);

		return $out;
	}
705431
function _readFileOnEnd(filename, contents, cache) {
  loading--;
  const data = Buffer.concat(contents);
  cache.set(filename, data);
  _fireReadFileCallbacks(filename, data);
  _runFileQueue();
}
114080
public function getFileContent($container, $path, $local_file = '', $content_as_base = true)
    {
        if (!$this->containerExists($container) || !$this->blobExists($container, $path)) {
            throw new NotFoundException("File '$path' does not exist in storage.");
        }
        if (!empty($local_file)) {
            // write to local or temp file
            $this->getBlobAsFile($container, $path, $local_file);

            return '';
        } else {
            // get content as raw or encoded as base64 for transport
            $data = $this->getBlobData($container, $path);
            if ($content_as_base) {
                $data = base64_encode($data);
            }

            return $data;
        }
    }
343738
function saveContentToEntitlementsFile(content) {
  var plistContent = plist.build(content);
  var filePath = pathToEntitlementsFile();

  // ensure that file exists
  mkpath.sync(path.dirname(filePath));

  // save it's content
  fs.writeFileSync(filePath, plistContent, 'utf8');
}
211449
function getNewContent(target, collection, opt) {
  var logger = opt.quiet ? noop : function (filesCount) {
    if (filesCount) {
      var pluralState = filesCount > 1 ? 's' : '';
      log(cyan(filesCount) + ' file' + pluralState + ' into ' + magenta(target.relative) + '.');
    } else {
      log('Nothing to inject into ' + magenta(target.relative) + '.');
    }
  };
  var content = String(target.contents);
  var targetExt = extname(target.path);
  var files = prepareFiles(collection, targetExt, opt, target);
  var filesPerTags = groupArray(files, 'tagKey');
  var startAndEndTags = Object.keys(filesPerTags);
  var matches = [];
  var injectedFilesCount = 0;

  startAndEndTags.forEach(function (tagKey) {
    var files = filesPerTags[tagKey];
    var startTag = files[0].startTag;
    var endTag = files[0].endTag;
    var tagsToInject = getTagsToInject(files, target, opt);
    content = inject(content, {
      startTag: startTag,
      endTag: endTag,
      tagsToInject: tagsToInject,
      removeTags: opt.removeTags,
      empty: opt.empty,
      willInject: function (filesToInject) {
        injectedFilesCount += filesToInject.length;
      },
      onMatch: function (match) {
        matches.push(match[0]);
      }
    });
  });

  logger(injectedFilesCount);

  if (opt.empty) {
    var ext = '{{ANY}}';
    var startTag = getTagRegExp(opt.tags.start(targetExt, ext, opt.starttag), ext, opt);
    var endTag = getTagRegExp(opt.tags.end(targetExt, ext, opt.endtag), ext, opt);

    content = inject(content, {
      startTag: startTag,
      endTag: endTag,
      tagsToInject: [],
      removeTags: opt.removeTags,
      empty: opt.empty,
      shouldAbort: function (match) {
        return matches.indexOf(match[0]) !== -1;
      }
    });
  }

  return Buffer.from(content);
}
647530
function dirtyFileSaveCancelled() {
        UpdateInfoBar.showUpdateBar({
            type: "warning",
            title: Strings.WARNING_TYPE,
            description: Strings.UPDATE_ON_NEXT_LAUNCH
        });
    }
432880
function envFileContent(cmdOptions) {
  var filePath, envFiles;
  var fileContent = '';
  if (cmdOptions.env) {
    envFiles = cmdOptions.env.split(',');
    for (var i = 0; i < envFiles.length; i++ ) {
      filePath = path.normalize(envFiles[i]);
      if (fs.existsSync(filePath)) {
	fileContent += fs.readFileSync(filePath, 'utf8');
	fileContent += "\n";
      }
    }
  } else if (fs.existsSync(parser.cmdWorkingDir(cmdOptions) + '/.env')) {
    filePath = parser.cmdWorkingDir(cmdOptions) + '/.env';
    fileContent = fs.readFileSync(filePath, 'utf8');
  }

  return fileContent;
}
1223853
def FetchFileContent(self):
    
    if not self.state.pending_files:
      return

    # Check what blobs we already have in the blob store.
    blob_hashes = []
    for file_tracker in itervalues(self.state.pending_files):
      for hash_response in file_tracker.get("hash_list", []):
        blob_hashes.append(rdf_objects.BlobID.FromBytes(hash_response.data))

    # This is effectively a BlobStore call.
    existing_blobs = data_store.BLOBS.CheckBlobsExist(blob_hashes)

    self.state.blob_hashes_pending = 0

    # If we encounter hashes that we already have, we will update
    # self.state.pending_files right away so we can't use an iterator here.
    for index, file_tracker in list(self.state.pending_files.items()):
      for i, hash_response in enumerate(file_tracker.get("hash_list", [])):
        # Make sure we read the correct pathspec on the client.
        hash_response.pathspec = file_tracker["stat_entry"].pathspec

        if existing_blobs[rdf_objects.BlobID.FromBytes(hash_response.data)]:
          # If we have the data we may call our state directly.
          self.CallStateInline(
              messages=[hash_response],
              next_state="WriteBuffer",
              request_data=dict(index=index, blob_index=i))
        else:
          # We dont have this blob - ask the client to transmit it.
          self.CallClient(
              server_stubs.TransferBuffer,
              hash_response,
              next_state="WriteBuffer",
              request_data=dict(index=index, blob_index=i))
915679
def cache_file(self, template):
        '''
        
        '''
        saltpath = salt.utils.url.create(template)
        self.file_client().get_file(saltpath, '', True, self.saltenv)
1153914
function loadIconsFromDiskCache (loader, query, cacheFile, fileHash, callback) {
  // Stop if cache is disabled
  if (!query.persistentCache) return callback(null);
  var resolvedCacheFile = path.resolve(loader._compiler.parentCompilation.compiler.outputPath, cacheFile);

  fs.exists(resolvedCacheFile, function (exists) {
    if (!exists) return callback(null);
    fs.readFile(resolvedCacheFile, function (err, content) {
      if (err) return callback(err);
      var cache;
      try {
        cache = JSON.parse(content);
        // Bail out if the file or the option changed
        if (!isCacheValid(cache, fileHash, query)) {
          return callback(null);
        }
      } catch (e) {
        return callback(e);
      }
      callback(null, cache.result);
    });
  });
}
316184
function loadFileContents(filePath, preloaded)
{
    //use pre-supplied contents?
    if (typeof preloaded !== 'undefined' && preloaded !== null)
    {
        //return a promise which will get resolved with the preloaded value
        if (preloaded instanceof Buffer)
        {
            return promiseValue(preloaded.toString());
        }
        else
        {
            return promiseValue(String(preloaded));
        }
    }
    else
    {
        return Q.nfcall(fs.readFile, filePath).invoke('toString');
    }
}