From 4e6aae19275dad2053adbc2ad34ab1330daf1b0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Tue, 4 Nov 2025 17:53:41 -0300 Subject: Working decoder on byte level --- file.lisp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 file.lisp (limited to 'file.lisp') 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))) -- cgit v1.2.3