O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

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 Nothingsignalling 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required