Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"GET" a bytes array instead of a string #43

Closed
Dinduks opened this issue Apr 30, 2013 · 2 comments
Closed

"GET" a bytes array instead of a string #43

Dinduks opened this issue Apr 30, 2013 · 2 comments

Comments

@Dinduks
Copy link
Contributor

Dinduks commented Apr 30, 2013

Hi,

I've search everywhere but couldn't find a hint about how to get a binary file, i.e. an array of bytes instead of a body.

When doing it the normal way, the body's size isn't correct; it's approximatively twice as big as it should. Probably due to the encoding.

My code at the moment:

(let [content-in-bytes (. (:body @p) getBytes)]
  (. file-channel write
    (ByteBuffer/wrap content-in-bytes)
    (:start-offset promises-hash)))

Can someone suggest how I should deal with this?

Thanks!

@shenfeng
Copy link
Member

shenfeng commented May 1, 2013

Hi, with this commit a15fde2,

It's possible to say something like this (modeled after clj-http):

(let [body (:body @(http/get "http://site.com/favicon.ico" {:as :byte-array}))]
  ;; body is a byte array
  ;; other options: :auto, :text :stream
  )
[http-kit "2.1.0-SNAPSHOT"]

Can you help review the API: is the :as option looks good, the :text :auto :byte-array :stream make sense?

@ptaoussanis , any ideas?

@Dinduks
Copy link
Contributor Author

Dinduks commented May 1, 2013

Damn, you're fast! :)
As a user, the API looks fine to me.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants