From 19647c98c1d961015bb4d51c264355d392bf0d20 Mon Sep 17 00:00:00 2001 From: Vadym Kochan Date: Mon, 13 Jan 2025 12:19:23 +0200 Subject: [PATCH] zlib: add simplified make-zlib-input-port version to pass just a port Signed-off-by: Vadym Kochan --- tests/test-zlib.scm | 15 +++++++++++++++ zlib.scm | 10 +++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/test-zlib.scm b/tests/test-zlib.scm index 0536855..b4af44f 100755 --- a/tests/test-zlib.scm +++ b/tests/test-zlib.scm @@ -93,4 +93,19 @@ #f)))) (test-end) +(test-begin "zlib simplified") +(define test-data #vu8( #x78 #x9c #xcb #x48 #xcd #xc9 #xc9 #x57 #xa8 #xca #xc9 #x4c + #x02 #x00 #x15 #x95 #x03 #xe6)) + +(call-with-port + (open-bytevector-input-port test-data) + (lambda (p) + (call-with-port (make-zlib-input-port p) + (lambda (zp) + (let* ([bv (get-bytevector-all zp)] + [s (bytevector->string bv (native-transcoder))]) + (test-equal "hello zlib" s)))))) + +(test-end) + (exit (if (zero? (test-runner-fail-count (test-runner-get))) 0 1)) diff --git a/zlib.scm b/zlib.scm index c406d7c..39f7c21 100644 --- a/zlib.scm +++ b/zlib.scm @@ -79,7 +79,7 @@ ;; size as max-buffer-size. See the URL earlier about flushing. The ;; `dictionaries' argument is an alist of Adler-32 checksums and ;; dictionaries (bytevectors). - (define (make-zlib-input-port in id max-buffer-size + (define (*make-zlib-input-port* in id max-buffer-size close-underlying-port? dictionaries) (let-values (((window-size dictid) (get-zlib-header in))) (let ((done #f) ;no more data? @@ -157,4 +157,12 @@ (set! inflater #f)) (make-custom-binary-input-port id read! #f #f close)))) + (define make-zlib-input-port + (case-lambda + [(in) + (*make-zlib-input-port* in "zlib" #f #f '())] + + [(in id max-buffer-size close-underlying-port? dictionaries) + (*make-zlib-input-port* in id max-buffer-size close-underlying-port? dictionaries)])) + ) -- GitLab