@@ -44,7 +44,7 @@ import Control.Monad.IO.Class
44import Control.Exception (throwIO, Exception, finally)
44import Control.Exception (throwIO, Exception, finally)
45import Control.Applicative
45import Control.Applicative
46import Control.Monad.Trans.Resource
46import Control.Monad.Trans.Resource
47−import Data.Conduit
47+import Data.Conduit hiding (Source, Sink, Conduit)
48import Control.Exception (mask_)
48import Control.Exception (mask_)
50data Event =
50data Event =
@@ -452,7 +452,7 @@ newtype ToEventRawException = ToEventRawException CInt
452 deriving (Show, Typeable)
452 deriving (Show, Typeable)
453instance Exception ToEventRawException
453instance Exception ToEventRawException
455−decode :: MonadResource m => B.ByteString -> Source m Event
455+decode :: MonadResource m => B.ByteString -> GSource m Event
456decode bs =
456decode bs =
457 bracketP alloc cleanup (runParser . fst)
457 bracketP alloc cleanup (runParser . fst)
@@ -475,7 +475,7 @@ decode bs =
475 c_yaml_parser_delete ptr
475 c_yaml_parser_delete ptr
478−decodeFile :: MonadResource m => FilePath -> Source m Event
478+decodeFile :: MonadResource m => FilePath -> GSource m Event
479decodeFile file =
479decodeFile file =
480 bracketP alloc cleanup (runParser . fst)
480 bracketP alloc cleanup (runParser . fst)
@@ -535,7 +535,7 @@ parserParseOne' parser = allocaBytes eventSize $ \er -> do
536 else Right <$> getEvent er
536 else Right <$> getEvent er
538−encode :: MonadResource m => Sink Event m ByteString
538+encode :: MonadResource m => GSink Event m ByteString
540 runEmitter alloc close
540 runEmitter alloc close
@@ -544,7 +544,7 @@ encode =
544 withForeignPtr fbuf c_buffer_init
544 withForeignPtr fbuf c_buffer_init
545 withForeignPtr fbuf $ c_my_emitter_set_output emitter
545 withForeignPtr fbuf $ c_my_emitter_set_output emitter
546 return fbuf
546 return fbuf
547− close fbuf = withForeignPtr fbuf $ \b -> do
547+ close _ fbuf = withForeignPtr fbuf $ \b -> do
548 ptr' <- c_get_buffer_buff b
548 ptr' <- c_get_buffer_buff b
549 len <- c_get_buffer_used b
549 len <- c_get_buffer_used b
550 fptr <- newForeignPtr_ $ castPtr ptr'
550 fptr <- newForeignPtr_ $ castPtr ptr'
@@ -552,9 +552,9 @@ encode =
553encodeFile :: MonadResource m
553encodeFile :: MonadResource m
554 => FilePath
554 => FilePath
555− -> Sink Event m ()
555+ -> GInfSink Event m
556encodeFile filePath =
556encodeFile filePath =
557− bracketP getFile c_fclose $ \file -> runEmitter (alloc file) return
557+ bracketP getFile c_fclose $ \file -> runEmitter (alloc file) (\u _ -> return u)
559 getFile = do
559 getFile = do
560 file <- withCString filePath $
560 file <- withCString filePath $
@@ -564,14 +564,12 @@ encodeFile filePath =
564 then throwIO $ YamlException $ "could not open file for write: " ++ filePath
564 then throwIO $ YamlException $ "could not open file for write: " ++ filePath
565 else return file
565 else return file
567− alloc file emitter = do
568− c_yaml_emitter_set_output_file emitter file
567+ alloc file emitter = c_yaml_emitter_set_output_file emitter file
571runEmitter :: MonadResource m
569runEmitter :: MonadResource m
572 => (Emitter -> IO a) -- ^ alloc
570 => (Emitter -> IO a) -- ^ alloc
573− -> (a -> IO b) -- ^ close
571+ -> (u -> a -> IO b) -- ^ close
574− -> Sink Event m b
572+ -> Pipe l Event o u m b
575runEmitter allocI closeI =
573runEmitter allocI closeI =
576 bracketP alloc cleanup go
574 bracketP alloc cleanup go
@@ -588,11 +586,11 @@ runEmitter allocI closeI =
588 go (emitter, a) =
586 go (emitter, a) =
591− loop = await >>= maybe close push
589+ loop = awaitE >>= either close push
592 push e = do
590 push e = do
593 _ <- liftIO $ toEventRaw e $ c_yaml_emitter_emit emitter
591 _ <- liftIO $ toEventRaw e $ c_yaml_emitter_emit emitter
595− close = liftIO $ closeI a
593+ close u = liftIO $ closeI u a
597data YamlException = YamlException String
595data YamlException = YamlException String
598 deriving (Show, Typeable)
596 deriving (Show, Typeable)