tamagohan2
tamagohan2

Reputation: 445

How to write to gzip file from elixir code

I would like to write gzip file from elixir code.

I tried to following code, but it doesn't work well.

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

IO.write returns :ok, but, /path/to/file.gzip is empty.

How can I write to gzip file?

Upvotes: 4

Views: 1251

Answers (2)

Kabie
Kabie

Reputation: 10663

You can also do whole thing in one step:

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

Upvotes: 8

Steve Vinoski
Steve Vinoski

Reputation: 20024

You need one more step: close the file so that any buffered data gets written:

File.close io_device

Upvotes: 6

Related Questions