@@ -45,6 +45,7 @@ import Control.Exception (throwIO, Exception, finally)
4545import Control.Applicative
4646import Control.Monad.Trans.Resource
4747import qualified Data.Conduit as C
48+import Control.Exception (mask_)
4849
4950data Event =
5051 EventStreamStart
@@ -451,7 +452,7 @@ newtype ToEventRawException = ToEventRawException CInt
451452 deriving (Show, Typeable)
452453instance Exception ToEventRawException
453454
454−decode :: ResourceIO m => B.ByteString -> C.Source m Event
455+decode :: C.MonadResource m => B.ByteString -> C.Source m Event
455456decode bs =
456457 C.sourceIO alloc cleanup (runParser . fst)
457458 where
@@ -474,7 +475,7 @@ decode bs =
474475 c_yaml_parser_delete ptr
475476 free ptr
476477
477−decodeFile :: ResourceIO m => FilePath -> C.Source m Event
478+decodeFile :: C.MonadResource m => FilePath -> C.Source m Event
478479decodeFile file =
479480 C.sourceIO alloc cleanup (runParser . fst)
480481 where
@@ -505,7 +506,7 @@ decodeFile file =
505506 c_yaml_parser_delete ptr
506507 free ptr
507508
508−runParser :: ResourceIO m => Parser -> m (C.SourceIOResult Event)
509+runParser :: C.MonadResource m => Parser -> m (C.SourceIOResult Event)
509510runParser parser = liftIO $ do
510511 e <- parserParseOne' parser
511512 case e of
@@ -534,7 +535,7 @@ parserParseOne' parser = allocaBytes eventSize $ \er -> do
534535 ]
535536 else Right <$> getEvent er
536537
537−encode :: ResourceIO m => C.Sink Event m ByteString
538+encode :: C.MonadResource m => C.Sink Event m ByteString
538539encode =
539540 runEmitter alloc close
540541 where
@@ -549,20 +550,14 @@ encode =
549550 fptr <- newForeignPtr_ $ castPtr ptr'
550551 return $ B.fromForeignPtr fptr 0 $ fromIntegral len
551552
552−encodeFile :: ResourceIO m
553+encodeFile :: C.MonadResource m
553554 => FilePath
554555 -> C.Sink Event m ()
555−encodeFile filePath = C.SinkData
556− { C.sinkPush = \input -> do
557− sink <- msink
558− C.sinkPush sink input
559− , C.sinkClose = do
560− sink <- msink
561− C.sinkClose sink
562− }
556+encodeFile filePath =
557+ C.SinkM msink
563558 where
564559 msink = do
565− (_releaseKey, file) <- flip withIO c_fclose $ do
560+ (_releaseKey, file) <- flip allocate c_fclose $ do
566561 file <- liftIO $ withCString filePath $
567562 \filePath' -> withCString "w" $
568563 \w' -> c_fopen filePath' w'
@@ -574,7 +569,7 @@ encodeFile filePath = C.SinkData
574569 c_yaml_emitter_set_output_file emitter file
575570 return ()
576571
577−runEmitter :: ResourceIO m
572+runEmitter :: C.MonadResource m
578573 => (Emitter -> IO a) -- ^ alloc
579574 -> (a -> IO b) -- ^ close
580575 -> C.Sink Event m b