Hello,
How can I read the contents of a textfile into a string in clojurescript? I've only found some information about how to do this in Clojure. http://clojuredocs.org/clojure_core/clojure.core/slurp But not how to use this in clojurescript. If I put this:
(:use [clojure.walk :only [walk]]
[clojure.core :only [slurp]])
in my namespace declaration I receive an error : Uncaught Error: goog.require could not find: clojure.core . Does anybody has an idea how I can manage to read the contents of a file into a string.
Thanks
--
Note that posts from new members are moderated - please be patient with your first post.
---
You received this message because you are subscribed to the Google Groups "ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojurescrip...@googlegroups.com.
To post to this group, send email to clojur...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript?hl=en.
or, you could try accessing the javascript filesystem api if you really want to read from the local filesystem.
http://www.html5rocks.com/en/tutorials/file/filesystem/
chrome only.
On Saturday, 2 March 2013 13:32:58 UTC+11, Evan Mezeske wrote:
> Reading a file is a platform-specific thing in JavaScript (ugh), and AFAIK there is not currently any abstraction in ClojureScript that allows you to read a file in a platform-independent way.
>
> If you are running on node.js, which I assume you are because you want to read a file, you can use JS interop to use node's API for reading files:
>
> http://docs.nodejitsu.com/articles/file-system/how-to-read-files-in-nodejs
>
> I have not run this code, so I'm sure it's horribly broken, but this is a rough idea of what that node.js example would look like in ClojureScript:
>
> (let [fs (.require "fs")]
> (.readFile fs "/etc/hosts" "utf8" (fn [err data]
> (.log console (or err data)))))