0

I'm trying to download an JPG image with an HTTP request in a way that it can be decoded for further processing.

It looks like a combination of the HTTP and the stb-image package should do the trick.

The latter provides a decoding function:

decodeImage :: ByteString -> IO (Either String Image)

Whereas the ByteString must be strict.

The former promises in their docs, that the 'representation of the bytes flowing' is extrensible via a type class, whereas ByteString and String are already provided by their lib. Here is an example of receiving a String:

do
  rsp <- Network.HTTP.simpleHTTP (getRequest "http://url.sth/img.jpg")
  fmap (take 100) (getResponseBody rsp)

I could not figure out how to configure the request in order to receive a ByteString. Could someone help me out here?

Bonus question: It looks like a Byte String is a good choice for this kind of data. Can someone explain the reason for this? And also, in which way it differs from a ByteArray.

Anton Harald
  • 5,772
  • 4
  • 27
  • 61
  • 2
    Any specific reason for using the `http` library instead of other modern ones present ? Note that the package doesn't support https and is mostly in the maintenance phase. – Sibi Jan 23 '17 at 14:57
  • No there is no reason. Was just a lack of information. Actually I just found out now about the HTTPS, which I'd definitely need. HTTP-Conduit then? Or what would you suggest? – Anton Harald Jan 23 '17 at 15:02
  • 2
    http-client or http-conduit: [Here](https://haskell-lang.org/library/http-client)'s a tutorial for the two. – sjakobi Jan 23 '17 at 16:10

0 Answers0