@@ -505,13 +505,13 @@ decodeFile file =
505 c_yaml_parser_delete ptr
505 c_yaml_parser_delete ptr
508−runParser :: ResourceIO m => Parser -> m (C.SourceResult Event)
508+runParser :: ResourceIO m => Parser -> m (C.SourceIOResult Event)
509runParser parser = liftIO $ do
509runParser parser = liftIO $ do
510 e <- parserParseOne' parser
510 e <- parserParseOne' parser
511 case e of
511 case e of
512 Left err -> throwIO $ YamlException err
512 Left err -> throwIO $ YamlException err
513− Right Nothing -> return $ C.Closed
513+ Right Nothing -> return $ C.IOClosed
514− Right (Just ev) -> return $ C.Open ev
514+ Right (Just ev) -> return $ C.IOOpen ev
516parserParseOne' :: Parser
516parserParseOne' :: Parser
517 -> IO (Either String (Maybe Event))
517 -> IO (Either String (Maybe Event))
@@ -552,16 +552,24 @@ encode =
552encodeFile :: ResourceIO m
552encodeFile :: ResourceIO m
553 => FilePath
553 => FilePath
554 -> C.Sink Event m ()
554 -> C.Sink Event m ()
555−encodeFile filePath = C.Sink $ do
555+encodeFile filePath = C.SinkData
556− (_releaseKey, file) <- flip withIO c_fclose $ do
556+ { C.sinkPush = \input -> do
557− file <- liftIO $ withCString filePath $
557+ sink <- msink
558− \filePath' -> withCString "w" $
558+ C.sinkPush sink input
559− \w' -> c_fopen filePath' w'
559+ , C.sinkClose = do
560− if (file == nullPtr)
560+ sink <- msink
561− then throwIO $ YamlException $ "could not open file for write: " ++ filePath
561+ C.sinkClose sink
562− else return file
562+ }
563− C.prepareSink $ runEmitter (alloc file) (return) -- FIXME close file early
565+ (_releaseKey, file) <- flip withIO c_fclose $ do
566+ file <- liftIO $ withCString filePath $
567+ \filePath' -> withCString "w" $
568+ \w' -> c_fopen filePath' w'
569+ if (file == nullPtr)
570+ then throwIO $ YamlException $ "could not open file for write: " ++ filePath
572+ return $ runEmitter (alloc file) (return) -- FIXME close file early
565 alloc file emitter = do
573 alloc file emitter = do
566 c_yaml_emitter_set_output_file emitter file
574 c_yaml_emitter_set_output_file emitter file
567 return ()
575 return ()
@@ -584,7 +592,7 @@ runEmitter allocI closeI =
584 free emitter
592 free emitter
585 push (emitter, _) e = do
593 push (emitter, _) e = do
586 _ <- liftIO $ toEventRaw e $ c_yaml_emitter_emit emitter
594 _ <- liftIO $ toEventRaw e $ c_yaml_emitter_emit emitter
587− return C.Processing
595+ return C.IOProcessing
588 close (_, a) = liftIO $ closeI a
596 close (_, a) = liftIO $ closeI a
590data YamlException = YamlException String
598data YamlException = YamlException String