on master help sign in
Use byteLength instead of length
commite8d4d7e440ef0c1c8e0bb33595f38f9a8bf56029 authorHarendra Kumar <harendra@composewell.com> dateSun 7 Nov 2021, 13:11 (5 years ago) parent95b8d90
1 file changed+7−5
src/Streamly/Internal/FileSystem/Handle.hs+7−5
src/Streamly/Internal/FileSystem/Handle.hs+7−5
@@ -113,7 +113,7 @@ import Streamly.Internal.Data.Fold (Fold)
113113import Streamly.Internal.Data.Refold.Type (Refold(..))
114114import Streamly.Internal.Data.Unfold.Type (Unfold(..))
115115import Streamly.Internal.Data.Array.Foreign.Type
116− (Array(..), writeNUnsafe, unsafeFreezeWithShrink)
116+ (Array(..), writeNUnsafe, unsafeFreezeWithShrink, byteLength)
117117import Streamly.Internal.Data.Array.Foreign.Mut.Type (fromForeignPtrUnsafe)
118118import Streamly.Internal.Data.Stream.Serial (SerialT)
119119import Streamly.Internal.Data.Stream.IsStream.Type
@@ -206,7 +206,7 @@ _toChunksWithBufferOf size h = go
206206 -- XXX use cons/nil instead
207207 go = mkStream $ \_ yld _ stp -> do
208208 arr <- getChunk size h
209− if A.length arr == 0
209+ if byteLength arr == 0
210210 then stp
211211 else yld arr go
212212
@@ -226,7 +226,7 @@ toChunksWithBufferOf size h = fromStreamD (D.Stream step ())
226226 step _ _ = do
227227 arr <- getChunk size h
228228 return $
229− case A.length arr of
229+ case byteLength arr of
230230 0 -> D.Stop
231231 _ -> D.Yield arr ()
232232
@@ -239,12 +239,14 @@ toChunksWithBufferOf size h = fromStreamD (D.Stream step ())
239239{-# INLINE_NORMAL readChunksWithBufferOf #-}
240240readChunksWithBufferOf :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
241241readChunksWithBufferOf = Unfold step return
242+
242243 where
244+
243245 {-# INLINE_LATE step #-}
244246 step (size, h) = do
245247 arr <- getChunk size h
246248 return $
247− case A.length arr of
249+ case byteLength arr of
248250 0 -> D.Stop
249251 _ -> D.Yield arr (size, h)
250252
@@ -279,7 +281,7 @@ readChunksFromToWith = Unfold step inject
279281 else do
280282 arr <- getChunk (min bufSize remaining) h
281283 return $
282− case A.length arr of
284+ case byteLength arr of
283285 0 -> D.Stop
284286 len ->
285287 assert (len <= remaining)