@@ -20,7 +20,6 @@ module Streamly.Internal.FileSystem.Handle
2020
2121 , toBytes
2222 , toBytesWithBufferOf
23− , getBytes
2423
2524 -- -- * Array Read
2625 -- , readArrayUpto
@@ -30,7 +29,6 @@ module Streamly.Internal.FileSystem.Handle
3029
3130 , toChunksWithBufferOf
3231 , toChunks
33− , getChunks
3432
3533 -- ** Write to Handle
3634 -- Byte stream write (Folds)
@@ -43,8 +41,8 @@ module Streamly.Internal.FileSystem.Handle
4341 , writeWithBufferOf
4442
4543 -- Byte stream write (Streams)
46− , fromBytes
47− , fromBytesWithBufferOf
44+ , putBytes
45+ , putBytesWithBufferOf
4846
4947 -- -- * Array Write
5048 , writeArray
@@ -52,12 +50,8 @@ module Streamly.Internal.FileSystem.Handle
5250 , writeChunksWithBufferOf
5351
5452 -- -- * Array stream Write
55− , fromChunksWithBufferOf
56− , fromChunks
53+ , putChunksWithBufferOf
5754 , putChunks
58− , putStrings
59− , putBytes
60− , putLines
6155
6256 -- -- * Random Access (Seek)
6357 -- -- | Unlike the streaming APIs listed above, these APIs apply to devices or
@@ -106,10 +100,9 @@ import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
106100import Foreign.Ptr (minusPtr, plusPtr)
107101import Foreign.Storable (Storable(..))
108102import GHC.ForeignPtr (mallocPlainForeignPtrBytes)
109−import System.IO (Handle, hGetBufSome, hPutBuf, stdin, stdout)
103+import System.IO (Handle, hGetBufSome, hPutBuf)
110104import Prelude hiding (read)
111105
112−import Streamly.Prelude (MonadAsync)
113106import Streamly.Data.Fold (Fold)
114107import Streamly.Internal.Data.Fold.Type (Fold2(..))
115108import Streamly.Internal.Data.Unfold.Type (Unfold(..))
@@ -124,7 +117,6 @@ import Streamly.Internal.Data.Array.Stream.Foreign (lpackArraysChunksOf)
124117import qualified Streamly.Data.Fold as FL
125118import qualified Streamly.Internal.Data.Fold.Type as FL
126119import qualified Streamly.Internal.Data.Unfold as UF
127−import qualified Streamly.Internal.Data.Array.Foreign as IA
128120import qualified Streamly.Internal.Data.Array.Stream.Foreign as AS
129121import qualified Streamly.Internal.Data.Stream.IsStream as S
130122import qualified Streamly.Data.Array.Foreign as A
@@ -231,28 +223,6 @@ readChunksWithBufferOf = Unfold step return
231223toChunks :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
232224toChunks = toChunksWithBufferOf defaultChunkSize
233225
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−-- /Pre-release/
241−--
242−{-# INLINE getChunks #-}
243−getChunks :: (IsStream t, MonadIO m) => t m (Array Word8)
244−getChunks = toChunks stdin
245−
246−-- | Read a stream of bytes from standard input.
247−--
248−-- > getBytes = toBytes stdin
249−--
250−-- /Pre-release/
251−--
252−{-# INLINE getBytes #-}
253−getBytes :: (IsStream t, MonadIO m) => t m Word8
254−getBytes = toBytes stdin
255−
256226-- | Unfolds a handle into a stream of 'Word8' arrays. Requests to the IO
257227-- device are performed using a buffer of size
258228-- 'Streamly.Internal.Data.Array.Foreign.Type.defaultChunkSize'. The
@@ -340,73 +310,31 @@ writeArray h Array{..} = withForeignPtr aStart $ \p -> hPutBuf h p aLen
340310-- | Write a stream of arrays to a handle.
341311--
342312-- @since 0.7.0
343−{-# INLINE fromChunks #-}
344−fromChunks :: (MonadIO m, Storable a)
345− => Handle -> SerialT m (Array a) -> m ()
346−fromChunks h = S.mapM_ (liftIO . writeArray h)
347−
348−-- | Write a stream of chunks to standard output.
349−--
350−-- /Pre-release/
351−--
352313{-# INLINE putChunks #-}
353−putChunks :: (MonadIO m, Storable a) => SerialT m (Array a) -> m ()
354−putChunks = fromChunks stdout
355−
356−-- XXX use an unfold so that we can put any type of strings.
357−-- | Write a stream of strings to standard output using the supplied encoding.
358−-- Output is flushed to the device for each string.
359−--
360−-- /Pre-release/
361−--
362−{-# INLINE putStrings #-}
363−putStrings :: MonadAsync m
364− => (SerialT m Char -> SerialT m Word8) -> SerialT m String -> m ()
365−putStrings encode = putChunks . S.mapM (IA.fromStream . encode . S.fromList)
366−
367−-- XXX use an unfold so that we can put lines from any object
368−-- | Write a stream of strings as separate lines to standard output using the
369−-- supplied encoding. Output is line buffered i.e. the output is written to the
370−-- device as soon as a newline is encountered.
371−--
372−-- /Pre-release/
373−--
374−{-# INLINE putLines #-}
375−putLines :: MonadAsync m
376− => (SerialT m Char -> SerialT m Word8) -> SerialT m String -> m ()
377−putLines encode = putChunks . S.mapM
378− (\xs -> IA.fromStream $ encode (S.fromList (xs ++ "\n")))
379−
380−-- | Write a stream of bytes from standard output.
381−--
382−-- > putBytes = fromBytes stdout
383−--
384−-- /Pre-release/
385−--
386−{-# INLINE putBytes #-}
387−putBytes :: MonadIO m => SerialT m Word8 -> m ()
388−putBytes = fromBytes stdout
314+putChunks :: (MonadIO m, Storable a)
315+ => Handle -> SerialT m (Array a) -> m ()
316+putChunks h = S.mapM_ (liftIO . writeArray h)
389317
390−-- | @fromChunksWithBufferOf bufsize handle stream@ writes a stream of arrays
318+-- | @putChunksWithBufferOf bufsize handle stream@ writes a stream of arrays
391319-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
392320-- The chunk size is only a maximum and the actual writes could be smaller as
393321-- we do not split the arrays to fit exactly to the specified size.
394322--
395323-- @since 0.7.0
396−{-# INLINE fromChunksWithBufferOf #-}
397−fromChunksWithBufferOf :: (MonadIO m, Storable a)
324+{-# INLINE putChunksWithBufferOf #-}
325+putChunksWithBufferOf :: (MonadIO m, Storable a)
398326 => Int -> Handle -> SerialT m (Array a) -> m ()
399−fromChunksWithBufferOf n h xs = fromChunks h $ AS.compact n xs
327+putChunksWithBufferOf n h xs = putChunks h $ AS.compact n xs
400328
401−-- | @fromBytesWithBufferOf bufsize handle stream@ writes @stream@ to @handle@
329+-- | @putBytesWithBufferOf bufsize handle stream@ writes @stream@ to @handle@
402330-- in chunks of @bufsize@. A write is performed to the IO device as soon as we
403331-- collect the required input size.
404332--
405333-- @since 0.7.0
406−{-# INLINE fromBytesWithBufferOf #-}
407−fromBytesWithBufferOf :: MonadIO m => Int -> Handle -> SerialT m Word8 -> m ()
408−fromBytesWithBufferOf n h m = fromChunks h $ S.arraysOf n m
409−-- fromBytesWithBufferOf n h m = fromChunks h $ AS.arraysOf n m
334+{-# INLINE putBytesWithBufferOf #-}
335+putBytesWithBufferOf :: MonadIO m => Int -> Handle -> SerialT m Word8 -> m ()
336+putBytesWithBufferOf n h m = putChunks h $ S.arraysOf n m
337+-- putBytesWithBufferOf n h m = putChunks h $ AS.arraysOf n m
410338
411339-- > write = 'writeWithBufferOf' A.defaultChunkSize
412340--
@@ -417,9 +345,9 @@ fromBytesWithBufferOf n h m = fromChunks h $ S.arraysOf n m
417345-- need some extra perf boost.
418346--
419347-- @since 0.7.0
420−{-# INLINE fromBytes #-}
421−fromBytes :: MonadIO m => Handle -> SerialT m Word8 -> m ()
422−fromBytes = fromBytesWithBufferOf defaultChunkSize
348+{-# INLINE putBytes #-}
349+putBytes :: MonadIO m => Handle -> SerialT m Word8 -> m ()
350+putBytes = putBytesWithBufferOf defaultChunkSize
423351
424352-- | Write a stream of arrays to a handle. Each array in the stream is written
425353-- to the device as a separate IO request.