Simplify S3.open_file with "with" form

master
Marcin Kulik 7 years ago
parent 8c9e9f4c03
commit a96e8518bc

@ -38,8 +38,7 @@ defmodule Asciinema.FileStore.S3 do
def open_file(path, function \\ nil) do
response = bucket() |> S3.get_object(base_path() <> path) |> make_request
case response do
{:ok, %{headers: headers, body: body}} ->
with {:ok, %{headers: headers, body: body}} <- response do
body =
case List.keyfind(headers, "Content-Encoding", 0) do
{"Content-Encoding", "gzip"} -> :zlib.gunzip(body)
@ -51,8 +50,6 @@ defmodule Asciinema.FileStore.S3 do
else
File.open(body, [:ram, :binary, :read])
end
{:error, reason} ->
{:error, reason}
end
end

Loading…
Cancel
Save