Skip to content

Instantly share code, notes, and snippets.

@rpav
Created June 10, 2016 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpav/a01c6f677fade725b43ac0b2d0f7bdd0 to your computer and use it in GitHub Desktop.
Save rpav/a01c6f677fade725b43ac0b2d0f7bdd0 to your computer and use it in GitHub Desktop.
;; This assumes conspack, salza2, and chipz are loaded
(defun compress (thing)
(cpk:encode
(salza2:compress-data (cpk:encode thing)
'salza2:gzip-compressor)))
(defun decompress (thing)
(cpk:decode (chipz:decompress nil 'chipz:gzip thing)))
(let ((array (make-array 1000000 :element-type '(unsigned-byte 8))))
(with-open-file (out "somefile.cpk"
:direction :output
:if-exists :supersede
:element-type '(unsigned-byte 8))
(loop for i from 0 below 10
as chunk = (compress array)
do (write-sequence chunk out))))
(with-open-file (in "somefile.cpk"
:direction :input
:element-type '(unsigned-byte 8))
(loop with eof = nil
as object = (handler-case
(cpk:decode-stream in)
(end-of-file () (setf eof t) (values)))
until eof
do (let ((thing (decompress object)))
(format t "thing = ~S~%" (type-of thing)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment