def read(self, key, path, image=False):
        if self.is_packed_file(path):
            key = key.lower()
            db = starbound.open_file(path)

            # try the cache first
            if image and key in self.image_cache:
                return self.image_cache[key]

            try:
                data = db.get(key)
            except KeyError:
                if image and path != self.vanilla_assets:
                    img = self.read(key, self.vanilla_assets, image)
                    self.image_cache[key] = img
                    return img
                else:
                    logging.exception("Unable to read db asset '%s' from '%s'" % (key, path))
                    return None
            if image:
                img = data
                self.image_cache[key] = img
                return img
            else:
                try:
                    asset = parse_json(data.decode("utf-8"), key)
                    return asset
                except ValueError:
                    logging.exception("Unable to read db asset '%s' from '%s'" % (key, path))
                    return None
        else:
            asset_file = os.path.join(path, key[1:])
            try:
                if image:
                    img = open(asset_file, "rb").read()
                    self.image_cache[key] = img
                    return img
                else:
                    asset = load_asset_file(asset_file)
                    return asset
            except (FileNotFoundError, ValueError):
                if image and path != self.vanilla_assets:
                    if self.is_packed_file(self.vanilla_assets):
                        img = self.read(key.replace("\\", "/"), self.vanilla_assets, image)
                        self.image_cache[key] = img
                        return img
                    else:
                        img = self.read(key, self.vanilla_assets, image)
                        self.image_cache[key] = img
                        return img
                else:
                    logging.exception("Unable to read asset file '%s' from '%s'" % (key, path))
                    return None
dataset/ETHPy150Open wizzomafizzo/starcheat/starcheat/assets/core.py/Assets.read/original