def objects_to_root(objects: List) -> Root:
    def _to_tree(objs: Iterable) -> Dict:
        path_tree = {}
        for obj in objs:
            is_dir = obj.key.endswith('/')
            chunks = [chunk for chunk in obj.key.split('/') if chunk]
            chunk_count = len(chunks)
            tmp = path_tree
            for i, chunk in enumerate(chunks):
                is_last_chunk = i == chunk_count - 1
                if is_last_chunk and not is_dir:
                    tmp[chunk] = obj
                else:
                    if chunk not in tmp:
                        tmp[chunk] = {}
                    tmp = tmp[chunk]
        return path_tree
    def _to_entity(key: str, value: Union[Dict, Any]) -> Entity:
        if isinstance(value, dict):
            return Directory(
                key,
                {key_: _to_entity(key_, value_)
                 for key_, value_ in value.items()})
        return File(pathlib.PurePath(value.key).name, value.size,
                    value.e_tag.strip('"'))
    tree = _to_tree(objects)
    return Root({pathlib.PurePath(key).name: _to_entity(key, value)
                 for key, value in tree.items()})