How to write to gzip file from elixir code

I would like to write a gzip file from elixir code.

I tried to execute the following code, but it does not work.

io_device = File.open!("/path/to/file.gzip", [:write, :compressed])
IO.write(io_device, "test")

IO.writereturns :okbut /path/to/file.gzipempty.

How can I write to a gzip file?

+4
source share
2 answers

You will need one more step: close the file to write any buffered data:

File.close io_device
+5
source

You can also do the whole thing in one step:

File.write "/path/to/file.gzip", "test", [:compressed]
+7
source

Source: https://habr.com/ru/post/1615505/


All Articles