<< Back to previous view

[CONTRIB-63] duck-streams open as resource what isn't File or URL Created: 26/Jan/10  Updated: 24/Aug/10  Resolved: 24/Aug/10

Status: Closed
Project: Clojure-Contrib
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect
Reporter: Anonymous Assignee: Stuart Halloway
Resolution: Declined Votes: 0
Labels: None


 Description   

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.



 Comments   
Comment by Assembla Importer [ 24/Aug/10 3:04 PM ]

Converted from http://www.assembla.com/spaces/clojure/tickets/63
Attachments:
0001-teach-duck-streams-classpath-on62.patch - https://www.assembla.com/spaces/clojure/documents/a8_B2gcSmr37PueJe5aVNr/download/a8_B2gcSmr37PueJe5aVNr
0001-teach-duck-streams-classpath.patch - https://www.assembla.com/spaces/clojure/documents/a8_zgOcSmr37PueJe5aVNr/download/a8_zgOcSmr37PueJe5aVNr

Comment by Assembla Importer [ 24/Aug/10 3:04 PM ]

stuart.sierra said: Updating tickets (#1, #2, #3, #4, #6, #20, #23, #25, #30, #31, #33, #34, #35, #37, #38, #52, #55, #58, #59, #60, #61, #62, #63, #64)

Comment by Assembla Importer [ 24/Aug/10 3:04 PM ]

stu said: I am going to reject this patch for now, because I don't like:

  1. 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?
  2. 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.

Comment by Assembla Importer [ 24/Aug/10 3:04 PM ]

bpsm said: Fair enough. The overloaded meaning of 'path-like-string' isn't pretty. As an alternative, perhaps you would consider including:

(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))
</code></pre>
This would allow formulations like:
<pre>{{(input-stream (resource "foo/bar.gif"))}}</pre>
or even:
<pre><code>(-?> "foo/bar.gif" resource input-stream)

Which is reasonably compact and makes the meaning of the string clear.

Generated at Wed Jul 30 18:26:43 CDT 2014 using JIRA 4.4#649-r158309.