Moved archive to from required to suggested packages

and edited code to check if it is installed, then perform the
appropriate operations in compress.log(). On Linux, `archive` needs some
system packages to be installed, so it is better as a suggested package.
This commit is contained in:
Rucknium 2024-04-29 01:01:10 +00:00
parent d6f3672015
commit e4fc8c5222
3 changed files with 25 additions and 13 deletions

View file

@ -25,9 +25,9 @@ Imports:
parallelly, parallelly,
future, future,
future.apply, future.apply,
qs, qs
archive
Suggests: Suggests:
archive,
testthat (>= 3.0.0), testthat (>= 3.0.0),
withr withr
Config/testthat/edition: 3 Config/testthat/edition: 3

View file

@ -2,5 +2,5 @@
export("ping.peers") export("ping.peers")
export("get.p2p.log") export("get.p2p.log")
export("compress.log") export("compress.log")
importFrom("utils", "read.csv", "untar") importFrom("utils", "read.csv", "untar", "installed.packages")
importFrom("stats", "complete.cases") importFrom("stats", "complete.cases")

View file

@ -263,14 +263,25 @@ compress.log <- function(bitmonero.dir = c("~/.bitmonero", "C:\\ProgramData\\bit
cat("Processing ", length(gz.files), " log files in ", tar.file, "...\n", sep = "") cat("Processing ", length(gz.files), " log files in ", tar.file, "...\n", sep = "")
for (gz.file in gz.files) { for (gz.file in gz.files) {
cat("Processing log file ", gz.file, " from ", tar.file, "...\n", sep = "") cat("Processing log file ", gz.file, " from ", tar.file, "...\n", sep = "")
gz.connection <- archive::archive_read(paste0(bitmonero.dir, "/", tar.file), file = gz.file) if ("archive" %in% installed.packages()[, 1]) {
gz.output <- readLines(gz.connection, skipNul = TRUE) gz.connection <- archive::archive_read(paste0(bitmonero.dir, "/", tar.file), file = gz.file)
# Cannot use data.table::fread() with a connection: https://github.com/Rdatatable/data.table/issues/561 gz.output <- readLines(gz.connection, skipNul = TRUE)
data.table::fwrite(list(paste0(gz.file, ":", gz.output[grep(log.filter, gz.output)])), # Cannot use data.table::fread() with a connection: https://github.com/Rdatatable/data.table/issues/561
file = output.file, append = TRUE, col.name = FALSE, showProgress = FALSE) data.table::fwrite(list(paste0(gz.file, ":", gz.output[grep(log.filter, gz.output)])),
rm(gz.output) file = output.file, append = TRUE, col.name = FALSE, showProgress = FALSE)
close(gz.connection) rm(gz.output)
# Close connection close(gz.connection)
# Close connection
} else {
tmp <- tempdir()
untar(paste0(bitmonero.dir, "/", tar.file), files = gz.file, exdir = tmp)
gz.output <- data.table::fread(paste0(bitmonero.dir, "/", gz.file), colClasses = "character",
header = FALSE, sep = NULL, blank.lines.skip = FALSE, showProgress = FALSE)[[1]]
data.table::fwrite(list(paste0(gz.file, ":", gz.output[grep(log.filter, gz.output)])),
file = output.file, append = TRUE, col.name = FALSE, showProgress = FALSE)
rm(gz.output)
unlink(paste0(tmp, "/", gz.file))
}
} }
} }
gc() gc()
@ -279,7 +290,7 @@ compress.log <- function(bitmonero.dir = c("~/.bitmonero", "C:\\ProgramData\\bit
cat("Processing log file ", bitmonero.file, "...\n", sep = "") cat("Processing log file ", bitmonero.file, "...\n", sep = "")
txt.output <- data.table::fread(paste0(bitmonero.dir, "/", bitmonero.file), colClasses = "character", txt.output <- data.table::fread(paste0(bitmonero.dir, "/", bitmonero.file), colClasses = "character",
header = FALSE, sep = NULL, blank.lines.skip = FALSE, showProgress = FALSE)[[1]] header = FALSE, sep = NULL, blank.lines.skip = FALSE, showProgress = FALSE)[[1]]
data.table::fwrite(list(paste0(gz.file, ":", txt.output[grep(log.filter, txt.output)])), data.table::fwrite(list(paste0(bitmonero.file, ":", txt.output[grep(log.filter, txt.output)])),
file = output.file, append = TRUE, col.name = FALSE, showProgress = FALSE) file = output.file, append = TRUE, col.name = FALSE, showProgress = FALSE)
rm(txt.output) rm(txt.output)
} }
@ -362,7 +373,8 @@ xzcompress <- function (filename, destname = sprintf("%s.xz", filename), tempora
nbytes <- nbytes + n nbytes <- nbytes + n
writeBin(bfr, con = out, size = 1L) writeBin(bfr, con = out, size = 1L)
bfr <- NULL bfr <- NULL
cat( formatC(round(nbytes / 10^9, 1), digits = 1, flag = "#"), " GB compressed...\r", sep = "") cat( formatC(round(nbytes / 10^9, 1), width = 2, digits = 1, flag = "#",
format = "f"), " GB compressed...\r", sep = "")
# Added this. \r is to delete previous line. # Added this. \r is to delete previous line.
} }
outComplete <- TRUE outComplete <- TRUE