application/octet-stream
•
1.18 KB
•
34 lines
(defun read-file (path)
(declare (type (or pathname string) path))
(let ((data (make-array 0 :element-type '(unsigned-byte 8) :adjustable t))
(block-size 4096)
(offset 0))
(with-open-file (file path :element-type '(unsigned-byte 8))
(loop
(let* ((capacity (array-total-size data))
(nb-left (- capacity offset)))
(when (< nb-left block-size)
(let ((new-length (max (+ capacity (- block-size nb-left))
(floor (* capacity 3) 2))))
(setf data (adjust-array data new-length)))))
(let ((end (read-sequence data file :start offset)))
(when (= end offset)
(return-from read-file (adjust-array data end)))
(setf offset end))))))
(compile 'read-file)
(defun adler32 (bv)
(let ((a 1)
(b 0))
(dotimes (i (length bv))
(setf a (mod (+ a (aref bv i)) 65521))
(setf b (mod (+ a b) 65521))
(format T "~a ~a~%" a b))
(logior a (ash b 16))))
(compile 'adler32)
(defun adler32-file (filename)
(format T "~%~X ~a ADLER32~%" (adler32 (read-file filename)) filename))
;(adler32-file "test-files/r5rs.pdf")
(adler32-file "test")