Commit 0cdbdb6d authored by Pascal J. Bourguignon's avatar Pascal J. Bourguignon

Added filter-stream.

parent 9d49004e
......@@ -59,6 +59,7 @@ specifications, like GRAY or other portability libraries.
#+(or ccl clisp sbcl cmu) "com.informatimago.clext.closer-weak"
#+(or ccl clisp sbcl cmu) "com.informatimago.clext.pipe"
"com.informatimago.clext.queue"
"com.informatimago.clext.filter-stream"
"com.informatimago.clext.redirecting-stream")
:components ()
#+adsf3 :in-order-to
......
;;;; -*- mode:lisp;coding:utf-8 -*-
;;;;**************************************************************************
;;;;FILE: com.informatimago.clext.filter-stream.asd
;;;;LANGUAGE: Common-Lisp
;;;;SYSTEM: Common-Lisp
;;;;USER-INTERFACE: NONE
;;;;DESCRIPTION
;;;;
;;;; ASD file to load the com.informatimago.clext.filter-stream library.
;;;;
;;;;AUTHORS
;;;; <PJB> Pascal J. Bourguignon <pjb@informatimago.com>
;;;;MODIFICATIONS
;;;; 2015-09-12 <PJB> Created this .asd file.
;;;;BUGS
;;;;LEGAL
;;;; AGPL3
;;;;
;;;; Copyright Pascal J. Bourguignon 2017 - 2017
;;;;
;;;; This program is free software: you can redistribute it and/or modify
;;;; it under the terms of the GNU Affero General Public License as published by
;;;; the Free Software Foundation, either version 3 of the License, or
;;;; (at your option) any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;;; GNU Affero General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU Affero General Public License
;;;; along with this program. If not, see http://www.gnu.org/licenses/
;;;;**************************************************************************
#+mocl
(asdf:defsystem "com.informatimago.clext.filter-stream"
;; system attributes:
:description "Informatimago Common Lisp Extensions: Filter-Streams."
:long-description "
This system would use TRIVIAL-GRAY-STREAMS, which is not available on MOCL.
"
:author "Pascal J. Bourguignon <pjb@informatimago.com>"
:maintainer "Pascal J. Bourguignon <pjb@informatimago.com>"
:licence "AGPL3"
;; component attributes:
:version "1.0.0"
:properties ((#:author-email . "pjb@informatimago.com")
(#:date . "Summer 2015")
((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.clext/")
((#:albert #:formats) . ("docbook"))
((#:albert #:docbook #:template) . "book")
((#:albert #:docbook #:bgcolor) . "white")
((#:albert #:docbook #:textcolor) . "black"))
#+asdf-unicode :encoding #+asdf-unicode :utf-8
:depends-on ()
:components ())
#-mocl
(asdf:defsystem "com.informatimago.clext.filter-stream"
;; system attributes:
:description "Informatimago Common Lisp Extensions: Filter-Streams."
:long-description "
This Gray stream filters the data.
"
:author "Pascal J. Bourguignon <pjb@informatimago.com>"
:maintainer "Pascal J. Bourguignon <pjb@informatimago.com>"
:licence "AGPL3"
;; component attributes:
:version "1.0.0"
:properties ((#:author-email . "pjb@informatimago.com")
(#:date . "Spring 2017")
((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.clext/")
((#:albert #:formats) . ("docbook"))
((#:albert #:docbook #:template) . "book")
((#:albert #:docbook #:bgcolor) . "white")
((#:albert #:docbook #:textcolor) . "black"))
:depends-on ("trivial-gray-streams"
"bordeaux-threads")
:components ((:file "filter-stream"))
;; #+adsf3 :in-order-to #+adsf3 ((asdf:test-op (asdf:test-op "com.informatimago.clext.filter-stream.test")))
#+asdf-unicode :encoding #+asdf-unicode :utf-8)
;;;; THE END ;;;;
......@@ -5,30 +5,34 @@
;;;;SYSTEM: Common-Lisp
;;;;USER-INTERFACE: NONE
;;;;DESCRIPTION
;;;;
;;;;
;;;; Filter streams are stream wrappers with a function to process
;;;; the data being input or output.
;;;;
;;;;
;;;;AUTHORS
;;;; <PJB> Pascal J. Bourguignon <pjb@informatimago.com>
;;;;MODIFICATIONS
;;;; 2017-04-16 <PJB> Close is also defered to the filter function.
;;;; Now all operations can be performed by the filter
;;;; function and the filter-stream stream can be any
;;;; object, not necessarily a stream.
;;;; 2016-12-22 <PJB> Created.
;;;;BUGS
;;;;LEGAL
;;;; AGPL3
;;;;
;;;;
;;;; Copyright Pascal J. Bourguignon 2016 - 2016
;;;;
;;;;
;;;; This program is free software: you can redistribute it and/or modify
;;;; it under the terms of the GNU Affero General Public License as published by
;;;; the Free Software Foundation, either version 3 of the License, or
;;;; (at your option) any later version.
;;;;
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;;; GNU Affero General Public License for more details.
;;;;
;;;;
;;;; You should have received a copy of the GNU Affero General Public License
;;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;;;**************************************************************************
......@@ -72,7 +76,7 @@
:function filter-function
:stream stream)))
(defun make-outpout-filter-stream (stream filter-function &key element-type)
(defun make-output-filter-stream (stream filter-function &key element-type)
(let ((element-type (or element-type (stream-element-type stream))))
(make-instance (if (subtypep element-type 'character)
'filter-character-output-stream
......@@ -189,20 +193,28 @@
(defmethod close ((stream filter-character-output-stream) &key abort)
(declare (ignore abort))
(close (filter-stream-stream stream)))
(funcall (filter-stream-function stream)
'close
(filter-stream-stream stream)
abort))
(defmethod close ((stream filter-binary-output-stream) &key abort)
(declare (ignore abort))
(close (filter-stream-stream stream)))
(funcall (filter-stream-function stream)
'close
(filter-stream-stream stream)
abort))
(defmethod close ((stream filter-character-input-stream) &key abort)
(declare (ignore abort))
(close (filter-stream-stream stream)))
(funcall (filter-stream-function stream)
'close
(filter-stream-stream stream)
abort))
(defmethod close ((stream filter-binary-input-stream) &key abort)
(declare (ignore abort))
(close (filter-stream-stream stream)))
(funcall (filter-stream-function stream)
'close
(filter-stream-stream stream)
abort))
;; binary input
......@@ -296,6 +308,7 @@
(write-byte (write-byte (first arguments) stream))
;; both:
(read-sequence (read-sequence (first arguments) stream :start (second arguments) :end (third arguments)))
(write-sequence (write-sequence (first arguments) stream :start (second arguments) :end (third arguments)))))
(write-sequence (write-sequence (first arguments) stream :start (second arguments) :end (third arguments)))
(close (close stream :abort (first arguments)))))
;;;; THE END ;;;;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment