content_id: Generate a content uri for a local file

Description Usage Arguments Details Value Examples

View source: R/content_id.R

Description

Generate a content uri for a local file

Usage

1
2
3
4
5
6
content_id(
  file,
  algos = default_algos(),
  raw = TRUE,
  as.data.frame = length(algos) > 1
)

Arguments

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 FALSE if only one algorithm is computed, otherwise TRUE.

Details

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.

Value

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.

Examples

1
2
3
4
5
6
7
## local file
path <- system.file("extdata", "vostok.icecore.co2", package = "contentid")
content_id(path)


content_id(paste0("https://knb.ecoinformatics.org/knb/d1/mn/v2/object/",
                  "ess-dive-457358fdc81d3a5-20180726T203952542"))

cboettig/contentid documentation built on April 1, 2021, 11:25 p.m.