View Source ExIpfs (Elixir IPFS v0.1.7)
Core commands and types for ExIpfs. In order for this module to work you need to have an IPFS daemon running. See README.md for details.
## Examples
iex> alias ExIpfs, as: Ipfs
iex> Ipfs.cat("QmZ4tDuvesekSs4qM5ZBKpXiZGun7S2CYtEZRB3DYXkjGx")
<<0, 19, 148, 0, ... >>
Summary
Types
A struct that represents the result of adding a file to IPFS.
A struct for the ID returned by the id command.
This struct is very simple. Some results are listed as "Value": size. This is a convenience struct to make it easier match on the result.
A struct for the links of a DAG in IPLD. When IPLD sees such a Key Value in the JSON result it will lookup the data.
ExIpfs.MultibaseCodec is a struct representing a hash. Seems much like a codec structure to me, but hey. Things may differ.
A Multihash.
An object in IPFS with a hash and links to other objects.
B58 encoded peer ID.
Functions
Add a file to IPFS.
Add a file to IPFS.
Get the contents of a file from ipfs. Easy way to get the contents of a text file for instance.
Get a file or directory from IPFS.
Show the id of the IPFS node.
List directory contents for Unix filesystem objects in IPFS.
Ping a peer in the IPFS network.
Resolve the value of names to IPFS.
Types
@type add_result() :: %ExIpfs.AddResult{ bytes: non_neg_integer(), hash: binary(), name: binary(), size: non_neg_integer() }
A struct that represents the result of adding a file to IPFS.
@type id() :: %ExIpfs.Id{ addresses: list(), agent_version: String.t(), id: String.t(), protocols: list(), public_key: String.t() }
A struct for the ID returned by the id command.
This struct is very simple. Some results are listed as "Value": size. This is a convenience struct to make it easier match on the result.
@type link() :: %ExIpfs.Link{/: binary()}
A struct for the links of a DAG in IPLD. When IPLD sees such a Key Value in the JSON result it will lookup the data.
@type multi_codec() :: %ExIpfs.Multicodec{code: non_neg_integer(), name: binary()}
ExIpfs.MultibaseCodec is a struct representing a hash. Seems much like a codec structure to me, but hey. Things may differ.
@type multi_hash() :: %ExIpfs.Multihash{code: non_neg_integer(), name: binary()}
A Multihash.
An object in IPFS with a hash and links to other objects.
@type peer_id() :: <<_::48, _::_*8>>
B58 encoded peer ID.
Functions
@spec add(any(), list()) :: {:ok, add_result()} | ExIpfs.Api.error_response()
Add a file to IPFS.
Parameters
data
- The data to be sent to the IPFS node.
Options
@spec add_fspath(Path.t(), list()) :: add_result() | ExIpfs.Api.error_response()
Add a file to IPFS.
https://docs.ipfs.tech/reference/kubo/rpc/#api-v0-add
Parameters
fspath
- The file system path to the file or directory to be sent to the node.
Options
Only options deemed relevant are listed here. See the link above for the full list.
[
chunker: "size-262144", # Chunking algorithm, size-[bytes], rabin-[min]-[avg]-[max] or buzhash
cid-version: 0, # Defaults to 0 unless an option that depends on CIDv1 is passed. Passing version 1 will cause the raw-leaves option to default to true.
fscache: true, # Check the filestore for pre-existing blocks. (experimental)
hash: "sha2-256", # Hash function to use. Implies CIDv1 if not sha2-256. (experimental)
inline-limit: 32, # Maximum block size to inline. (experimental)
inline: false, # Inline small blocks into CIDs. (experimental).
only-hash: false, # Only chunk and hash - do not write to disk.
pin: true, # Pin locally to protect added files from garbage collection.
raw-leaves: false, # Use raw blocks for leaf nodes. (experimental)
to-files: <<>>, # Add reference to Files API (MFS) at the provided path.
trickle: false, # Use trickle-dag format for dag generation.
wrap-with-directory: false, # Wrap files with a directory object.
@spec cat(Path.t(), list()) :: {:ok, any()} | ExIpfs.Api.error_response()
Get the contents of a file from ipfs. Easy way to get the contents of a text file for instance.
Options
https://docs.ipfs.tech/reference/kubo/rpc/#api-v0-cat
[
offset: <int64>,
length: <int64>,
progress: <bool>
]
@spec get(Path.t(), list()) :: {:ok, Path.t()} | ExIpfs.Api.error_response()
Get a file or directory from IPFS.
NB! Unsafe (relative symlinks) will raise an error. This is a limitation of the underlying library.
Options
https://docs.ipfs.tech/reference/kubo/rpc/#api-v0-get
[
output: <string>, # Output to file or directory name. Optional, default: <cid-ipfs-or-ipns-path>
archive: <bool>, # Output as a tarball. Optional, default: false
timeout: <int64>, # Timeout in seconds. Optional, default: 100
]
Compression is not implemented.
If you feel that you need more timeouts, you can use the :timeout
option in the opts
list.
But the default should be enough for most cases. More likely your content isn't available....
@spec id() :: {:ok, id()} | ExIpfs.Api.error_response()
Show the id of the IPFS node.
https://docs.ipfs.tech/reference/kubo/rpc/#api-v0-id Returns a map with the following keys:
- ID: the id of the node.
- PublicKey: the public key of the node.
- Addresses: the addresses of the node.
- AgentVersion: the version of the node.
- Protocols: the protocols of the node.
@spec ls(Path.t(), list()) :: {:ok, [object()]} | ExIpfs.Api.error_response()
List directory contents for Unix filesystem objects in IPFS.
Options
https://docs.ipfs.tech/reference/kubo/rpc/#api-v0-ls
[
headers: <bool>, # Print table headers (Hash, Size, Name). Optional, default: false
resolve-type: <bool>, # Resolve linked objects to find out their types. Optional, default: false
timeout: <int64>, # Timeout in seconds. Optional, default: 100
]
Streaming is not supported yet, but might be in there future. Post a feature request if you need it.
@spec ping(peer_id(), pid(), atom() | integer(), list()) :: :ignore | {:error, any()} | {:ok, pid()}
Ping a peer in the IPFS network.
@spec resolve(Path.t(), list()) :: {:ok, Path.t()} | ExIpfs.Api.error_response()
Resolve the value of names to IPFS.
https://docs.ipfs.tech/reference/kubo/rpc/#api-v0-resolve
Options
[
recursive: true,
nocache: true,
dht-record-count: 10,
dht-timeout: 10
]