FileStore.open -> FileStore.open_file

new-login
Marcin Kulik 7 years ago
parent 26ea613c36
commit ff7ed75c2b

@ -6,17 +6,17 @@ defmodule Asciinema.FileStore do
@callback serve_file(conn :: %Plug.Conn{}, path :: String.t, filename :: String.t) :: %Plug.Conn{}
@doc "Opens the given path in store"
@callback open(path :: String.t) :: {:ok, File.io_device} | {:error, File.posix}
@callback open_file(path :: String.t) :: {:ok, File.io_device} | {:error, File.posix}
@doc "Opens the given path in store, executes given fn and closes the file"
@callback open(path :: String.t, function :: (File.io_device -> res)) :: {:ok, res} | {:error, File.posix} when res: var
@callback open_file(path :: String.t, function :: (File.io_device -> res)) :: {:ok, res} | {:error, File.posix} when res: var
def put_file(dst_path, src_local_path, content_type) do
instance().put_file(dst_path, src_local_path, content_type)
end
def open_file(path, f) do
instance().open(path, f)
instance().open_file(path, f)
end
def download_file(store_path, local_path) do

@ -29,10 +29,10 @@ defmodule Asciinema.FileStore.Local do
|> halt
end
def open(path) do
def open_file(path) do
File.open(base_path() <> path, [:binary, :read])
end
def open(path, function) do
def open_file(path, function) do
File.open(base_path() <> path, [:binary, :read], function)
end

@ -25,7 +25,7 @@ defmodule Asciinema.FileStore.S3 do
|> redirect(external: url)
end
def open(path, function \\ nil) do
def open_file(path, function \\ nil) do
response = S3.get_object(bucket(), base_path() <> path) |> ExAws.request(region: region())
# TODO: use make_request

@ -65,7 +65,7 @@ defmodule Asciinema.PngGenerator.A2png do
Integer.to_string(png_params.scale)
]
{:ok, {:ok, _}} = file_store().open(path, &(:file.copy(&1, json_path)))
:ok = file_store().download_file(path, json_path)
process = Porcelain.spawn(bin_path(), args, err: :string)
case Porcelain.Process.await(process, @a2png_timeout) do

Loading…
Cancel
Save