The fs namespace is a convenience wrapper around the node file system module.
all functions will throw immediately if given the wrong type. This is a different class of error vs. an actual IO exception, which may be handled differently
Predicates
IO operations
[err]
or [err data]
depending on the operation.
err
will be nil
. This lets you destructure the result and branch on err(let [[err data] (<! afn)]
(if-not err
(handle-result data)
(handle-error err)))
In busy processes, it is strongly encouraged to use the asynchronous versions of these calls. The synchronous versions will block the entire process until they complete--halting all connections.
The relative path to a filename can be used. Remember, however, that this path will be relative to process.cwd()
.
Asynchronous methods have no ordering guarantee...so things like the following are error prone ...It could be that astat
is run before arename
(def rc (arename "/tmp/hello" "/tmp/world"))
(def sc (astat "tmp/world"))
(take! rc
(fn [[e]]
(if-not e
(println "rename completed!")
(throw res))))
(take! sc
(fn [[sterr st]]
(if-not sterr
(println (js/JSON.stringify res))
(throw res))))
(go
(let [[rerr] (<! (arename "/tmp/hello" "/tmp/world"))]
(if-not rerr
(let [[sterr st] (<! (astat "/tmp/world"))]
(if-not sterr
(println (js/JSON.stringify st))
(throw sterr)))
(throw rerr))))
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close