mirror of
https://github.com/janet-lang/janet
synced 2025-01-13 09:00:26 +00:00
Add slurp and spit to the core library.
This commit is contained in:
parent
d1a075b2a6
commit
48b179d67e
@ -1705,5 +1705,24 @@ value, one key will be ignored."
|
||||
(put symbol-set k true))
|
||||
(sort (keys symbol-set)))
|
||||
|
||||
(defn slurp
|
||||
"Read all data from a file with name path
|
||||
and then close the file."
|
||||
[path]
|
||||
(def f (file/open path :r))
|
||||
(def contents (file/read f :all))
|
||||
(file/close f)
|
||||
contents)
|
||||
|
||||
(defn spit
|
||||
"Write contents to a file at path.
|
||||
Can optionally append to the file."
|
||||
[path contents mode &]
|
||||
(default mode :w)
|
||||
(def f (file/open path mode))
|
||||
(file/write f contents)
|
||||
(file/close f)
|
||||
nil)
|
||||
|
||||
# Use dynamic *env* from now on
|
||||
(put _env '_env nil)
|
||||
|
Loading…
Reference in New Issue
Block a user