zstr icon indicating copy to clipboard operation
zstr copied to clipboard

Request: constants instead of magic numbers for windowBits parameter

Open stertingen opened this issue 4 years ago • 1 comments

zstr.hpp:99 and zstr.hpp:103 use 15+32 and 12+16 as default window size. The semantics of this behavior are documented in https://zlib.net/manual.html, but I find this interface not very intuitive. It's not clear that gzip is used by default, which lead to subtle bugs in some project code.

I would appreciate if there were constants or separate parameters to make the used window size and header explicit. It would be more clear that the default value 15 + 16 refers to a 64KiB window with gzip header. Also, changing the compression header would not involve setting arbitrary numbers to the windowBits parameter.

I would propose adding an enum class type for the compression header:

enum class header {auto_detect, zlib, gzip, raw_deflate};

The streambuf classes get additional constructors which take a compression header argument and calculate the windowBits value based on the compression header and the desired window size (+32, +16 or negate window size).

stertingen avatar Mar 03 '22 10:03 stertingen

Thanks for the ideas. I do not develop this package, but I have merge-rights, so any PR is welcome.

ferdymercury avatar Mar 03 '22 10:03 ferdymercury