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
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
The pieces are almost all there:
- you can create an IO descriptor for an in-memory file with the
:ramoption 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
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
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).
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









