Last active
March 26, 2020 17:40
-
-
Save jeroen/2087db9eaeac46fc1cd4cb107c7e106b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
openssl_multihash <- function(con, algos = c('md5', 'sha1', 'sha256', 'sha384', 'sha512')){ | |
if(!isOpen(con)){ | |
open(con, "rb") | |
on.exit(close(con)) | |
} | |
states <- lapply(algos, function(algo){ | |
structure(openssl:::md_init(algo), algo = algo) | |
}) | |
while(length(data <- readBin(con, raw(), 512*1024))){ | |
lapply(states, openssl:::md_feed, data = data) | |
} | |
hashes <- lapply(states, function(x){ | |
hash <- openssl:::md_final(x) | |
structure(hash, class = c("hash", attr(x, 'algo'))) | |
}) | |
structure(hashes, names = algos) | |
} | |
openssl_multihash(curl::curl("https://zenodo.org/record/3678928/files/vostok.icecore.co2")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment