changelog shortlog graph tags branches changeset file revisions annotate raw help

Mercurial > core / lisp/ffi/zstd/stream.lisp

revision 507: 4dd7b6320efc
parent 469: 7354623e5b54
child 657: 937a6f354047
     1.1--- a/lisp/ffi/zstd/stream.lisp	Wed Jul 03 22:21:46 2024 -0400
     1.2+++ b/lisp/ffi/zstd/stream.lisp	Thu Jul 04 16:42:46 2024 -0400
     1.3@@ -5,6 +5,18 @@
     1.4 ;;; Code:
     1.5 (in-package :zstd)
     1.6 
     1.7+(deferror zstd-dstream-error (zstd-alien-error) ())
     1.8+(deferror zstd-cstream-error (zstd-alien-error)
     1.9+    ()
    1.10+    (:report (lambda (c s)
    1.11+               (format s "ZSTD CStream signalled error: ~A" (zstd-errorcode* (zstd-error-code c))))))
    1.12+
    1.13+(defun zstd-dstream-error (code)
    1.14+  (error 'zstd-dstream-error :code code))
    1.15+
    1.16+(defun zstd-cstream-error (code)
    1.17+  (error 'zstd-cstream-error :code code))
    1.18+
    1.19 (define-alien-type zstd-cstream zstd-cctx)
    1.20 
    1.21 (define-alien-routine "ZSTD_createCStream" (* zstd-cstream))
    1.22@@ -44,12 +56,22 @@
    1.23 (define-alien-routine "ZSTD_DStreamInSize" size-t)
    1.24 (define-alien-routine "ZSTD_DStreamOutSize" size-t)
    1.25 
    1.26-(defmacro with-zstd-dstream ((dv dst &key (close t)) &body body)
    1.27-  `(let ((,dv ,dst))
    1.28-     (unwind-protect (progn ,@body)
    1.29-       ,@(when close `((zstd-freedstream ,dv))))))
    1.30+(defmacro with-zstd-cstream ((cv &key (init t) (close t) (level (zstd-defaultclevel)) ) &body body)
    1.31+  `(with-alien ((,cv (* zstd-cstream) (zstd-createcstream)))
    1.32+     (unwind-protect
    1.33+          (progn
    1.34+            ,@(when init `((let ((%cinit (zstd-initcstream ,cv ,level)))
    1.35+                             (unless (zerop (zstd-iserror %cinit))
    1.36+                               (zstd-cstream-error %cinit)))))
    1.37+            ,@body)
    1.38+       ,@(when close `((zstd-freecstream ,cv))))))
    1.39 
    1.40-(defmacro with-zstd-cstream ((cv cst &key (close t)) &body body)
    1.41-  `(let ((,cv ,cst))
    1.42-     (unwind-protect (progn ,@body)
    1.43-       ,@(when close `((zstd-freecstream ,cv))))))
    1.44+(defmacro with-zstd-dstream ((dv &key (init t) (close t)) &body body)
    1.45+  `(with-alien ((,dv (* zstd-dstream) (zstd-createdstream)))
    1.46+     (unwind-protect
    1.47+          (progn
    1.48+            ,@(when init `((let ((%dinit (zstd-initdstream ,dv)))
    1.49+                             (unless (zerop (zstd-iserror %dinit))
    1.50+                               (zstd-dstream-error %dinit)))))
    1.51+            ,@body)
    1.52+       ,@(when close `((zstd-freedstream ,dv))))))