JLD.jl icon indicating copy to clipboard operation
JLD.jl copied to clipboard

save("file.jld", "foo", foo) overwrites contents of file

Open sivark opened this issue 8 years ago • 5 comments

It seems like the file is opened in "w" mode and thereby other variables saved in the same file are lost. Is there any reason why this is preferable to appending data to a file? (I notice that the FileIO.jl package has a similar setting)

I feel that appending would be least surprising for the user.

sivark avatar Sep 07 '16 04:09 sivark

Yep, same opinion. Can it be possible to only write or modify one field on the Dictionary of the file? Maybe using jldopen("somefile.jld")?

kzapfe avatar Nov 09 '16 03:11 kzapfe

Yeah, this tripped me up for a couple hours. In fact, is there any way to append to an existing JLD file at all (even if it's not the default behavior in "w" mode)?

crbinz avatar Nov 16 '16 17:11 crbinz

"r+"

timholy avatar Nov 20 '16 21:11 timholy

One issue is that the save function is generic and operates not only on JLD files, which support appending data, but also on many other file types that don't support append, so making append mode the default would not lead to consistent generic behavior.

StefanKarpinski avatar Nov 21 '16 16:11 StefanKarpinski

I see. In such a case, could the method(s) be more appropriately named save!() ? This would make explicit the potential for overwriting the data.

sivark avatar Nov 21 '16 18:11 sivark