     end
 
     defp write_file(raw, multihash) do
-      File.write(multihash, raw, [:write])
+      File.write(multihash, raw, [:write, :utf8])
     end
     
 end
defmodule IpfsConnection do
    defstruct host: "localhost", port: 5001, base: "api/v0", protocol: "http" 
    use Tesla
    
    @boundary "7MA4YWxkTrZu0gW"

    plug Tesla.Middleware.BaseUrl, "http://localhost:5001/api/v0"
    plug Tesla.Middleware.JSON


    def get_cmd(multihash) do
        res = requests("/get?arg=", multihash)
        res |> write_file(multihash)

        requests("/swarm/peers", "")
    end

    #Ls cmd Todo  Implement proper Json Format. 
    def ls_cmd(multihash) do
        res = requests("/ls?arg=", multihash)
        res
    end

    #Update function - Todo (correctly format res.body string)
    def update(args) do
        res = requests("/update?arg=", args)
        String.replace(res, "\n", " ")
    end



    defp build_url(conn, path) do
        "#{conn.protocol}://#{conn.host}:#{conn.port}/#{conn.base}/#{path}"
