Debian Codegraph @

R/md5sum.R

raw
1
2 renv_md5sum_old <- function(text) {
3
4 tempfile <- tempfile("renv-md5sum-")
5 con <- file(tempfile, open = "wb")
6 writeLines(enc2utf8(text), con = con, useBytes = TRUE)
7 flush(con)
8 close(con)
9
10 hash <- unname(md5sum(tempfile))
11 unlink(tempfile)
12
13 hash
14
15 }
16
17 renv_md5sum_new <- function(text) {
18
19 # The old implementation worked by writing a string out to a file using
20 # writeLines(), which would ensure a trailing newline was included in
21 # the generated output. We append a newline here to preserve that behavior.
22 newline <- as.raw(0x0a)
23 bytes <- c(charToRaw(enc2utf8(text)), newline)
24
25 # silence R CMD check warning -- this only gets invoked for R >= 4.5.0
26 (md5sum)(bytes = bytes)
27
28 }
29
30 md5 <- if (getRversion() < "4.5.0") {
31 renv_md5sum_old
32 } else {
33 renv_md5sum_new
34 }