Baishampayan Ghose <b.gh...@ocricket.com> writes: > Hello, > > I was trying to download a zip file using clojure.contrib.http.agent and > writing it to a file using clojure.contrib.duck-streams. > > Apparently the zip file is getting corrupt because I was trying to treat > the stream as a string. > > Is there any way to use duck-streams to write data as binary? > > I looked at the code but I am not sure about the exact way to do it. I > can probably use straight Java interop, but I would rather use the > contrib lib.
"reader" and "writer" from duck streams are intended only for character streams and AFAIK there are no binary counterparts available so far. So the only way is to use Java streams directly. This is what I came up with: <code> (ns test-http (:require [clojure.contrib.duck-streams :as ds] [clojure.contrib.http.agent :as http]) (:import [java.io FileOutputStream])) (await (http/http-agent "http://clojure.googlecode.com/files/clojure_1.0.0.zip" :handler (fn [agnt] (with-open [w (FileOutputStream. "clojure.zip")] (ds/copy (http/stream agnt) w))))) (shutdown-agents) </code> HTH, Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---