on master help sign in
Implement readChunksWithBufferOf idiomatically
09d4257Harendra Kumar
src/Streamly/Internal/FileSystem/Handle.hs+11
@@ -100,6 +100,7 @@ where
100
100
101import Control.Exception (assert)
101import Control.Exception (assert)
102import Control.Monad.IO.Class (MonadIO(..))
102import Control.Monad.IO.Class (MonadIO(..))
103+import Data.Function ((&))
103import Data.Word (Word8)
104import Data.Word (Word8)
104import Foreign.ForeignPtr (withForeignPtr)
105import Foreign.ForeignPtr (withForeignPtr)
105import Foreign.Ptr (minusPtr, plusPtr)
106import Foreign.Ptr (minusPtr, plusPtr)
@@ -220,6 +221,11 @@ _toChunksWithBufferOf size h = go
220{-# INLINE_NORMAL toChunksWithBufferOf #-}
221{-# INLINE_NORMAL toChunksWithBufferOf #-}
221toChunksWithBufferOf :: (IsStream t, MonadIO m) =>
222toChunksWithBufferOf :: (IsStream t, MonadIO m) =>
222 Int -> Handle -> t m (Array Word8)
223 Int -> Handle -> t m (Array Word8)
224+{-
225+toChunksWithBufferOf size h =
226+ S.repeatM (getChunk size h)
227+ & S.takeWhile ((/= 0) . byteLength)
228+-}
223toChunksWithBufferOf size h = fromStreamD (D.Stream step ())
229toChunksWithBufferOf size h = fromStreamD (D.Stream step ())
224 where
230 where
225 {-# INLINE_LATE step #-}
231 {-# INLINE_LATE step #-}
@@ -238,6 +244,10 @@ toChunksWithBufferOf size h = fromStreamD (D.Stream step ())
238-- @since 0.7.0
244-- @since 0.7.0
239{-# INLINE_NORMAL readChunksWithBufferOf #-}
245{-# INLINE_NORMAL readChunksWithBufferOf #-}
240readChunksWithBufferOf :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
246readChunksWithBufferOf :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
247+readChunksWithBufferOf =
248+ UF.lmap (uncurry getChunk) UF.repeatM
249+ & UF.takeWhile ((/= 0) . byteLength)
250+{-
241readChunksWithBufferOf = Unfold step return
251readChunksWithBufferOf = Unfold step return
242
252
243 where
253 where
@@ -249,6 +259,7 @@ readChunksWithBufferOf = Unfold step return
249 case byteLength arr of
259 case byteLength arr of
250 0 -> D.Stop
260 0 -> D.Stop
251 _ -> D.Yield arr (size, h)
261 _ -> D.Yield arr (size, h)
262+-}
252
263
253-- There are two ways to implement this.
264-- There are two ways to implement this.
254--
265--