@@ -3,6 +3,7 @@ module Network.Wai.Source
33 -- * Conversions
44 toEnumerator
55 , toLBS
6+ , fromLBS
67 ) where
78
89import Network.Wai
@@ -35,3 +36,11 @@ toLBS source0 = L.fromChunks `fmap` helper source0 where
3536 Just (bs, source') -> do
3637 rest <- helper source'
3738 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)