module Data.Repa.Flow.IO.Binary
( sourceBinary )
where
import Data.Repa.Array.Material as A
import Data.Repa.Array.Generic as A
import Data.Repa.Flow.IO.Storable as F
import Data.Repa.Flow.IO.Bucket as F
import Data.Repa.Flow.Generic as G
#include "repa-flow.h"
sourceBinary
:: F.Storable a
=> Spec a
-> Integer
-> Array B Bucket
-> IO (G.Sources Int IO (Array (Rep a) a))
sourceBinary spec lenElems bs
= return $ G.Sources (A.length bs) pull_sourceBinary
where
pull_sourceBinary i eat eject
= do let b = A.index bs i
op <- bIsOpen b
if not op
then eject
else do
eof <- bAtEnd b
if eof
then eject
else do
Just !chunk <- getArray spec lenElems b
eat chunk