R/checksums.R

Defines functions sha256 md5 .digest

Documented in md5 sha256

#' Generate checksum from file
#'
#' @name checksums
#' @note Updated 2021-04-27.
#'
#' @inheritParams AcidRoxygen::params
#'
#' @examples
#' file <- system.file("extdata/example.csv", package = "pipette")
#' md5(file)
#' sha256(file)
NULL



## Updated 2021-04-27.
.digest <- function(
    file,
    algo = c("md5", "sha256")
) {
    requireNamespaces("digest")
    assert(isAFile(file))
    x <- digest::digest(
        object = file,
        algo = match.arg(algo),
        file = TRUE
    )
    assert(isString(x))
    x
}


#' @rdname checksums
#' @export
md5 <- function(file) {
    .digest(file = file, algo = "md5")
}



#' @rdname checksums
#' @export
sha256 <- function(file) {
    .digest(file = file, algo = "sha256")
}
acidgenomics/pipette documentation built on Sept. 27, 2021, 9:10 a.m.