diff options
author | Colin Okay <cbeok@protonmail.com> | 2020-07-08 12:07:08 -0500 |
---|---|---|
committer | Colin Okay <cbeok@protonmail.com> | 2020-07-08 12:07:08 -0500 |
commit | a671a67d368bbf1d14338932cf844d6999c33a13 (patch) | |
tree | f7079b741659ff48de1440b5011f8db3dcc78521 | |
parent | 794ea388d43d474d9666d9b67d0ec0ede163b94d (diff) |
file stream backed generator constructors take streams or paths
-rw-r--r-- | gtwiwtg.lisp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/gtwiwtg.lisp b/gtwiwtg.lisp index 87f2bad..c150a60 100644 --- a/gtwiwtg.lisp +++ b/gtwiwtg.lisp @@ -175,10 +175,13 @@ But this isn't: (values nil stream))))))) -(defun file-lines (path) +(defun file-lines (file) "Creates a generator that produces the lines of a file. The stream to the file is closed when the generator finishes. +FILE is either a path to a file, or is an open character input stream +to a file. + Returns NIL on the last iteration. Avoid using with TAKE or PICK-OUT as the file stream will not be closed. @@ -190,13 +193,16 @@ within an UNWIND-PROTECTing form such as WITH-OPEN-FILE. See the documentation for FROM-INPUT-STREAM for an example of the distinction. " - (from-input-stream (open path) + (from-input-stream (if (streamp file) file (open file)) (lambda (stream) (read-line stream nil nil)))) -(defun file-chars (path) +(defun file-chars (file) "Creates a generator that produces the characters of a file. The stream to the file is closed when the generator finishes. +FILE is either a path to a file, or is an open character input stream +to a file. + Returns NIL on the last iteration. Avoid using with TAKE or PICK-OUT as the file stream will not be closed. @@ -209,13 +215,16 @@ See the documentation for FROM-INPUT-STREAM for an example of the distinction. " - (from-input-stream (open path) + (from-input-stream (if (streamp file) file (open file)) (lambda (stream) (read-char stream nil nil)))) -(defun file-bytes (path) +(defun file-bytes (file) "Creates a generator that produces the bytes of a file. The stream to the file is closed when the generator finishes. +FILE is either a path to a file, or is an open byte input stream to a +file. + Returns NIL on the last iteration. Avoid using with TAKE or PICK-OUT as the file stream will not be closed. @@ -226,9 +235,9 @@ within an UNWIND-PROTECTing form such as WITH-OPEN-FILE. See the documentation for FROM-INPUT-STREAM for an example of the distinction. - " - (from-input-stream (open path :element-type '(unsigned-byte 8)) + (from-input-stream (if (streamp file) file + (open file :element-type '(unsigned-byte 8))) (lambda (stream) (read-byte stream nil nil)))) ;;; Some utilities |