При прохождении исходного кода загрузки исходного кода в репозитории Flux.jl github (https://github.com/FluxML/Flux.jl/blob/master/src/data/Data.jl),
Полный исходный код:
module Data
import ..Flux
import SHA
export CMUDict, cmudict
deps(path...) = joinpath(@__DIR__, "..", "..", "deps", path...)
function download_and_verify(url, path, hash)
tmppath = tempname()
download(url, tmppath)
hash_download = open(tmppath) do f
bytes2hex(SHA.sha256(f))
end
if hash_download !== hash
msg = "Hash Mismatch!\n"
msg *= " Expected sha256: $hash\n"
msg *= " Calculated sha256: $hash_download"
error(msg)
end
mv(tmppath, path; force=true)
end
function __init__()
mkpath(deps())
end
include("mnist.jl")
export MNIST
include("fashion-mnist.jl")
export FashionMNIST
include("cmudict.jl")
using .CMUDict
include("tree.jl")
include("sentiment.jl")
using .Sentiment
include("iris.jl")
export Iris
end
I не могу понять, что следующие строки делают и , почему они необходимы,
hash_download = open(tmppath) do f
bytes2hex(SHA.sha256(f))
end
if hash_download !== hash
msg = "Hash Mismatch!\n"
msg *= " Expected sha256: $hash\n"
msg *= " Calculated sha256: $hash_download"
error(msg)
end
Следующий код используется iris.jl (скрипт для скачайте набор данных iris), в этом контексте,
download_and_verify("$(cache_prefix)https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data",
deps("iris.data"),
"6f608b71a7317216319b4d27b4d9bc84e6abd734eda7872b71a458569e2656c0")
Буду признателен, если кто-нибудь сможет уточнить, что делает секция хеширования кода и зачем они нужны.