import qualified Data.Text as Timport Pipesimport qualified Pipes.Prelude as Pimport qualified Pipes.Prelude.Text as PTimport Pipes.Safeimport Text.Printf.TH
-- | Streams lines from the source file.
-- This drops the first three lines, which are not Elements.
xml :: MonadSafe m => FilePath -> Producer T.Text m ()
xml fp = PT.readFileLn fp >-> P.drop 3
-- | Stream an entire OSM Element with all its children (tags, etc).
-- Note: OSM XML is rather flat - children never have children.
element :: Monad m => Pipe T.Text [T.Text] m ()
element = undefined -- `await` lines until you find a closing tag, then pack as a List and `yield`?
-- | Writes one legal @<osm> ... </osm>@ block.
osm :: Int -> Consumer [T.Text] (SafeT IO) ()
osm !fpn = do
let fp = [s|catalog/out-%d.osm|] fpn
P.take 1000 >-> P.concat >-> PT.writeFileLn fp
osm $ fpn + 1
splitAll :: Effect (SafeT IO) ()
splitAll = xml "somefile" >-> element >-> osm 0
<foo>
<bar/>
<bar/>
<bar/>
</foo>
Yes, the `pipes-group` library is what you need. I recommend reading this if you haven't done so already:
http://www.haskellforall.com/2013/09/perfect-streaming-using-pipes-bytestring.html
... so the type of `element` would become:
element :: Monad m => Producer Text m r -> FreeT (Producer Text m) m rThe result is a "stream of streams" that preserves the lazy streaming behavior of each sub-stream so that you don't have to wait to collect all children before processing them.
There is also another library you should check out which is more specialized to this particular use case which is the `streaming` library:
--
You received this message because you are subscribed to the Google Groups "Haskell Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-pipe...@googlegroups.com.
To post to this group, send email to haskel...@googlegroups.com.