Updated version to 2.1.
[salza2.git] / zlib.lisp
blobe5df7188dff26d549f50ac351e3e926ede6b8f36
1 ;;;
2 ;;; Copyright (c) 2007 Zachary Beane, All Rights Reserved
3 ;;;
4 ;;; Redistribution and use in source and binary forms, with or without
5 ;;; modification, are permitted provided that the following conditions
6 ;;; are met:
7 ;;;
8 ;;; * Redistributions of source code must retain the above copyright
9 ;;; notice, this list of conditions and the following disclaimer.
10 ;;;
11 ;;; * Redistributions in binary form must reproduce the above
12 ;;; copyright notice, this list of conditions and the following
13 ;;; disclaimer in the documentation and/or other materials
14 ;;; provided with the distribution.
15 ;;;
16 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
17 ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 ;;;
29 (in-package #:salza2)
31 (defclass zlib-compressor (deflate-compressor)
32 ((adler32
33 :initarg :adler32
34 :accessor adler32))
35 (:default-initargs
36 :adler32 (make-instance 'adler32-checksum)))
38 (defmethod start-data-format :before ((compressor zlib-compressor))
39 ;; FIXME: Replace these naked constants with symbolic constants.
40 (write-octet #x78 compressor)
41 (write-octet #x9C compressor))
43 (defmethod process-input :after ((compressor zlib-compressor) input start count)
44 (let ((checksum (adler32 compressor)))
45 (update checksum input start count)))
47 (defmethod finish-data-format :after ((compressor zlib-compressor))
48 (dolist (octet (result-octets (adler32 compressor)))
49 (write-octet octet compressor)))
51 (defmethod reset :after ((compressor zlib-compressor))
52 (reset (adler32 compressor)))