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 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).

jeroenbourgois

jeroenbourgois

Zip files would work, I don’t know for tar… Erlang has a zip package readily available:

 :zip.create(file_list, [{:cwd, path}, :memory])

See the docs. I see there is a tar module as well.

PabloG6

PabloG6

Thanks, i’ll look into it and see if i can submit a patch to get around this.

Where Next?

Popular in Questions Top

LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
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
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New

Other popular topics Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
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

We're in Beta

About us Mission Statement