I want to create a zip in particular location consider “/tmp/zip”.
I got two solutions for doing that,
1). One is changing File.cwd!/ to that specific folder and after creating the zip. Have to revert back to the old path
def create_zip(path) do
old_path = File.cwd!
File.cd! path
:zip.create("images.zip", ['images'], [{:cwd, path}])
File.cd! old_path
path<>"/images.zip"
end
I got above reference from here → Elixir: Export, Download, Zip, and Email | by Jebin | Medium
But, i think what happen if error occurs after changing the first File.cd!. I tried to simulate the scenario in my local. The whole project path was changing, so the next APIs are not working. And doing this in distributed system is right?
2). Create a zip file in current CWD then move the zip into required folder. In my case it “/tmp/zip/”. But, i was creating and moving the file to specific directory. Is it costly operation in the API? And also, creating the zip in current project directory instead of particular directory is correct approach?
Is there is any other way to create the zip in specific directory or which method can i follow from the above?