1.1--- a/lisp/ffi/zstd/simple.lisp Sat Jun 22 19:45:19 2024 -0400
1.2+++ b/lisp/ffi/zstd/simple.lisp Sat Jun 22 22:16:21 2024 -0400
1.3@@ -13,5 +13,37 @@
1.4 (compression int))
1.5
1.6 (define-alien-routine "ZSTD_decompress" size-t
1.7- (dst (* t)) (dst-capacity size-t)
1.8- (src (* t)) (compressed-size size-t))
1.9+ (dst (* t))
1.10+ (dst-capacity size-t)
1.11+ (src (* t))
1.12+ (compressed-size size-t))
1.13+
1.14+(deferror zstd-simple-error () () (:auto t))
1.15+
1.16+(defun zstdc (octets &optional (level 3))
1.17+ (let ((len (length octets)))
1.18+ (with-alien ((in (* (unsigned 8)) (make-alien (unsigned 8) len))
1.19+ (out (* (unsigned 8)) (make-alien (unsigned 8) (zstd-compressbound len))))
1.20+ (clone-octets-to-alien octets in)
1.21+ (let ((csize (zstd-compress out len in len level)))
1.22+ (if (= 1 (zstd-iserror csize))
1.23+ (zstd-simple-error (zstd-geterrorname csize))
1.24+ (coerce
1.25+ (loop for i from 0 below csize
1.26+ collect (deref out i))
1.27+ 'vector))))))
1.28+
1.29+(defun zstdd (octets &optional (capacity 4096))
1.30+ (let ((len (length octets)))
1.31+ (with-alien ((in (* (unsigned 8)) (make-alien (unsigned 8) len)))
1.32+ (clone-octets-to-alien octets in)
1.33+ (with-alien ((out (* (unsigned 8)) (make-alien (unsigned 8) capacity)))
1.34+ (let ((dsize (zstd-decompress out capacity in len)))
1.35+ (if (= 1 (zstd-iserror dsize))
1.36+ (zstd-simple-error (zstd-geterrorname dsize))
1.37+ (coerce
1.38+ (loop for i from 0 below dsize
1.39+ collect (deref out i))
1.40+ 'vector)))))))
1.41+
1.42+;; (zstdd (zstdc (make-array 4000 :initial-element (random 255) :element-type 'integer) 22))