on master help sign in
conduit 0.2
f3161f5Michael Snoyman
Text/Libyaml.hs+21−13
@@ -505,13 +505,13 @@ decodeFile file =
505 c_yaml_parser_delete ptr
505 c_yaml_parser_delete ptr
506 free ptr
506 free ptr
507
507
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
515
515
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
564 where
563 where
564+ msink = do
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
571+ else return file
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
589
597
590data YamlException = YamlException String
598data YamlException = YamlException String
yaml.cabal+2−2
@@ -1,5 +1,5 @@
1name: yaml
1name: yaml
2−version: 0.5.1.2
2+version: 0.5.2
3license: BSD3
3license: BSD3
4license-file: LICENSE
4license-file: LICENSE
5author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
5author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
@@ -30,7 +30,7 @@ library
30 build-depends: base >= 4 && < 5
30 build-depends: base >= 4 && < 5
31 , transformers >= 0.1 && < 0.3
31 , transformers >= 0.1 && < 0.3
32 , bytestring >= 0.9.1.4 && < 0.10
32 , bytestring >= 0.9.1.4 && < 0.10
33− , conduit
33+ , conduit >= 0.2 && < 0.3
34 , aeson >= 0.5
34 , aeson >= 0.5
35 , containers
35 , containers
36 , unordered-containers
36 , unordered-containers