summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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