R Under development (unstable) (2025-11-20 r89043 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # Utility tests for file compression/decompression and raw helpers > # Note: do not run here; leave execution to the user/environment. > > library(qs2) qs2 0.1.6 > > cat("Testing zstd file compression (small file)...\n") Testing zstd file compression (small file)... > infile <- tempfile() > outfile <- tempfile() > decoded <- tempfile() > > writeBin(as.raw(1:100), infile) > zstd_compress_file(infile, outfile, compress_level = 1L) > zstd_decompress_file(outfile, decoded) > stopifnot(file.exists(outfile)) > stopifnot(file.exists(decoded)) > stopifnot(identical(readBin(infile, what = "raw", n = file.info(infile)$size), + readBin(decoded, what = "raw", n = file.info(decoded)$size))) > > cat("Testing zstd file compression (multi-buffer)...\n") Testing zstd file compression (multi-buffer)... > infile <- tempfile() > outfile <- tempfile() > decoded <- tempfile() > data <- as.raw(sample(0:255, size = 3 * 1024 * 1024, replace = TRUE)) > writeBin(data, infile) > zstd_compress_file(infile, outfile, compress_level = 1L) > zstd_decompress_file(outfile, decoded) > stopifnot(file.exists(outfile)) > stopifnot(file.exists(decoded)) > stopifnot(identical(readBin(decoded, what = "raw", n = length(data)), data)) > > cat("Testing zstd file compression (buffer edges)...\n") Testing zstd file compression (buffer edges)... > infile <- tempfile() > outfile <- tempfile() > decoded <- tempfile() > buf_size <- 1024 * 1024 > data_exact <- as.raw(sample(0:255, size = buf_size, replace = TRUE)) > writeBin(data_exact, infile) > zstd_compress_file(infile, outfile, compress_level = 1L) > zstd_decompress_file(outfile, decoded) > stopifnot(identical(readBin(decoded, what = "raw", n = length(data_exact)), data_exact)) > > data_over <- c(data_exact, as.raw(1L)) > writeBin(data_over, infile) > zstd_compress_file(infile, outfile, compress_level = 1L) > zstd_decompress_file(outfile, decoded) > stopifnot(identical(readBin(decoded, what = "raw", n = length(data_over)), data_over)) > > cat("Testing raw compression utilities...\n") Testing raw compression utilities... > x <- serialize(list(a = 1:5, b = letters[1:10]), connection = NULL) > z <- zstd_compress_raw(x, compress_level = 1L) > x2 <- unserialize(zstd_decompress_raw(z)) > stopifnot(identical(x2, list(a = 1:5, b = letters[1:10]))) > > cat("Testing zstd_compress_bound...\n") Testing zstd_compress_bound... > stopifnot(zstd_compress_bound(0L) >= 0L) > stopifnot(zstd_compress_bound(100000L) >= 100000L) > > cat("Testing blosc shuffle/unshuffle...\n") Testing blosc shuffle/unshuffle... > raw_data <- serialize(1L:1000L, NULL) > shuf4 <- blosc_shuffle_raw(raw_data, 4L) > unshuf4 <- blosc_unshuffle_raw(shuf4, 4L) > stopifnot(identical(unshuf4, raw_data)) > shuf8 <- blosc_shuffle_raw(raw_data, 8L) > unshuf8 <- blosc_unshuffle_raw(shuf8, 8L) > stopifnot(identical(unshuf8, raw_data)) > > cat("Testing xxhash_raw...\n") Testing xxhash_raw... > raw_hash <- xxhash_raw(as.raw(c(1, 2, 3, 4))) > stopifnot(is.character(raw_hash)) > > cat("Testing base85 encode/decode...\n") Testing base85 encode/decode... > b85_raw <- as.raw(sample(0:255, size = 128, replace = TRUE)) > b85_enc <- base85_encode(b85_raw) > b85_dec <- base85_decode(b85_enc) > stopifnot(identical(b85_dec, b85_raw)) > > cat("Testing base91 encode/decode...\n") Testing base91 encode/decode... > b91_raw <- as.raw(sample(0:255, size = 256, replace = TRUE)) > b91_enc <- base91_encode(b91_raw) > b91_dec <- base91_decode(b91_enc) > stopifnot(identical(b91_dec, b91_raw)) > > cat("Testing qx_dump...\n") Testing qx_dump... > tmp_qs <- tempfile(fileext = ".qs2") > obj <- as.raw(sample(0:255, size = 2 * 1024 * 1024, replace = TRUE)) > qs_save(obj, tmp_qs, shuffle = TRUE, compress_level = 1L) > qd <- qx_dump(tmp_qs) > stopifnot(any(qd$block_shuffled == 1)) > recovered <- do.call(c, qd$blocks) > stopifnot(identical(unserialize(recovered), obj)) > stopifnot(identical(qd$stored_hash, qd$computed_hash)) > > cat("Utility tests completed.\n") Utility tests completed. > > proc.time() user system elapsed 0.70 0.10 0.79