diff --git a/fd-flexi.lisp b/fd-flexi.lisp
index 63be835..6936e12 100644
--- a/fd-flexi.lisp
+++ b/fd-flexi.lisp
@@ -18,11 +18,38 @@
(in-package :fd-flexi)
-(defun stream (fd &key (external-format :utf-8))
- (make-flexi-stream (make-instance 'fd-gray:stream :fd fd)
+(defun input-stream (fd &optional (external-format :utf-8))
+ (make-flexi-stream (fd-gray:input-stream fd)
:external-format external-format))
-(defmacro with-stream ((var fd &key (external-format :utf-8)) &body body)
- `(let ((,var (stream ,fd :external-format ,external-format)))
- (unwind-protect (progn ,@body)
- (close ,var))))
+(defmacro with-input-stream ((var fd &optional (external-format :utf-8))
+ &body body)
+ (let ((stream (gensym "STREAM-")))
+ `(let ((,stream (input-stream ,fd ,external-format)))
+ (unwind-protect (let ((,var ,stream))
+ ,@body)
+ (close ,stream)))))
+
+(defun output-stream (fd &optional (external-format :utf-8))
+ (make-flexi-stream (fd-gray:output-stream fd)
+ :external-format external-format))
+
+(defmacro with-output-stream ((var fd &optional (external-format :utf-8))
+ &body body)
+ (let ((stream (gensym "STREAM-")))
+ `(let ((,stream (output-stream ,fd ,external-format)))
+ (unwind-protect (let ((,var ,stream))
+ ,@body)
+ (close ,stream)))))
+
+(defun io-stream (fd &optional (external-format :utf-8))
+ (make-flexi-stream (fd-gray:io-stream fd)
+ :external-format external-format))
+
+(defmacro with-io-stream ((var fd &optional (external-format :utf-8))
+ &body body)
+ (let ((stream (gensym "STREAM-")))
+ `(let ((,stream (io-stream ,fd ,external-format)))
+ (unwind-protect (let ((,var ,stream))
+ ,@body)
+ (close ,stream)))))
diff --git a/package.lisp b/package.lisp
index 29067a0..4285253 100644
--- a/package.lisp
+++ b/package.lisp
@@ -25,5 +25,9 @@
(:shadow
#:stream)
(:export
- #:stream
- #:with-stream))
+ #:input-stream
+ #:with-input-stream
+ #:output-stream
+ #:with-output-stream
+ #:io-stream
+ #:with-io-stream))