Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Enumerate ByteString in chunks.

  • Loading branch information...
commit 0b46c0c1324cf960732d2684390d6cb695fe8add 1 parent 9655e9e
@syg syg authored committed
Showing with 9 additions and 5 deletions.
  1. +9 −5 Data/Enumerator.hs
View
14 Data/Enumerator.hs
@@ -27,11 +27,15 @@ type EnumeratorM m = forall a. IterateeM a m -> a -> m a
-- | Enumerates a 'ByteString'.
bytesEnum :: Monad m => S.ByteString -> EnumeratorM m
-bytesEnum bs f seed = do
- seed' <- f seed bs
- case seed' of
- Left seed'' -> return seed''
- Right seed'' -> return seed''
+bytesEnum bs f seed =
+ let block = S.take blockSize bs
+ in if S.null block
+ then return seed
+ else do
+ seed' <- f seed block
+ case seed' of
+ Left seed'' -> return seed''
+ Right seed'' -> bytesEnum (S.drop blockSize bs) f seed''
nl :: Word8
Please sign in to comment.
Something went wrong with that request. Please try again.