@@ -1,6 +1,7 @@
11{-# OPTIONS_HADDOCK hide #-}
22{-# LANGUAGE CPP #-}
33{-# LANGUAGE BangPatterns #-}
4+{-# LANGUAGE FlexibleContexts #-}
45{-# LANGUAGE MagicHash #-}
56{-# LANGUAGE RecordWildCards #-}
67{-# LANGUAGE UnboxedTuples #-}
@@ -27,6 +28,7 @@ module Streamly.Internal.FileSystem.Handle
2728
2829 , toBytes
2930 , toBytesWithBufferOf
31+ , getBytes
3032
3133 -- -- * Array Read
3234 -- , readArrayUpto
@@ -44,6 +46,7 @@ module Streamly.Internal.FileSystem.Handle
4446 -- , writeUtf8
4547 -- , writeUtf8ByLines
4648 -- , writeByFrames
49+ -- , writeLines
4750 , writeWithBufferOf
4851
4952 -- Byte stream write (Streams)
@@ -60,6 +63,7 @@ module Streamly.Internal.FileSystem.Handle
6063 , fromChunks
6164 , putChunks
6265 , putStrings
66+ -- , putLines
6367
6468 -- -- * Random Access (Seek)
6569 -- -- | Unlike the streaming APIs listed above, these APIs apply to devices or
@@ -111,6 +115,7 @@ import GHC.ForeignPtr (mallocPlainForeignPtrBytes)
111115import System.IO (Handle, hGetBufSome, hPutBuf, stdin, stdout)
112116import Prelude hiding (read)
113117
118+import Streamly (MonadAsync)
114119import Streamly.Data.Fold (Fold)
115120import Streamly.Internal.Data.Unfold.Types (Unfold(..))
116121import Streamly.Internal.Memory.Array.Types
@@ -124,6 +129,7 @@ import qualified Streamly.Data.Fold as FL
124129import qualified Streamly.Internal.Data.Fold.Types as FL
125130import qualified Streamly.Internal.Data.Unicode.Stream as U
126131import qualified Streamly.Internal.Data.Unfold as UF
132+import qualified Streamly.Internal.Memory.Array as IA
127133import qualified Streamly.Internal.Memory.ArrayStream as AS
128134import qualified Streamly.Internal.Prelude as S
129135import qualified Streamly.Memory.Array as A
@@ -245,6 +251,16 @@ toChunks = toChunksWithBufferOf defaultChunkSize
245251getChunks :: (IsStream t, MonadIO m) => t m (Array Word8)
246252getChunks = toChunks stdin
247253
254+-- | Read a stream of bytes from standard input.
255+--
256+-- > getBytes = toBytes stdin
257+--
258+-- /Internal/
259+--
260+{-# INLINE getBytes #-}
261+getBytes :: (IsStream t, MonadIO m) => t m Word8
262+getBytes = toBytes stdin
263+
248264-- | Unfolds a handle into a stream of 'Word8' arrays. Requests to the IO
249265-- device are performed using a buffer of size
250266-- 'Streamly.Internal.Memory.Array.Types.defaultChunkSize'. The
@@ -344,16 +360,13 @@ fromChunks h m = S.mapM_ (liftIO . writeArray h) m
344360putChunks :: (MonadIO m, Storable a) => SerialT m (Array a) -> m ()
345361putChunks = fromChunks stdout
346362
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.
363+-- | Write a stream of strings to standard output using Latin1 encoding.
351364--
352365-- /Internal/
353366--
354367{-# INLINE putStrings #-}
355−putStrings :: MonadIO m => SerialT m String -> m ()
356−putStrings = fromBytes stdout . U.encodeUtf8 . S.concatUnfold UF.fromList
368+putStrings :: MonadAsync m => SerialT m String -> m ()
369+putStrings = putChunks . S.mapM (IA.fromStream . U.encodeLatin1 . S.fromList)
357370
358371-- | @fromChunksWithBufferOf bufsize handle stream@ writes a stream of arrays
359372-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.