R/file-hashers.R

Defines functions md5 sha256 sha1

Documented in md5 sha1 sha256

#' Create hash digest from a file
#'
#' Thin wrapper around {openssl} counterparts that automatically wrap `x` with `file()`
#' and return unclassed character representations of the digests.
#'
#' @param x path to file
#' @return hash digest (chr)
#' @export
#' @examples
#' md5(system.file("samples/s_copypix.txt", package = "hashlookup")),
#' sha1(system.file("samples/s_copypix.txt", package = "hashlookup")),
#' sha256(system.file("samples/s_copypix.txt", package = "hashlookup")),
sha1 <- function(x) {
  unclass(as.character(openssl::sha1(file(x))))
}

#' Create hash digest from a file
#'
#' Thin wrapper around {openssl} counterparts that automatically wrap `x` with `file()`
#' and return unclassed character representations of the digests.
#'
#' @param x path to file
#' @return hash digest (chr)
#' @export
#' @examples
#' md5(system.file("samples/s_copypix.txt", package = "hashlookup")),
#' sha1(system.file("samples/s_copypix.txt", package = "hashlookup")),
#' sha256(system.file("samples/s_copypix.txt", package = "hashlookup")),
sha256 <- function(x) {
  unclass(as.character(openssl::sha256(file(x))))
}

#' Create hash digest from a file
#'
#' Thin wrapper around {openssl} counterparts that automatically wrap `x` with `file()`
#' and return unclassed character representations of the digests.
#'
#' @param x path to file
#' @return hash digest (chr)
#' @export
#' @examples
#' md5(system.file("samples/s_copypix.txt", package = "hashlookup")),
#' sha1(system.file("samples/s_copypix.txt", package = "hashlookup")),
#' sha256(system.file("samples/s_copypix.txt", package = "hashlookup")),
md5 <- function(x) {
  unclass(as.character(openssl::md5(file(x))))
}
hrbrmstr/hashlookup documentation built on Jan. 3, 2022, 12:14 a.m.