fireproofsocks

fireproofsocks

Adding a file to an existing zip

Hoping to tap into the community for some advice. Is there a way to add a file to an existing zip archive?

This seems like maybe it’s not supported by the Erlang :zip module:

Changing a zip archive is not supported. To add or remove a file from an archive, the whole archive must be recreated.

But maybe someone knows of another library or other algorithm (bzip, gzip, ?) that might support this more easily.

It’s relevant that these zip files may be stored in S3, so maybe it would be ok to do this via a Lamba (looks like maybe this article is poking at that idea Zip files from Amazon S3 without saving them locally | tech, life & music.)

Thanks for any ideas!

Marked As Solved

adamu

adamu

You could resort to calling zip in a separate process:

iex(1)> for file <- ["foo", "bar", "baz"], do: File.write(file, file)
[:ok, :ok, :ok]
iex(2)> System.cmd("zip", ["zipped.zip", "foo", "bar", "baz"])
{"  adding: foo (stored 0%)\n  adding: bar (stored 0%)\n  adding: baz (stored 0%)\n",
 0}
iex(3)> File.write("extra_file", "some more stuff")
:ok
iex(4)> System.cmd("zip", ["zipped.zip", "extra_file"])
{"  adding: extra_file (stored 0%)\n", 0}
iex(5)>
BREAK: (a)bort (A)bort with dump (c)ontinue (p)roc info (i)nfo
       (l)oaded (v)ersion (k)ill (D)b-tables (d)istribution
^C~ $ mkdir example
~ $ mv zipped.zip example/
~ $ cd example/
~/example $ unzip zipped.zip
Archive:  zipped.zip
 extracting: foo
 extracting: bar
 extracting: baz
 extracting: extra_file

Also Liked

LostKobrakai

LostKobrakai

I guess this stems from expecting a filesystem, but S3 is not a filesystem. It‘s a database for files. You wouldn‘t try to zip up files in e.g. postgres.

Where Next?

Popular in Questions Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
Kagamiiiii
Student &amp; New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement