<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div name="messageBodySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;">Dear Cafe, 
<div><br /></div>
<div>I am using conduit to parse a file in a streaming fashion. In the middle of the conduit pipeline, I have a conduit that parses a value, returns the value, and then passes all other input downstream. Is there any way to express this? I looked up functions provided by the conduit and it seems that there is no such a function that provides such semantics. </div>
<div><br /></div>
<div>My conduit function looks as follows: </div>
<div><br /></div>
<div>
<div>-- | Run the given `Get` only once and push unconsumed bytes from upstream to </div>
<div>-- downstream </div>
<div>conduitParseOnce :: (MonadThrow m, MonadResource m) => </div>
<div>                        Get a -> ConduitT BS.ByteString BS.ByteString m a </div>
<div>conduitParseOnce g = go0 </div>
<div>    where </div>
<div>      go0 = do x <- await </div>
<div>               case x of </div>
<div>                 Nothing -> undefined -- throwM SomeException </div>
<div>                 Just bs -> go (runGetChunk g Nothing bs)</div>
<div><br /></div>
<div>      go (Fail msg bs) = throwM (DecodeError bs msg "conduitParseOnce")</div>
<div>      go (Partial f)   = await >>= maybe (go $ f mempty) (go . f) </div>
<div>      go (Done v bs)   = leftover bs >> return v </div>
</div>
<div><br /></div>
<div>The downstream of this conduit will take all remaining inputs and parses them. The issue with this implementation is that the downstream will only be able to get the first chunk of data. </div>
</div>
<div name="messageSignatureSection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;"><br />
Best Regards,
<div>Qingbo Liu<br /></div>
</div>
</body>
</html>