Browse Source

Lazy write on Streamline

Marcos Dumay de Medeiros 6 years ago
parent
commit
32fef5ed3e
1 changed files with 9 additions and 1 deletions
  1. 9 1
      src/System/IO/Uniform/Streamline.hs

+ 9 - 1
src/System/IO/Uniform/Streamline.hs

@@ -3,7 +3,7 @@
 -- |
 -- Streamline exports a monad that, given an uniform IO target, emulates
 -- character tream IO using high performance block IO.
-module System.IO.Uniform.Streamline (Streamline, withClient, withServer, withTarget, send, receiveLine, lazyRecieveLine, lazyReceiveN, startTls, runAttoparsec, runAttoparsecAndReturn, isSecure, setTimeout, setEcho) where
+module System.IO.Uniform.Streamline (Streamline, withClient, withServer, withTarget, send, send', receiveLine, lazyRecieveLine, lazyReceiveN, startTls, runAttoparsec, runAttoparsecAndReturn, isSecure, setTimeout, setEcho) where
 
 import qualified System.IO.Uniform as S
 import qualified System.IO.Uniform.Network as N
@@ -16,6 +16,7 @@ import Control.Monad.IO.Class
 import System.IO.Error
 import Data.ByteString (ByteString)
 import qualified Data.ByteString as BS
+import qualified Data.ByteString.Lazy as LBS
 import Data.Word8 (Word8)
 import Data.IP (IP)
 
@@ -109,6 +110,13 @@ send r = Streamline $ \cl -> do
   writeF cl r
   return ((), cl)
 
+-- | Sends data from a lazy byte string
+send' :: MonadIO m => LBS.ByteString -> Streamline m ()
+send' r = Streamline $ \cl -> do
+  let dd = LBS.toChunks r
+  mapM (writeF cl) dd
+  return ((), cl)
+
 -- | Receives a line from the streamlined IO target.
 receiveLine :: MonadIO m => Streamline m ByteString
 receiveLine = do