@@ -36,6 +36,7 @@ module Streamly.Internal.FileSystem.Handle
3636
3737 , toChunksWithBufferOf
3838 , toChunks
39+ , getChunks
3940
4041 -- ** Write to Handle
4142 -- Byte stream write (Folds)
@@ -55,8 +56,9 @@ module Streamly.Internal.FileSystem.Handle
5556 , writeChunksWithBufferOf
5657
5758 -- -- * Array stream Write
58− , fromChunks
5959 , fromChunksWithBufferOf
60+ , fromChunks
61+ , putChunks
6062
6163 -- -- * Random Access (Seek)
6264 -- -- | Unlike the streaming APIs listed above, these APIs apply to devices or
@@ -105,7 +107,7 @@ import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
105107import Foreign.Ptr (minusPtr, plusPtr)
106108import Foreign.Storable (Storable(..))
107109import GHC.ForeignPtr (mallocPlainForeignPtrBytes)
108−import System.IO (Handle, hGetBufSome, hPutBuf)
110+import System.IO (Handle, hGetBufSome, hPutBuf, stdin, stdout)
109111import Prelude hiding (read)
110112
111113import Streamly.Data.Fold (Fold)
@@ -229,6 +231,18 @@ readChunksWithBufferOf = Unfold step return
229231toChunks :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
230232toChunks = toChunksWithBufferOf defaultChunkSize
231233
234+-- | Read a stream of chunks from standard input. The maximum size of a single
235+-- chunk is limited to @defaultChunkSize@. The actual size read may be less
236+-- than @defaultChunkSize@.
237+--
238+-- > getChunks = toChunks stdin
239+--
240+-- /Internal/
241+--
242+{-# INLINE getChunks #-}
243+getChunks :: (IsStream t, MonadIO m) => t m (Array Word8)
244+getChunks = toChunks stdin
245+
232246-- | Unfolds a handle into a stream of 'Word8' arrays. Requests to the IO
233247-- device are performed using a buffer of size
234248-- 'Streamly.Internal.Memory.Array.Types.defaultChunkSize'. The
@@ -320,6 +334,14 @@ fromChunks :: (MonadIO m, Storable a)
320334 => Handle -> SerialT m (Array a) -> m ()
321335fromChunks h m = S.mapM_ (liftIO . writeArray h) m
322336
337+-- | Write a stream of chunks to standard output.
338+--
339+-- /Internal/
340+--
341+{-# INLINE putChunks #-}
342+putChunks :: (MonadIO m, Storable a) => SerialT m (Array a) -> m ()
343+putChunks = fromChunks stdout
344+
323345-- | @fromChunksWithBufferOf bufsize handle stream@ writes a stream of arrays
324346-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
325347-- The chunk size is only a maximum and the actual writes could be smaller as