Mercurial > core / lisp/lib/io/flate.lisp
changeset 698: |
96958d3eb5b0 |
parent: |
804b5ee20a46
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
1 ;;; io/flate.lisp --- Compressed IO Interface 3 ;; Use compression (ZSTD) with Lisp objects and streams. 7 ;; compression ref: https://www.xach.com/lisp/salza2/ (compression only) 9 ;; decompression ref: https://github.com/sharplispers/chipz (decompression only) 11 ;; The libraries above are the current state-of-the-art for compression and 12 ;; decompression in Common Lisp. They are portable packages which depend on 13 ;; gray streams. They loosely cover deflate, zlib, gzip, and bzip2 data. 15 ;; The compression backends are themselves hand-coded in Common Lisp, making 16 ;; them excellent reference material. However, we don't have much use for the 17 ;; compression backends offered. 19 ;; We intend to almost exclusively support Zstd compression and decompression 20 ;; using our ZSTD FFI Lisp system, so we'll make a new library - FLATE - which 21 ;; provides a shared zstd compression/decompression to Lisp objects and 25 (in-package :io/flate) 28 (defparameter *compression-buffer-size* 4096) 29 (defparameter *decompression-buffer-size* 4096) 30 (defparameter *default-compression-level* (zstd:zstd-defaultclevel)) 32 (defvar *compression-level*) 37 (eval-always (deferror flate-error () () (:auto t))) 39 (deferror compression-error (flate-error) () (:auto t)) 40 (deferror decompression-error (flate-error) () (:auto t)) 43 (defgeneric finish-compression (self)) 44 (defgeneric finish-decompression (self)) 45 ;; TODO 2024-06-08: maybe move this to generic io/stream protocol - 'RESET' 46 (defgeneric reset-compressor (self)) 47 (defgeneric reset-decompressor (self)) 48 (defgeneric make-compressed-stream (&optional stream)) 49 (defgeneric make-decompressed-stream (&optional stream)) 50 (defgeneric compress-object (self)) 51 (defgeneric decompress-object (self)) 53 (defgeneric compress (input output state)) 54 (defgeneric decompress (input output state)) 63 ;; compress-octet-vector 65 ;; finish-compression (finish-output?) 69 ;; make-compressed-stream 71 (defclass compressor () ()) 73 (defclass compressed-stream (fundamental-binary-stream) 81 ;; We provide several convenience functions for decompression: 83 ;; * decompress a buffer to a newly-consed buffer; 84 ;; * decompress a stream to a newly-consed buffer; 85 ;; * decompress a pathname to a newly-consed buffer; 86 ;; * decompress a buffer to a user-specified buffer; 87 ;; * decompress a buffer to a stream; 88 ;; * decompress a stream to a stream. 89 ;; * decompress a pathname to another pathname; 90 ;; * decompress a pathname to a stream; 92 ;; We do not provide stream->buffer decompression, as we have no way of 93 ;; knowing how much to read from the stream to fill the buffer, no way 94 ;; of determining what to do with possible state left in the 95 ;; INFLATE-STATE that we used, etc. Application-specific logic will 96 ;; have to handle those bits. 98 ;; make-decompressed-stream 100 ;; decompress-octet-vector 102 (defclass decompressor () ()) 104 (defclass decompressed-stream (fundamental-binary-stream)