on master help sign in
Removed lazy IO
bf9c588Michael Snoyman
Network/Wai.hs+9−2
@@ -23,6 +23,8 @@ module Network.Wai
23import qualified Data.ByteString.Lazy as L
23import qualified Data.ByteString.Lazy as L
24import qualified Data.ByteString as B
24import qualified Data.ByteString as B
25import qualified Data.ByteString.Char8 as B8
25import qualified Data.ByteString.Char8 as B8
26+import System.IO (withBinaryFile, IOMode (ReadMode), hIsEOF)
27+import Control.Monad (unless)
26
28
27-- | Please do not use the Show and Read instances for anything other than
29-- | Please do not use the Show and Read instances for anything other than
28-- debugging purposes. Instead, the 'methodFromBS' and 'methodToBS' provide a
30-- debugging purposes. Instead, the 'methodFromBS' and 'methodToBS' provide a
@@ -121,8 +123,13 @@ class ResponseBodyClass a where
121 sendLazyByteString a bs = mapM_ (sendByteString a) $ L.toChunks bs
123 sendLazyByteString a bs = mapM_ (sendByteString a) $ L.toChunks bs
122
124
123 sendFile :: a -> FilePath -> IO ()
125 sendFile :: a -> FilePath -> IO ()
124− -- FIXME do not use lazy I/O
126+ sendFile a fp = withBinaryFile fp ReadMode helper where
125− sendFile a fp = L.readFile fp >>= sendLazyByteString a
127+ helper h = do
128+ eof <- hIsEOF h
129+ unless eof $ do
130+ b <- B.hGet h 1024 -- FIXME determine better block size
131+ sendByteString a b
132+ helper h
126instance ResponseBodyClass ResponseBody where
133instance ResponseBodyClass ResponseBody where
127 sendByteString (ResponseBody a) = sendByteString a
134 sendByteString (ResponseBody a) = sendByteString a
128 sendLazyByteString (ResponseBody a) = sendLazyByteString a
135 sendLazyByteString (ResponseBody a) = sendLazyByteString a