on master help sign in
Added LBS -> Source conversion
636ec55Michael Snoyman
Network/Wai/Source.hs+9
@@ -3,6 +3,7 @@ module Network.Wai.Source
3 -- * Conversions
3 -- * Conversions
4 toEnumerator
4 toEnumerator
5 , toLBS
5 , toLBS
6+ , fromLBS
6 ) where
7 ) where
7
8
8import Network.Wai
9import Network.Wai
@@ -35,3 +36,11 @@ toLBS source0 = L.fromChunks `fmap` helper source0 where
35 Just (bs, source') -> do
36 Just (bs, source') -> do
36 rest <- helper source'
37 rest <- helper source'
37 return $ bs : rest
38 return $ bs : rest
39+
40+-- | Convert a lazy bytestring to a 'Source'. This operation does not request lazy I\/O.
41+fromLBS :: L.ByteString -> Source
42+fromLBS =
43+ go . L.toChunks
44+ where
45+ go [] = Source $ return Nothing
46+ go (x:xs) = Source $ return $ Just (x, go xs)