Skip to content

Instantly share code, notes, and snippets.

@jsonkenl
Created December 6, 2016 18:25
Show Gist options
  • Save jsonkenl/ae892175f7e165eed585bbe6dd6d8aaf to your computer and use it in GitHub Desktop.
Save jsonkenl/ae892175f7e165eed585bbe6dd6d8aaf to your computer and use it in GitHub Desktop.
def multi_extract(path, index \\ nil, timer \\ false) do
case is_nil(index) do
true ->
case Unzip.validate_path_all_indexes(path) do
{:ok, indexes} ->
{pids, times} = Enum.reduce(indexes, {[], []}, fn index, {pids, times} ->
case multi_extract(path, index, timer) do
{:ok, pid, time} -> {pids ++ [pid], times ++ [time]}
{:ok, pid} -> {pids ++ [pid], times}
{:error, reason} -> {pids ++ [{:error, reason}], times}
end
end)
if times == [], do: {:ok, pids}, else: {:ok, pids, times}
{:error, reason} -> {:error, reason}
end
false ->
if timer, do: Timer.start
case Unzip.validate_path_and_index(path, index) do
{:ok, file} -> Unzip.xml_file_list(index)
|> Unzip.extract_xml_to_file(file)
|> case do
{:ok, file_paths} -> do_multi_extract(file_paths, index, timer)
{:error, reason} -> {:error, reason}
end
{:error, reason} -> {:error, reason}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment