packages feed

wai 0.2.1 → 0.2.2

raw patch · 2 files changed

+25/−2 lines, 2 filesdep +directory

Dependencies added: directory

Files

Network/Wai/Enumerator.hs view
@@ -12,8 +12,11 @@     , toSource       -- ** Handle     , fromHandle+    , fromHandleFinally       -- ** FilePath     , fromFile+    , fromFileFinally+    , fromTempFile     , fromResponseBody     ) where @@ -21,10 +24,12 @@ import qualified Network.Wai.Source as Source import qualified Data.ByteString.Lazy as L import qualified Data.ByteString as B+import System.Directory (removeFile) import System.IO (withBinaryFile, IOMode (ReadMode), Handle, hIsEOF) import Data.ByteString.Lazy.Internal (defaultChunkSize) import Control.Concurrent (forkIO) import Control.Concurrent.MVar+import Control.Exception import Control.Monad ((<=<))  -- | Performs a specified conversion on each 'B.ByteString' output by an@@ -105,10 +110,27 @@                 Left a' -> return $ Left a'                 Right a' -> runEnumerator (fromHandle h) iter a' +-- | Wrapper around fromHandle to perform an action after EOF or an exception.+fromHandleFinally :: Handle -> IO a -> Enumerator+fromHandleFinally h onEOF = Enumerator $ \iter a0 ->+                            finally (runEnumerator (fromHandle h) iter a0)+                                    onEOF+ -- | A little wrapper around 'fromHandle' which first opens a file for reading. fromFile :: FilePath -> Enumerator fromFile fp = Enumerator $ \iter a0 -> withBinaryFile fp ReadMode $ \h ->     runEnumerator (fromHandle h) iter a0++-- | Wrapper around fromFile to perform an action after the file is closed.+fromFileFinally :: FilePath -> IO a -> Enumerator+fromFileFinally fp onClose = Enumerator $ \iter a0 ->+                             finally (runEnumerator (fromFile fp) iter a0)+                                     onClose++-- | Enumerator to read and remove a file. Being based on 'fromFileFinally', it+-- ensures the file is removed, even in the presence of exceptions.+fromTempFile :: FilePath -> Enumerator+fromTempFile fp = fromFileFinally fp $ removeFile fp  -- | Since the response body is defined as a 'ResponseBody', this function -- simply reduces the whole value to an enumerator. This can be convenient for
wai.cabal view
@@ -1,5 +1,5 @@ Name:                wai-Version:             0.2.1+Version:             0.2.2 Synopsis:            Web Application Interface. Description:         Provides a common protocol for communication between web aplications and web servers. License:             BSD3@@ -18,7 +18,8 @@  Library   Build-Depends:     base >= 3 && < 5,-                     bytestring >= 0.9 && < 0.10+                     bytestring >= 0.9 && < 0.10,+                     directory >= 1.0 && < 1.1   Exposed-modules:   Network.Wai                      Network.Wai.Enumerator                      Network.Wai.Source