The file uploader in the preceding recipe uses the function called foldMultipart. It handles Content-type: multipart/form-data, and handles each chunk. It takes PartFold as an argument. The type PartFold a is defined as follows:
type PartFold a = PartInfo -> InputStream ByteString -> a -> IO a
The data type InputStream can be worked upon by a function read (System.IO.Streams module). This function waits for the data being uploaded, and spits out the contents in part. At the end of the data being uploaded, read produces Nothing, signalling the end of data.
In the preceding recipe, the function foldMultipart works similar to foldr, except that at each folding operation, we can use read to wait for the data being chunked and ...