duck-streams open as resource what isn't File or URL
Currently: When duck-streams is given a string, it attempts to open it for reading as a URL and if that fails it tries the string as a path specifying a File. When the string doesn't specify a readable file either, we fail.
I'd like to see duck-streams try to resolve the string as a resource name before finally giving up.
I'd like to see duck-streams try to resolve the string as a resource name before finally giving up.
Leave a comment
on 2010-04-13 05:16 *
By stuart.halloway
Assigned to set to stuart.halloway
Milestone changed from Backlog to Release 1.2
I am going to reject this patch for now, because I don't like:
Better IMO just to be explicit about hitting the classpath.
- the double-purposing of filelike names. If a "foo/bar" points to something on the classpath, and something different on the filesystem, which one should dominate?
- the asymmetry with writing: you can't write to things on the classpath, so writer and reader would become asymmetric.
Better IMO just to be explicit about hitting the classpath.
Fair enough. The overloaded meaning of 'path-like-string' isn't pretty. As an alternative, perhaps you would consider including:
This would allow formulations like:
or even:
Which is reasonably compact and makes the meaning of the string clear.
(defn #^URL resource
"Return the URL of the named resource on the CLASSPATH.
nil indicates no such resource was found."
[#^String name]
(.getResource (clojure.lang.RT/baseLoader) name))
This would allow formulations like:
(input-stream (resource "foo/bar.gif"))
or even:
(-?> "foo/bar.gif" resource input-stream)
Which is reasonably compact and makes the meaning of the string clear.