Clojure-Contrib

duck-streams open as resource what isn't File or URL

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • 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.

Activity

Hide
Assembla Importer added a comment -

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.

Show
Assembla Importer added a comment - 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.
Hide
Assembla Importer added a comment -

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.

Show
Assembla Importer added a comment - 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.
Hide
Assembla Importer added a comment -

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)

Show
Assembla Importer added a comment - 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)

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: