bfs.cljs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. (ns frontend.fs.bfs
  2. (:require [frontend.fs.protocol :as protocol]
  3. [frontend.util :as util]
  4. [promesa.core :as p]))
  5. (defrecord Bfs []
  6. protocol/Fs
  7. (mkdir! [this dir]
  8. (when (and js/window.pfs (not (util/electron?)))
  9. (->
  10. (js/window.pfs.mkdir dir)
  11. (p/catch (fn [error] (println "Mkdir error: " error))))))
  12. (readdir [this dir]
  13. (when js/window.pfs
  14. (js/window.pfs.readdir dir)))
  15. (unlink! [this repo path opts]
  16. (when js/window.pfs
  17. (p/let [stat (js/window.pfs.stat path)]
  18. (if (= (.-type stat) "file")
  19. (js/window.pfs.unlink path opts)
  20. (p/rejected "Unlinking a directory is not allowed")))))
  21. (rmdir! [this dir]
  22. (js/window.workerThread.rimraf dir))
  23. (read-file [this dir path options]
  24. (js/window.pfs.readFile (str dir "/" path) (clj->js options)))
  25. (write-file! [this repo dir path content opts]
  26. (when-not (util/electron?)
  27. (js/window.pfs.writeFile (str dir "/" path) content)))
  28. (rename! [this repo old-path new-path]
  29. (js/window.pfs.rename old-path new-path))
  30. (stat [this dir path]
  31. (js/window.pfs.stat (str dir path)))
  32. (open-dir [this ok-handler]
  33. nil)
  34. (get-files [this path-or-handle ok-handler]
  35. nil)
  36. (watch-dir! [this dir]
  37. nil))