Loads a specified file and returns Hash including the given key.
435986
def load_file(path, key_word)
      begin
        data = MultiJson.load(IO.read(File.expand_path(path)), symbolize_keys: true)
      rescue RuntimeError, Errno::ENOENT => e
        raise e.message
      rescue MultiJson::LoadError => e
        raise e.message
      end
        if data.has_key?(key_word)
        data[key_word].map { |k,v| data[key_word][k] = v } if data[key_word].is_a? Hash
      end
      data
    end
150547
def [](key)
      file = filename key
      return unless File.exist? file

      File.read(file, encoding: "utf-8")
    end
361255
function loadFromIndividualConfigFile(key) {
    key = _.replace(key, /\/|\\/g, ''); //forward and backslashes are unsafe when resolving filenames

    if (individualKeyCache[key]) {
        return individualKeyCache[key];
    } else {
        var toLoad = path.resolve(global.__appDir, 'config/' + key + '.json');

        var content = '{}';
        try {
            content = fs.readFileSync(toLoad);
        } catch (err) {
            //file must not exists
        }

        var json = {};
        try {
            json = JSON.parse(stripJsonComments(content.toString()));
        } catch (err) {
            console.warn('Error parsing JSON for %s', toLoad);
        }

        security.decryptObject(json, function (str) {
            //Decryption function
            return security.decrypt(str, process.env.decryptionKey);
        });
        individualKeyCache[key] = json;

        return individualKeyCache[key];
    }
}
368407
@Override
    public byte[] get(String key) {
        File f = new File(directory, hash(key));
        FileInputStream fi = null;
        byte[] data = null;
        int read = 0;
        try {
            if (outOfDate(f)) {
                f.delete();
                return null;
            }
            data = new byte[(int) f.length()];
            fi = new FileInputStream(f);
            read = fi.read(data);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (fi != null) {
            try {
                fi.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (read == 0) {
            return null;
        }
        return data;
    }
813883
def hash(filename):
    ''''''
    buffer_size = 10*1024*1024
    m = hashlib.md5()
    with open(filename) as f:
        buff = f.read(buffer_size)
        while len(buff)>0:
            m.update(buff)
            buff = f.read(buffer_size)
    dig = m.digest()
    return ''.join(['%x' % ord(x) for x in dig])
206753
def get_hash(fName, readSize, dire=pDir()):
    
    if not fileExists(fName, dire):
        return -1
    readSize = readSize * 1024 # bytes to be read
    fName = os.path.join(dire, fName) # name coupled with path
    with open(fName, 'rb') as f:
        size = os.path.getsize(fName)
        if size < readSize * 2:
            return -1
        data = f.read(readSize)
        f.seek(-readSize, os.SEEK_END)
        data += f.read(readSize)
    return md5(data).hexdigest()
1068452
def load(cls,filename):
        """"""
        filename = cls.correct_file_extension(filename)
        with open(filename,'rb') as f:
            return pickle.load(f)
1349155
def get(type, hash)
      dir = directory(type, hash)
      return unless dir
      dir.files.get(key_component(type, hash))
    end
754507
def load_hashes(filename):
    """"""
    # { filename : (sha1 of header if available or 'NA',
    #               sha1 of input,
    #               sha1 of output) }

    hashes = {}
    try:
        with open(filename, 'r') as cython_hash_file:
            for hash_record in cython_hash_file:
                (filename, header_hash,
                 cython_hash, gen_file_hash) = hash_record.split()
                hashes[filename] = (header_hash, cython_hash, gen_file_hash)
    except (KeyError, ValueError, AttributeError, IOError):
        hashes = {}
    return hashes
502532
def load(cls, directory):
    
    read_file = maybe_read_file(cls._path(directory))
    if read_file:
      fingerprint, length = read_file.split(':')
      return Digest(fingerprint, int(length))
    else:
      return None
180324
def file_hash(load, fnd):
    '''
    
    '''
    path = fnd['path']
    ret = {}

    if 'env' in load:
        # "env" is not supported; Use "saltenv".
        load.pop('env')

    if load['saltenv'] not in envs():
        return {}

    # if the file doesn't exist, we can't get a hash
    if not path or not os.path.isfile(path):
        return ret

    # set the hash_type as it is determined by config-- so mechanism won't change that
    ret['hash_type'] = __opts__['hash_type']

    # check if the hash is cached
    # cache file's contents should be "hash:mtime"
    cache_path = os.path.join(
        __opts__['cachedir'],
        'minionfs',
        'hash',
        load['saltenv'],
        '{0}.hash.{1}'.format(fnd['rel'], __opts__['hash_type'])
    )
    # if we have a cache, serve that if the mtime hasn't changed
    if os.path.exists(cache_path):
        try:
            with salt.utils.files.fopen(cache_path, 'rb') as fp_:
                try:
                    hsum, mtime = salt.utils.stringutils.to_unicode(fp_.read()).split(':')
                except ValueError:
                    log.debug(
                        'Fileserver attempted to read incomplete cache file. '
                        'Retrying.'
                    )
                    file_hash(load, fnd)
                    return ret
                if os.path.getmtime(path) == mtime:
                    # check if mtime changed
                    ret['hsum'] = hsum
                    return ret
        # Can't use Python select() because we need Windows support
        except os.error:
            log.debug(
                'Fileserver encountered lock when reading cache file. '
                'Retrying.'
            )
            file_hash(load, fnd)
            return ret

    # if we don't have a cache entry-- lets make one
    ret['hsum'] = salt.utils.hashutils.get_hash(path, __opts__['hash_type'])
    cache_dir = os.path.dirname(cache_path)
    # make cache directory if it doesn't exist
    if not os.path.exists(cache_dir):
        os.makedirs(cache_dir)
    # save the cache object "hash:mtime"
    cache_object = '{0}:{1}'.format(ret['hsum'], os.path.getmtime(path))
    with salt.utils.files.flopen(cache_path, 'w') as fp_:
        fp_.write(cache_object)
    return ret
919935
def read_and_hash(fname, **kw):
    '''
    
    '''
    return [addhash(frame, **kw) for frame in read(fname, **kw)];
1320331
def file(filename):
        
        m = hashlib.md5()
        with open(filename, 'rb') as f:
            m.update(f.read())
            result = m.hexdigest()
            return result
1271036
def _hash_of_file(path, algorithm):
    """"""
    with open(path, 'rb') as archive:
        hash = hashlib.new(algorithm)
        for chunk in read_chunks(archive):
            hash.update(chunk)
    return hash.hexdigest()
692229
def load(element_key)
      parameter = { basic_auth: @auth }
      response = self.class.get("/elements/#{element_key}/files", parameter)
      parse_files(response['FileInfos']) if response.success?
    end
306749
def __load_file(self, key_list) -> str:
        
        file = str(key_list[0]) + self.extension
        key_list.pop(0)
        file_path = os.path.join(self.path, file)
        if os.path.exists(file_path):
            return Json.from_file(file_path)
        else:
            raise FileNotFoundError(file_path)
1205507
def load(key, options = {})
      if options[:sync] || (value = @cache.load(key, options)) == nil
        value = @adapter.load(key, options)
        @cache.store(key, value, options) if value != nil
      end
      value
    end