Generate a content uri for a local file
content_id( file, algos = default_algos(), raw = TRUE, as.data.frame = length(algos) > 1 )
file | path to the file, URL, or a base::file connection |
---|---|
algos | Which algorithms should we compute contentid for? Default "sha256", see details. |
raw | Logical, should compressed data be left as compressed binary? |
as.data.frame | should the output be coerced into a data.frame?
Default is |
a content identifier URI If multiple algorithms
are requested, content_id
will return a data.frame with one
column per algorithm and one row for each input file. Otherwise
it will return a character vector with one identifier URI for
each input file. See argument as.data.frame
above.
See https://github.com/hash-uri/hash-uri for an overview of the content uri format and comparison to similar approaches.
Compressed file streams will have different raw (binary) and uncompressed
hashes. Set raw = FALSE
to allow base::file connection to uncompress
common compression streams before calculating the hash, but this will
be slower.
## local file path <- system.file("extdata", "vostok.icecore.co2", package = "contentid") content_id(path)#> [1] "hash://sha256/9412325831dab22aeebdd674b6eb53ba6b7bdd04bb99a4dbb21ddff646287e37"# \donttest{ content_id(paste0("https://knb.ecoinformatics.org/knb/d1/mn/v2/object/", "ess-dive-457358fdc81d3a5-20180726T203952542"))#> [1] "hash://sha256/9412325831dab22aeebdd674b6eb53ba6b7bdd04bb99a4dbb21ddff646287e37"# }