From bd3ff4cd2272235e6b3e43843b6ede1ecf4052dc Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 30 May 2022 20:39:34 -0700 Subject: 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. --- buf.c | 2 +- tests/012/buf.tl | 18 ++++++++++++++++++ txr.1 | 5 +++-- 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 -- cgit v1.2.3