summaryrefslogtreecommitdiff
path: root/file.lisp
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2025-11-04 17:53:41 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2025-11-04 17:53:41 -0300
commit4e6aae19275dad2053adbc2ad34ab1330daf1b0f (patch)
tree0f6d08e48b06be9ee48ca6848289068ea228112c /file.lisp
parentd2a8d3a2171ebbc9934e3703a0f9b6fd4070a6b8 (diff)
downloadlempel-4e6aae19275dad2053adbc2ad34ab1330daf1b0f.tar.gz
lempel-4e6aae19275dad2053adbc2ad34ab1330daf1b0f.zip
Working decoder on byte level
Diffstat (limited to 'file.lisp')
-rw-r--r--file.lisp29
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)))