Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn for unknown compressor config args #126

Merged
merged 22 commits into from
Jan 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions R/numcodecs.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ Codec <- R6::R6Class("Codec",
)
)

#' @keywords internal
warn_if_unk_args <- function(unk_args, compressor_name) {
if(length(unk_args) > 0) {
unk_args_str <- paste(names(unk_args), collapse = ", ")
warning(paste(compressor_name, "received unrecognized compressor config parameters:", unk_args_str))
}
}

#' ZSTD compressor for Zarr
#' @title ZstdCodec Class
Expand All @@ -52,8 +59,9 @@ ZstdCodec <- R6::R6Class("ZstdCodec",
#' Create a new ZSTD compressor.
#' @param level The compression level, between 1 and 22.
#' @return A new `ZstdCodec` object.
initialize = function(level = 1) {
initialize = function(level = 1, ...) {
self$level <- level
warn_if_unk_args(list(...), "ZstdCodec")
},
#' @description
#' Compress data.
Expand Down Expand Up @@ -105,8 +113,9 @@ Lz4Codec <- R6::R6Class("Lz4Codec",
#' Create a new LZ4 compressor.
#' @param acceleration The compression level.
#' @return A new `Lz4Codec` object.
initialize = function(acceleration = 1) {
initialize = function(acceleration = 1, ...) {
self$acceleration <- acceleration
warn_if_unk_args(list(...), "Lz4Codec")
},
#' @description
#' Compress data.
Expand Down Expand Up @@ -167,9 +176,10 @@ ZlibCodec <- R6::R6Class("ZlibCodec",
#' Create a new Zlib compressor.
#' @param level The compression level, between 1 and 22.
#' @return A new `ZlibCodec` object.
initialize = function(level = 6) {
initialize = function(level = 6, ...) {
self$level <- level
# No config options for zlib.
warn_if_unk_args(list(...), "ZlibCodec")
},
#' @description
#' Compress data.
Expand Down Expand Up @@ -227,9 +237,10 @@ GzipCodec <- R6::R6Class("GzipCodec",
#' Create a new Gzip compressor.
#' @param level The compression level, between 1 and 22.
#' @return A new `GzipCodec` object.
initialize = function(level = 6) {
initialize = function(level = 6, ...) {
# No config options for gzip.
self$level <- level
warn_if_unk_args(list(...), "GzipCodec")
},
#' @description
#' Compress data.
Expand Down Expand Up @@ -284,9 +295,10 @@ Bz2Codec <- R6::R6Class("Bz2Codec",
#' Create a new Bz2 compressor.
#' @param level The compression level, between 1 and 22.
#' @return A new `Bz2Codec` object.
initialize = function(level = 6) {
initialize = function(level = 6, ...) {
# No config options for bz2.
self$level <- level
warn_if_unk_args(list(...), "Bz2Codec")
},
#' @description
#' Compress data.
Expand Down Expand Up @@ -344,13 +356,14 @@ LzmaCodec <- R6::R6Class("LzmaCodec",
#' @param level The compression level, between 1 and 22.
#' @param format only 1 is supported
#' @return A new `LzmaCodec` object.
initialize = function(level = 9, format = 1) {
initialize = function(level = 9, format = 1, ...) {
# No config options for lzma.
self$level <- level
self$format <- format
if(format != 1) {
stop("Only format 1 is supported for lzma compression")
}
warn_if_unk_args(list(...), "LzmaCodec")
},
#' @description
#' Compress data.
Expand Down Expand Up @@ -415,7 +428,7 @@ BloscCodec <- R6::R6Class("BloscCodec",
#' @param shuffle The shuffle filter to use.
#' @param blocksize The block size.
#' @return A new `BloscCodec` object.
initialize = function(cname = "lz4", clevel = 5, shuffle = TRUE, blocksize = NA) {
initialize = function(cname = "lz4", clevel = 5, shuffle = TRUE, blocksize = NA, ...) {
self$cname <- cname
self$clevel <- clevel
self$shuffle <- shuffle
Expand All @@ -424,6 +437,7 @@ BloscCodec <- R6::R6Class("BloscCodec",
if (!require("Rarr", quietly = TRUE)) {
stop("Rarr package must be installed to use the Blosc codec. Install with BiocManager::install('Rarr')")
}
warn_if_unk_args(list(...), "BloscCodec")
},
#' @description
#' Compress data.
Expand Down
Loading