A Few Quick Notes About babashka/fs


Recently I've used babashka/fs a little bit, here are some quick notes for it:

  • Path vs File. Use Path whenever possible, according to this SO answer to "Java: Path vs File". This is actually Java related.
  • It's ok to use a path as a key for a clojure map. At my first try, I somehow came to the conclusion that it's not ok, while I was refactoring the live reload for clay. And later I found that it's totally fine to use it as a key. 😞
  • Use fs/path to construct file/directory paths, for example, (fs/path "/tmp" "foo" "bar" "baz.clj") will result in a path object for /tmp/foo/bar/baz.clj on linux. If you're coming from Python, it might remind you of os.path.join(path, *paths).
  • Use fs/createdirs for mkdir -p, though its name is a bit misleading, I first thought it's for creating a few dirs.
  • fs/with-temp-dir is convenient for creating tests.

See also

comments powered by Disqus