]> gitweb @ CieloNegro.org - wavpack.git/blobdiff - Codec/Audio/WavPack/Block.hs
readBlocks
[wavpack.git] / Codec / Audio / WavPack / Block.hs
index aff1da3249c0904256f0565e4ad49326816620b9..4ecdb7d8d40e5530f6e8e8846d8ef776320a104a 100644 (file)
@@ -9,7 +9,7 @@ module Codec.Audio.WavPack.Block
     , BlockHeader(..)
     , BlockFlags(..)
 
-    , findNextBlock
+    , readBlocks
     )
     where
 import Codec.Audio.WavPack.Metadata
@@ -286,10 +286,17 @@ decodeSamplingRate 0x0D = S.Just  96000
 decodeSamplingRate 0x0E = S.Just 192000
 decodeSamplingRate    _ =     S.Nothing
 
--- | Find a WavPack block in a given stream. Returns 'S.Nothing' if no
--- blocks are found.
-findNextBlock ∷ L.ByteString -- ^ the input
-              → (# S.Maybe Block, L.ByteString #) -- ^ the rest of input
+-- | Read WavPack blocks in a given stream lazily.
+readBlocks ∷ L.ByteString → [Block]
+readBlocks src
+    = case findNextBlock src of
+        (# S.Just block, src' #)
+            → block : readBlocks src'
+        (# S.Nothing, _ #)
+            → []
+
+findNextBlock ∷ L.ByteString
+              → (# S.Maybe Block, L.ByteString #)
 findNextBlock src
     = case L.uncons src of
         Nothing