on master help sign in
Add putStrings
4bdebf1Harendra Kumar
src/Streamly/Internal/FileSystem/Handle.hs+13
@@ -59,6 +59,7 @@ module Streamly.Internal.FileSystem.Handle
59 , fromChunksWithBufferOf
59 , fromChunksWithBufferOf
60 , fromChunks
60 , fromChunks
61 , putChunks
61 , putChunks
62+ , putStrings
62
63
63 -- -- * Random Access (Seek)
64 -- -- * Random Access (Seek)
64 -- -- | Unlike the streaming APIs listed above, these APIs apply to devices or
65 -- -- | Unlike the streaming APIs listed above, these APIs apply to devices or
@@ -121,6 +122,7 @@ import Streamly.Streams.StreamK.Type (IsStream, mkStream)
121
122
122import qualified Streamly.Data.Fold as FL
123import qualified Streamly.Data.Fold as FL
123import qualified Streamly.Internal.Data.Fold.Types as FL
124import qualified Streamly.Internal.Data.Fold.Types as FL
125+import qualified Streamly.Internal.Data.Unicode.Stream as U
124import qualified Streamly.Internal.Data.Unfold as UF
126import qualified Streamly.Internal.Data.Unfold as UF
125import qualified Streamly.Internal.Memory.ArrayStream as AS
127import qualified Streamly.Internal.Memory.ArrayStream as AS
126import qualified Streamly.Internal.Prelude as S
128import qualified Streamly.Internal.Prelude as S
@@ -342,6 +344,17 @@ fromChunks h m = S.mapM_ (liftIO . writeArray h) m
342putChunks :: (MonadIO m, Storable a) => SerialT m (Array a) -> m ()
344putChunks :: (MonadIO m, Storable a) => SerialT m (Array a) -> m ()
343putChunks = fromChunks stdout
345putChunks = fromChunks stdout
344
346
347+-- XXX this is currently buffered with 32K buffer. We need to use a timeout
348+-- based scheme instead.
349+--
350+-- | Write a stream of strings to standard output.
351+--
352+-- /Internal/
353+--
354+{-# INLINE putStrings #-}
355+putStrings :: MonadIO m => SerialT m String -> m ()
356+putStrings = fromBytes stdout . U.encodeUtf8 . S.concatUnfold UF.fromList
357+
345-- | @fromChunksWithBufferOf bufsize handle stream@ writes a stream of arrays
358-- | @fromChunksWithBufferOf bufsize handle stream@ writes a stream of arrays
346-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
359-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
347-- The chunk size is only a maximum and the actual writes could be smaller as
360-- The chunk size is only a maximum and the actual writes could be smaller as