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.