summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-05-30 20:39:34 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-05-30 20:39:34 -0700
commit6802740f63fdd37078bf8b7c90772f97460840ad (patch)
treeed4b2fbab40ee22134d828d42a66e1eef67ba03c
parentda08194bb7db19064ad82cc0d7341ff5ed1438e7 (diff)
downloadtxr-6802740f63fdd37078bf8b7c90772f97460840ad.tar.gz
txr-6802740f63fdd37078bf8b7c90772f97460840ad.tar.bz2
txr-6802740f63fdd37078bf8b7c90772f97460840ad.zip
buf: compression tests.
* buf.c (buf_compress): Let's use the level value of -1 if not specified, so Zlib defaults it to 6, or whatever. * tests/012/buf.tl: New tests. * txr.1: Note that -1 is a valid level value and that is the default.
-rw-r--r--buf.c2
-rw-r--r--tests/012/buf.tl18
-rw-r--r--txr.15
3 files changed, 22 insertions, 3 deletions
diff --git a/buf.c b/buf.c
index be728189..e6e03da1 100644
--- a/buf.c
+++ b/buf.c
@@ -1231,7 +1231,7 @@ static val uint_buf(val buf)
static val buf_compress(val buf, val level_opt)
{
val self = lit("buf-compress");
- val level = default_arg(level_opt, num_fast(6));
+ val level = default_arg(level_opt, negone);
int lev = c_int(level, self);
struct buf *b = buf_handle(buf, self);
ucnum size = c_unum(b->len, self);
diff --git a/tests/012/buf.tl b/tests/012/buf.tl
index 8f494264..01a510ab 100644
--- a/tests/012/buf.tl
+++ b/tests/012/buf.tl
@@ -8,3 +8,21 @@
(buf-str "\xDCE6\xDCBC") #b'E6BC'
(str-buf #b'E6') "\xDCE6"
(buf-str "\xDCE6") #b'E6')
+
+(when (fboundp 'usr:buf-compress)
+ (mtest
+ (< (len (buf-compress (make-buf 1024))) 100) t
+ (buf-compress (make-buf 1024) -2) :error
+ (buf-compress (make-buf 1024) 10) :error)
+
+ (each ((i 0..65535))
+ (let* ((buf (ffi-put i (ffi uint16)))
+ (zbuf (buf-compress buf)))
+ (vtest (buf-decompress zbuf) buf)))
+
+ (let ((buf (random-buf 65536)))
+ (vtest (buf-decompress (buf-compress buf)) buf))
+
+ (mtest
+ (buf-decompress (make-buf 1024)) :error
+ (buf-decompress (make-buf 1024 255)) :error))
diff --git a/txr.1 b/txr.1
index c243d516..e27fd431 100644
--- a/txr.1
+++ b/txr.1
@@ -28444,8 +28444,9 @@ function compresses the entire contents of
.meta buf
and returns new buffer with the compressed contents. The optional
.meta level
-argument specifies the compression level as an integer, which defaults to 6.
-Valid values range from 0 to 9: no compression, to maximum.
+argument specifies the compression level as an integer.
+Valid values range from 0 (no compression) to 9 (maximum compression).
+The value -1 selects a default compression determined internally by Zlib.
The
.code buf-decompress