-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDigest.R
54 lines (53 loc) · 1.71 KB
/
Digest.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#' Digest files from (digest package)
#' @description Compute file hash without checking file.access
#' @return The filehash
#' @export
Digest <- function (object, algo = c("md5", "sha1", "crc32", "sha256",
"sha512"), serialize = TRUE, file = FALSE, length = Inf,
skip = "auto", ascii = FALSE, raw = FALSE)
{
algo <- match.arg(algo)
if (is.infinite(length)) {
length <- -1
}
if (is.character(file) && missing(object)) {
object <- file
file <- TRUE
}
if (serialize && !file) {
object <- serialize(object, connection = NULL, ascii = ascii)
if (any(!is.na(pmatch(skip, "auto")))) {
if (ascii) {
skip <- which(object[1:30] == as.raw(10))[4]
}
else {
skip <- 14
}
}
}
else if (!is.character(object) && !inherits(object, "raw")) {
stop("Argument object must be of type character or raw vector if serialize is FALSE")
}
if (file && !is.character(object))
stop("file=TRUE can only be used with a character object")
algoint <- switch(algo, md5 = 1, sha1 = 2, crc32 = 3, sha256 = 4,
sha512 = 5)
if (file) {
algoint <- algoint + 100
object <- path.expand(object)
if (!file.exists(object)) {
stop("The file does not exist: ", object)
}
if (!isTRUE(!file.info(object)$isdir)) {
stop("The specified pathname is not a file: ", object)
}
# if (file.access(object, 4)) {
# stop("The specified file is not readable: ", object)
# }
}
if (is.character(skip))
skip <- 0
val <- .Call("digest", object, as.integer(algoint), as.integer(length),
as.integer(skip), as.integer(raw), PACKAGE = "digest")
return(val)
}