Current section
Files
Jump to
Current section
Files
lib/agent.ex
defmodule HashFS.Agent do
@moduledoc """
This is a simple agent which enables your application to access a single
instance of the store.
"""
defmacro __using__(opts) do
quote do
def start_link do
Agent.start_link(fn -> HashFS.new(Application.get_env(unquote(opts[:otp_app]), __MODULE__, :path), name: __MODULE__) end)
end
@doc "Stores a new file in this store"
def store(input, length) do
Agent.get(__MODULE__, fn fs ->
HashFS.store(fs, input, length)
end)
end
@doc "Check if the store has a value on the given address"
def has(hash) do
Agent.get(__MODULE__, fn fs -> HashFS.has(hash) end)
end
@doc "Retrieve the contents of the file at the given address"
def retrieve(hash) do
Agent.get(__MODULE__, fn fs -> HashFS.retrieve(hash) end)
end
end
end
end