In the following code I created a “erlang file” with 10 lists. I tried to read the lists back and but I got only the last list.
import :erlang, only: [binary_to_term: 1, term_to_binary: 1]
path = "/home/x/y"
# I write ,for example, 10 lists into a file.
for a_map <- results do
# 10 lists made
bin = :erlang.term_to_binary(a_list)
File.write!(path,bin)
end
# Now I want to read the lists back.
# The following code shows only the last list:
for a_map <- results do
File.read!(path) |> :erlang.binary_to_term
end
I shall try it but I am a little bit afraid because I have 3000 “list records” .
It should be something like: my_single_list = [ [list1], [list2],…[list3000] ] ?
bin = :erlang.term_to_binary(my_single_list)
File.write!(path,bin)
Thanks for your suggestion. I am learning to use the erlang stuf in my elixir program, so I am not familiar with it. Nobbz gave me a suggestion which I shall try.
Of course you cal also use File.open, IO.binwrite and IO.binread to write and read a stream of binary terms, but that might be harder to read in, as you need to do the chunking manually.