1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-28 11:09:54 +00:00

file/linex now only acceps a file, not a path name

This commit is contained in:
Ico Doornekamp 2023-05-26 17:50:26 +02:00
parent 64e3cdeb2b
commit 09345ec786
2 changed files with 9 additions and 13 deletions

View File

@ -1749,18 +1749,13 @@
(printf (dyn *pretty-format* "%q") x) (printf (dyn *pretty-format* "%q") x)
(flush)) (flush))
(defn file/lines (defn file/lines
"Return an iterator over the lines of a file" "Return an iterator over the lines of a file."
[file-or-path &opt mode] [file]
(default mode :r) (coro
(if (bytes? file-or-path) (while (def line (file/read file :line))
(coro (yield line))))
(with [f (file/open file-or-path mode)]
(while (def line (file/read f :line))
(yield line))))
(coro
(while (def line (file/read file-or-path :line))
(yield line)))))
### ###
### ###

View File

@ -110,8 +110,9 @@
(defer (:close outstream) (defer (:close outstream)
(:write outstream buf1)) (:write outstream buf1))
(var buf2 "") (var buf2 "")
(each line (file/lines "unique.txt") (with [f (file/open "unique.txt" :r)]
(set buf2 (string buf2 line))) (each line (file/lines f)
(set buf2 (string buf2 line))))
(assert (= buf1 buf2) "file/lines iterator") (assert (= buf1 buf2) "file/lines iterator")
(os/rm "unique.txt")) (os/rm "unique.txt"))