@@ -36,6 +36,7 @@ module Streamly.Internal.FileSystem.Handle
37 , toChunksWithBufferOf
37 , toChunksWithBufferOf
38 , toChunks
38 , toChunks
40 -- ** Write to Handle
41 -- ** Write to Handle
41 -- Byte stream write (Folds)
42 -- Byte stream write (Folds)
@@ -55,8 +56,9 @@ module Streamly.Internal.FileSystem.Handle
55 , writeChunksWithBufferOf
56 , writeChunksWithBufferOf
57 -- -- * Array stream Write
58 -- -- * Array stream Write
59 , fromChunksWithBufferOf
59 , fromChunksWithBufferOf
61 -- -- * Random Access (Seek)
63 -- -- * Random Access (Seek)
62 -- -- | Unlike the streaming APIs listed above, these APIs apply to devices or
64 -- -- | Unlike the streaming APIs listed above, these APIs apply to devices or
@@ -105,7 +107,7 @@ import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
105import Foreign.Ptr (minusPtr, plusPtr)
107import Foreign.Ptr (minusPtr, plusPtr)
106import Foreign.Storable (Storable(..))
108import Foreign.Storable (Storable(..))
107import GHC.ForeignPtr (mallocPlainForeignPtrBytes)
109import GHC.ForeignPtr (mallocPlainForeignPtrBytes)
108−import System.IO (Handle, hGetBufSome, hPutBuf)
110+import System.IO (Handle, hGetBufSome, hPutBuf, stdin, stdout)
109import Prelude hiding (read)
111import Prelude hiding (read)
111import Streamly.Data.Fold (Fold)
113import Streamly.Data.Fold (Fold)
@@ -229,6 +231,18 @@ readChunksWithBufferOf = Unfold step return
229toChunks :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
231toChunks :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
230toChunks = toChunksWithBufferOf defaultChunkSize
232toChunks = toChunksWithBufferOf defaultChunkSize
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@.
238+-- > getChunks = toChunks stdin
242+{-# INLINE getChunks #-}
243+getChunks :: (IsStream t, MonadIO m) => t m (Array Word8)
244+getChunks = toChunks stdin
232-- | Unfolds a handle into a stream of 'Word8' arrays. Requests to the IO
246-- | Unfolds a handle into a stream of 'Word8' arrays. Requests to the IO
233-- device are performed using a buffer of size
247-- device are performed using a buffer of size
234-- 'Streamly.Internal.Memory.Array.Types.defaultChunkSize'. The
248-- 'Streamly.Internal.Memory.Array.Types.defaultChunkSize'. The
@@ -320,6 +334,14 @@ fromChunks :: (MonadIO m, Storable a)
320 => Handle -> SerialT m (Array a) -> m ()
334 => Handle -> SerialT m (Array a) -> m ()
321fromChunks h m = S.mapM_ (liftIO . writeArray h) m
335fromChunks h m = S.mapM_ (liftIO . writeArray h) m
337+-- | Write a stream of chunks to standard output.
341+{-# INLINE putChunks #-}
342+putChunks :: (MonadIO m, Storable a) => SerialT m (Array a) -> m ()
343+putChunks = fromChunks stdout
323-- | @fromChunksWithBufferOf bufsize handle stream@ writes a stream of arrays
345-- | @fromChunksWithBufferOf bufsize handle stream@ writes a stream of arrays
324-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
346-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
325-- The chunk size is only a maximum and the actual writes could be smaller as
347-- The chunk size is only a maximum and the actual writes could be smaller as