diff options
Diffstat (limited to 'file.lisp')
| -rw-r--r-- | file.lisp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/file.lisp b/file.lisp new file mode 100644 index 0000000..642c5ab --- /dev/null +++ b/file.lisp @@ -0,0 +1,29 @@ +(in-package #:lempel) + +(defun compress-file (input-path output-path) + (let ((file (str:read-file input-path))) + (with-open-file (output output-path + :direction :output + :if-does-not-exist :create + :if-exists :supersede + :element-type '(unsigned-byte 8)) + (write-sequence (prefix-encode (compress file) #xAE) output))) + t) + +(defun decompress-file (input-path output-path) + (let ((file (read-file input-path))) + (with-open-file (output output-path + :direction :output + :if-does-not-exist :create + :if-exists :supersede + :element-type :default) + (write-sequence (prefix-decode file #xAE) output))) + t) + +(declaim (ftype (function (string) (array (unsigned-byte 8))) read-file)) +(defun read-file (path) + (with-open-file (file path :element-type '(unsigned-byte 8)) + (let* ((size (file-length file)) + (buf (make-array size :element-type '(unsigned-byte 8)))) + (read-sequence buf file) + buf))) |
