Skip to content

aea.helpers.ipfs.base

This module contains helper methods and classes for the 'aea' package.

SHA256_ID

0x12

LEN_SHA256

0x20

chunks

def chunks(data: Sized, size: int) -> Generator

Yield successivesize chunks from data.

IPFSHashOnly Objects

class IPFSHashOnly()

A helper class which allows construction of an IPFS hash without interacting with an IPFS daemon.

get

@classmethod
def get(cls, file_path: str, wrap: bool = True, cid_v1: bool = True) -> str

Get the IPFS hash.

hash_file

@classmethod
def hash_file(cls,
              file_path: str,
              wrap: bool = True,
              cid_v1: bool = True) -> str

Get the IPFS hash for a single file.

Arguments:

  • file_path: the file path
  • wrap: whether to wrap the content in wrapper node or not
  • cid_v1: whether to use CID v1 hashes

Returns:

the ipfs hash

hash_bytes

@classmethod
def hash_bytes(cls,
               data: bytes,
               wrap: bool = True,
               cid_v1: bool = True,
               file_name_if_wrap: Optional[str] = None) -> str

Get the IPFS hash for a single file.

Arguments:

  • data: bytes
  • wrap: whether to wrap the content in wrapper node or not
  • cid_v1: whether to use CID v1 hashes
  • file_name_if_wrap: optional str with filename applied if wrap is True

Returns:

the ipfs hash

hash_directory

@classmethod
def hash_directory(cls,
                   dir_path: str,
                   wrap: bool = True,
                   cid_v1: bool = True) -> str

Get the IPFS hash for a directory.

Arguments:

  • dir_path: the directory path
  • wrap: whether to wrap the content in wrapper node or not
  • cid_v1: whether to use CID v1 hashes

Returns:

the ipfs hash

@staticmethod
def create_link(link_hash: bytes, tsize: int, name: str) -> Any

Create PBLink object.

wrap_in_a_node

@classmethod
def wrap_in_a_node(cls, link: Any) -> str

Wrap content in a wrapper node.