@@ -43,6 +43,7 @@ module Streamly.Internal.FileSystem.Handle
43 -- ** Write to Handle
43 -- ** Write to Handle
44 -- Byte stream write (Folds)
44 -- Byte stream write (Folds)
46 -- , writeUtf8
47 -- , writeUtf8
47 -- , writeUtf8ByLines
48 -- , writeUtf8ByLines
48 -- , writeByFrames
49 -- , writeByFrames
@@ -117,6 +118,7 @@ import Prelude hiding (read)
118import Streamly (MonadAsync)
119import Streamly (MonadAsync)
119import Streamly.Data.Fold (Fold)
120import Streamly.Data.Fold (Fold)
121+import Streamly.Internal.Data.Fold.Types (Fold2(..))
120import Streamly.Internal.Data.Unfold.Types (Unfold(..))
122import Streamly.Internal.Data.Unfold.Types (Unfold(..))
121import Streamly.Internal.Memory.Array.Types
123import Streamly.Internal.Memory.Array.Types
122 (Array(..), writeNUnsafe, defaultChunkSize, shrinkToFit,
124 (Array(..), writeNUnsafe, defaultChunkSize, shrinkToFit,
@@ -410,6 +412,10 @@ fromBytes = fromBytesWithBufferOf defaultChunkSize
410writeChunks :: (MonadIO m, Storable a) => Handle -> Fold m (Array a) ()
412writeChunks :: (MonadIO m, Storable a) => Handle -> Fold m (Array a) ()
411writeChunks h = FL.drainBy (liftIO . writeArray h)
413writeChunks h = FL.drainBy (liftIO . writeArray h)
415+{-# INLINE writeChunks2 #-}
416+writeChunks2 :: (MonadIO m, Storable a) => Fold2 m Handle (Array a) ()
417+writeChunks2 = Fold2 (\h arr -> liftIO $ writeArray h arr >> return h) return (\_ -> return ())
413-- | @writeChunksWithBufferOf bufsize handle@ writes a stream of arrays
419-- | @writeChunksWithBufferOf bufsize handle@ writes a stream of arrays
414-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
420-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
415-- We never split an array, if a single array is bigger than the specified size
421-- We never split an array, if a single array is bigger than the specified size
@@ -439,6 +445,10 @@ writeChunksWithBufferOf n h = lpackArraysChunksOf n (writeChunks h)
439writeWithBufferOf :: MonadIO m => Int -> Handle -> Fold m Word8 ()
445writeWithBufferOf :: MonadIO m => Int -> Handle -> Fold m Word8 ()
440writeWithBufferOf n h = FL.lchunksOf n (writeNUnsafe n) (writeChunks h)
446writeWithBufferOf n h = FL.lchunksOf n (writeNUnsafe n) (writeChunks h)
448+{-# INLINE writeWithBufferOf2 #-}
449+writeWithBufferOf2 :: MonadIO m => Int -> Fold2 m Handle Word8 ()
450+writeWithBufferOf2 n = FL.lchunksOf2 n (writeNUnsafe n) writeChunks2
442-- > write = 'writeWithBufferOf' A.defaultChunkSize
452-- > write = 'writeWithBufferOf' A.defaultChunkSize
444-- | Write a byte stream to a file handle. Accumulates the input in chunks of
454-- | Write a byte stream to a file handle. Accumulates the input in chunks of
@@ -450,6 +460,10 @@ writeWithBufferOf n h = FL.lchunksOf n (writeNUnsafe n) (writeChunks h)
450write :: MonadIO m => Handle -> Fold m Word8 ()
460write :: MonadIO m => Handle -> Fold m Word8 ()
451write = writeWithBufferOf defaultChunkSize
461write = writeWithBufferOf defaultChunkSize
463+{-# INLINE write2 #-}
464+write2 :: MonadIO m => Fold2 m Handle Word8 ()
465+write2 = writeWithBufferOf2 defaultChunkSize
454{-# INLINE write #-}
468{-# INLINE write #-}
455write :: (MonadIO m, Storable a) => Handle -> SerialT m a -> m ()
469write :: (MonadIO m, Storable a) => Handle -> SerialT m a -> m ()