View Source MyspaceIPFS (Myspace IPFS v0.2.0-alpha.2)
MyspaceIPFS is where the main commands of the IPFS API reside. Alias this library and you can run the commands via Api.<cmd_name>.
## Examples
iex> alias MyspaceIPFS, as: Ipfs
iex> Ipfs.cat(QmZ4tDuvesekSs4qM5ZBKpXiZGun7S2CYtEZRB3DYXkjGx")
<<0, 19, 148, 0, ... >>
Link to this section Summary
Types
A struct that represents the result of adding a file to IPFS.
A struct for a hash in the hash links list in Objects.
A struct for the links of hash in Objects.
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.
MyspaceIPFS.MultibaseCodec is a struct representing a hash. Seems much like a codec structure to me, but hey. Things may differ.
A multihash.
A struct that represents the objects in IPFS.
B58 encoded peer ID.
A struct for list of peers in the network.
This struct is very simple. Some results are listed as %{"/": cid}
. This is a
convenience struct to make it easier match on the result.
A struct when IPFS API returns a list of strings.
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.
Start the IPFS daemon.
Get a file or directory from IPFS.
Show the id of the IPFS node.
List the files in an IPFS object.
Mount an IPFS read-only mountpoint.
Ping a peer.
Resolve the value of names to IPFS.
Shutdown the IPFS daemon.
Link to this section Types
@type add_result() :: %MyspaceIPFS.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 hash() :: %MyspaceIPFS.Hash{ hash: binary(), name: binary(), size: non_neg_integer(), target: binary(), type: non_neg_integer() }
A struct for a hash in the hash links list in Objects.
A struct for the links of hash in Objects.
@type id() :: %MyspaceIPFS.Id{ addresses: list(), agent_version: String.t(), id: String.t(), protocol_version: 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 multi_codec() :: %MyspaceIPFS.MultiCodec{ code: non_neg_integer(), name: binary() }
MyspaceIPFS.MultibaseCodec is a struct representing a hash. Seems much like a codec structure to me, but hey. Things may differ.
@type multi_hash() :: %MyspaceIPFS.MultiHash{code: non_neg_integer(), name: binary()}
A multihash.
@type objects() :: %MyspaceIPFS.Objects{objects: [hash_links()]}
A struct that represents the objects in IPFS.
@type peer_id() :: <<_::48, _::_*8>>
B58 encoded peer ID.
@type peers() :: %MyspaceIPFS.Peers{peers: list() | nil}
A struct for list of peers in the network.
@type slash_cid() :: %MyspaceIPFS.SlashCID{/: binary()}
This struct is very simple. Some results are listed as %{"/": cid}
. This is a
convenience struct to make it easier match on the result.
The name is odd, but it signifies that it is a CID of in the API notation, with the leading slash. It is used for the root of a tree.
@type strings() :: %MyspaceIPFS.Strings{strings: [binary()]}
A struct when IPFS API returns a list of strings.
Link to this section Functions
@spec add(any(), list()) :: {:ok, add_result()} | MyspaceIPFS.Api.error_response()
Add a file to IPFS.
parameters
Parameters
fspath
- The file system path to the file or directory to be sent to the node.
options
Options
@spec add_fspath(Path.t(), list()) :: {:ok, add_result()} | MyspaceIPFS.Api.error_response()
Add a file to IPFS.
parameters
Parameters
fspath
- The file system path to the file or directory to be sent to the node.
options
Options
@spec cat(Path.t(), list()) :: {:ok, any()} | MyspaceIPFS.Api.error_response()
Get the contents of a file from ipfs. Easy way to get the contents of a text file for instance.
options
Options
https://docs.ipfs.tech/reference/kubo/rpc/#api-v0-cat
[
offset: <int64>,
length: <int64>,
progress: <bool>
]
Start the IPFS daemon.
You should run this before any other command, but it's probably easier to do outside of the library.
The flag is the signal to send to the daemon process when shutting it down, ie. when start? is false.
The default is :normal
.
options
Options
https://docs.ipfs.tech/reference/kubo/cli/#ipfs-daemon
[
"--init", # <bool> Initialize IPFS with default settings, if not already initialized
"--migrate", # <bool> If answer yes to migration prompt
"--init-config <string>", # Path to the configuration file to use
"--init-profile <string>", # Apply profile settings to config
"--routing <string>", # Override the routing system
"--mount", # <bool> Mount IPFS to the filesystem (experimental)
"--writable", # <bool> Enable writing objects (with POST, PUT, DELETE)
"--mount-ipfs <string>", # Path to the mountpoint for IPFS (if using --mount)
"--mount-ipns <string>", # Path to the mountpoint for IPNS (if using --mount)
"--unrestricted-api", # <bool> Allow API access to unlisted hashes
"--disable-transport-encryption", # <bool> Disable transport encryption (for debugging)
"--enable-gc", # <bool> Enable automatic repo garbage collection
"--enable-pubsub-experiment", # <bool> Enable experimental pubsub
"--enable-namesys-pubsub", # <bool> Enable experimental namesys pubsub
"--agent-version-suffix <string>", # Suffix to append to the AgentVersion string for id()
]
@spec get(Path.t(), list()) :: {:ok, Path.t()} | MyspaceIPFS.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
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()} | MyspaceIPFS.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.
- ProtocolVersion: the protocol version of the node.
- Protocols: the protocols of the node.
@spec ls(Path.t(), list()) :: {:ok, objects()} | MyspaceIPFS.Api.error_response()
List the files in an IPFS object.
options
Options
https://docs.ipfs.tech/reference/kubo/rpc/#api-v0-ls
[
headers: <bool>,
resolve-type: <bool>,
stream: <bool>,
size: <bool>,
]
response
Response
{
Objects: [
{
"Name": "string",
"Hash": "string",
"Size": 0,
"Type": 0,
"Links": [
{
"Name": "string",
"Hash": "string",
"Size": 0,
"Type": 0
}
]
}
]
}
@spec mount(list()) :: {:ok, any()} | MyspaceIPFS.Api.error_response()
Mount an IPFS read-only mountpoint.
options
Options
https://docs.ipfs.tech/reference/kubo/rpc/#api-v0-mount
[
ipfs-path: <string>, # default: /ipfs
ipns-path: <string>, # default: /ipns
]
Ping a peer.
parameters
Parameters
- peer: the peer to ping.
options
Options
https://docs.ipfs.tech/reference/kubo/rpc/#api-v0-ping
[
n|count: <int>,
timeout: <int>,
]
@spec resolve(Path.t(), list()) :: {:ok, Path.t()} | MyspaceIPFS.Api.error_response()
Resolve the value of names to IPFS.
options
Options
https://docs.ipfs.tech/reference/kubo/rpc/#api-v0-resolve
[
recursive: true,
nocache: true,
dht-record-count: 10,
dht-timeout: 10
]
@spec shutdown() :: :ok
Shutdown the IPFS daemon.