blob: 642c5abc66fad661e6e4cf80f46eb8e9875a1598 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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)))
|