I’ve found combining serialization and compression with CodecZstd to be reasonably efficacious for saving large arbitrary data structures:
using Revise, CodecZstd, Serialization
function OUT_BIN_STREAM(p::String, obj; level=1)
io = ZstdCompressorStream(open(p, "w"), level=level)
try
serialize(io, obj)
finally
close(io)
end
end
function IN_BIN_STREAM(p::String)
local obj
open(ZstdDecompressorStream, p) do io
obj = deserialize(io)
end
return obj
end
obj = [rand(2,3), rand(1:4, 3)]
OUT_BIN_STREAM("test.jls",obj)
objin = IN_BIN_STREAM("test.jls")
println(objin)
However, I think its allowed for future versions of Julia to break the format, so its only future proof if in the future you have access to older versions of Julia (which are fortunately available).
You can try JDF.jl but I am planning a big update for v0.3.
I am trying write a parquet writer so that may be another avenue. I found Feather.jl to be quite good for most cases but there is feather v2 format coming out and I am not sure if Feather.jl supports it. But the old feather format can be read by all feather readers as Wes McKinney has promised.
If you are concerned about reading it back in a decade or so, write a simple conversion routine that saves it into a format composed purely of primitives (numbers, keys, strings, etc), and dump it into something simple, eg JSON.
The fundamental problem faced by all solutions that try to translate from and to native Julia types is that Julia’s types can be incredibly complex.
In R you have the nice dput command that saves you objects as R code, which you later just have to evaluate. Really useful for stackoverflow questions . Is there something similar in Julia?
Note that the data types in R are much, much simpler than Julia. Basically vectors (of booleans, integers, floats, complex numbers, characters), with some added metadata as key-value pairs. No user-defined types, no type parameters; not even scalars, just 1-element vectors.