       {:ok, {{_, 200, _}, _, body}} ->
         body
         |> IO.iodata_to_binary()
-        |> maybe_gunzip(filename)
-        |> maybe_untar(filename)
+        |> maybe_gunzip()
+        |> maybe_untar()
         |> MMDB2Decoder.parse_database()
 
       {:ok, {{_, status, _}, _, _}} ->

      {:ok, _} ->
        filename
        |> File.read!()
        |> maybe_gunzip(filename)
        |> maybe_untar(filename)
        |> MMDB2Decoder.parse_database()

      error ->

    end
  end

  defp maybe_untar(data) do
    case :erl_tar.extract({:binary, data}, [:memory]) do
      {:ok, files} -> find_mmdb_contents(files)
      {:error, _} -> data
    end
  end

  defp maybe_gunzip(data) do
    try do
      :zlib.gunzip(data)
    rescue
      _ -> data
    end
  end
end
