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

Replacing only some entries on the file

Open kzapfe opened this issue 7 years ago • 1 comments
trafficstars

Okey, this may not be an "issue" per se, but I do not seem to find here or anywhere else a practical way to replace the contents of only some entries on the datafile. As an example, if I do make something of this sort

arx=load(filename)

I get, let us say, a Dictionary with Entries "A", "B", and "C". So I make some calculations on "A", and then I have two options. If I do

jldopen(filename, "r+") do file
    write(file, "A", A)
end

Julia will complaint that "A" exists and cannot overwrite them. If I do

jldopen(filename, "w") do file
    write(file, "A", A)
end

Then I end with a new file that only stores "A". Of course I could rewrite everything, but If I have a large dictionary, seems impractical (and problematic if I miss something out).

Grettings and thanks in Advance K:

kzapfe avatar Nov 27 '17 22:11 kzapfe

Put a delete!(file, "A", A) before yourwrite. Note, however, that HDF5 doesn't always actually free the space. So your file might be growing although you have the same size object stored inside. To avoid this generically, you would have to repack your file (look here for a hack to do this).

I do agree though that some convenience mappings would be nice here.

carstenbauer avatar Dec 22 '17 14:12 carstenbauer