invenia / JLSO.jl

Julia Serialized Object (JLSO) file format for storing checkpoint data.
MIT License
90 stars 5 forks source link

Add some methods to make JLSOFile more Dict-like #108

Closed nickrobinson251 closed 3 years ago

nickrobinson251 commented 3 years ago

Together, this allows users to write code like

jlso = isfile(filename) ? read(filename, JLSOFile) : JLSOFile()
get!(jlso, :qux) do
    make_qux()
end
JLSO.save(filename, jlso)

or

if isfile(filename) 
    jlso = read(filename, JLSOFile)
    haskey(jlso, :qux) && return jlso[:qux]
else
    jlso = JLSOFile()    
end
jlso[:qux] = make_qux()
JLSO.save(filename, jlso)

The main advantage is this allows working with a JLSOFile similar to working with the Dict that would be returned by JLSO.load(filename), but with JLSOFile lazily deserialising (unlike load)

codecov[bot] commented 3 years ago

Codecov Report

Merging #108 (0a08047) into master (dbf7be6) will increase coverage by 0.11%. The diff coverage is 100.00%.

:exclamation: Current head 0a08047 differs from pull request most recent head 7c75b90. Consider uploading reports for the commit 7c75b90 to get more accurate results Impacted file tree graph

@@            Coverage Diff             @@
##           master     #108      +/-   ##
==========================================
+ Coverage   97.56%   97.67%   +0.11%     
==========================================
  Files           6        6              
  Lines         205      215      +10     
==========================================
+ Hits          200      210      +10     
  Misses          5        5              
Impacted Files Coverage Δ
src/JLSOFile.jl 93.33% <100.00%> (+2.85%) :arrow_up:
src/file_io.jl 94.44% <100.00%> (+0.10%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update dbf7be6...7c75b90. Read the comment docs.