PabloG6

PabloG6

Is there a way to create a tar file in memory in elixir?

Is there a way to create a tar file in memory in elixir?

Marked As Solved

eksperimental

eksperimental

Hi, I use GitHub - marianoguerra/efe: Elixir Flavoured Erlang: an Erlang to Elixir Transpiler · GitHub which is really super cool tool (I give credits both in the README and the top of the .ex file)

It required a bit of tweaking, but it worked.

The library (Tar) is a 100% port of :erl_tar. TarOpen is just the minimum working version to offer the patched open/2.

Also Liked

al2o3cr

al2o3cr

The pieces are almost all there:

  • you can create an IO descriptor for an in-memory file with the :ram option for :file.open/2
  • you can pass an IO descriptor to :erl_tar.open/2

so you might think this would work:

{:ok, fd} = :file.open("", [:read, :write, :ram])
{:ok, tar_desc} = :erl_tar.open({:file, fd}, [:write])

but this fails with an argument error:

** (FunctionClauseError) no function clause matching in :erl_tar.open1/4    
    
    The following arguments were given to :erl_tar.open1/4:
    
        # 1
        {:file, {:file_descriptor, :ram_file, #Port<0.7>}}
    
        # 2
        :write
    
        # 3
        [:raw]
    
        # 4
        []
    
    (stdlib 3.15.2) erl_tar.erl:324: :erl_tar.open1/4
al2o3cr

al2o3cr

FWIW, you are almost certainly going to get better performance with doing file-based operations against something like tmpfs (versus bending a ram_file to your will); depending on how many times ram_file needs to resize its internal binary it could get very expensive…

AndrewDryga

AndrewDryga

I would simply use tmpfs as mentioned earlier, you can mount it pretty much anywhere, it will give good IO performance and won’t require patching Erlang (and then running on your own build for a while, while it gets to the released version).

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&amp;query=perfume&amp;page=2, I would like to get: ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: &lt;h1&gt;Create Post&lt;/h1&gt; &lt;%= ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New

Other popular topics Top

WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
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
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31013 112
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement