"Fossies" - the Fresh Open Source Software Archive

Member "julia-1.1.1/share/julia/stdlib/v1.1/Pkg/src/Compress.jl" (16 May 2019, 1522 Bytes) of package /linux/misc/julia-1.1.1-linux-i686.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Julia source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 module Compress
    2 
    3 import Pkg.TOML
    4 import Pkg.Types: VersionSpec, compress_versions
    5 
    6 function load_versions(path::String)
    7     versions_file = joinpath(dirname(path), "Versions.toml")
    8     versions_dict = TOML.parsefile(versions_file)
    9     sort!([VersionNumber(v) for v in keys(versions_dict)])
   10 end
   11 
   12 function load(path::String,
   13     versions::Vector{VersionNumber} = load_versions(path))
   14     compressed = TOML.parsefile(path)
   15     uncompressed = Dict{VersionNumber,Dict{Any,Any}}()
   16     for (vers, data) in compressed
   17         vs = VersionSpec(vers)
   18         for v in versions
   19             v in vs || continue
   20             merge!(get!(uncompressed, v, Dict()), deepcopy(data))
   21         end
   22     end
   23     return uncompressed
   24 end
   25 
   26 function compress(path::String, uncompressed::Dict,
   27     versions::Vector{VersionNumber} = load_versions(path))
   28     inverted = Dict()
   29     for (ver, data) in uncompressed, (key, val) in data
   30         val isa TOML.TYPE || (val = string(val))
   31         push!(get!(inverted, key => val, VersionNumber[]), ver)
   32     end
   33     compressed = Dict()
   34     for ((k, v), vers) in inverted
   35         for r in compress_versions(versions, sort!(vers)).ranges
   36             get!(compressed, string(r), Dict{String,Any}())[k] = v
   37         end
   38     end
   39     return compressed
   40 end
   41 
   42 function save(path::String, uncompressed::Dict,
   43     versions::Vector{VersionNumber} = load_versions(path))
   44     compressed = compress(path, uncompressed)
   45     open(path, write=true) do io
   46         TOML.print(io, compressed, sorted=true)
   47     end
   48 end
   49 
   50 end # module