예제 #1
0
 def pin_assets(self, file_or_dir_path: Path) -> List[Dict[str, str]]:
     """
     Return a dict containing the IPFS hash, file name, and size of a file.
     """
     if file_or_dir_path.is_dir():
         asset_data = [dummy_ipfs_pin(path) for path in file_or_dir_path.glob("*")]
     elif file_or_dir_path.is_file():
         asset_data = [dummy_ipfs_pin(file_or_dir_path)]
     else:
         raise FileNotFoundError(
             f"{file_or_dir_path} is not a valid file or directory path."
         )
     return asset_data
예제 #2
0
 def pin_assets(self, file_or_dir_path: Path) -> List:
     """
     Return a dict containing the IPFS hash, file name, and size of a file.
     """
     if file_or_dir_path.is_dir():
         for path in file_or_dir_path.glob("*"):
             with path.open() as fp:
                 self._assets[path.name] = fp.read()
         asset_data = [dummy_ipfs_pin(path) for path in file_or_dir_path.glob("*")]
     elif file_or_dir_path.is_file():
         asset_data = [dummy_ipfs_pin(file_or_dir_path)]
         with file_or_dir_path.open() as fp:
             self._assets[file_or_dir_path.name] = fp.read()
         self._assets[asset_data[0]["Hash"]] = self._assets[file_or_dir_path.name]
     else:
         raise FileNotFoundError(f"{file_or_dir_path} is not a valid file or directory path.")
     return asset_data