on master help sign in
conduit 0.2
commitf3161f5109e180be08a4dc0c2a7d418c7b90c77c authorMichael Snoyman <michael@snoyman.com> dateSat 28 Jan 2012, 23:35 (15 years ago) parentb33dd6f
2 files changed+23−15
Text/Libyaml.hs+21−13 yaml.cabal+2−2
Text/Libyaml.hs+21−13
@@ -505,13 +505,13 @@ decodeFile file =
505505 c_yaml_parser_delete ptr
506506 free ptr
507507
508−runParser :: ResourceIO m => Parser -> m (C.SourceResult Event)
508+runParser :: ResourceIO m => Parser -> m (C.SourceIOResult Event)
509509runParser parser = liftIO $ do
510510 e <- parserParseOne' parser
511511 case e of
512512 Left err -> throwIO $ YamlException err
513− Right Nothing -> return $ C.Closed
514− Right (Just ev) -> return $ C.Open ev
513+ Right Nothing -> return $ C.IOClosed
514+ Right (Just ev) -> return $ C.IOOpen ev
515515
516516parserParseOne' :: Parser
517517 -> IO (Either String (Maybe Event))
@@ -552,16 +552,24 @@ encode =
552552encodeFile :: ResourceIO m
553553 => FilePath
554554 -> C.Sink Event m ()
555−encodeFile filePath = C.Sink $ do
556− (_releaseKey, file) <- flip withIO c_fclose $ do
557− file <- liftIO $ withCString filePath $
558− \filePath' -> withCString "w" $
559− \w' -> c_fopen filePath' w'
560− if (file == nullPtr)
561− then throwIO $ YamlException $ "could not open file for write: " ++ filePath
562− else return file
563− C.prepareSink $ runEmitter (alloc file) (return) -- FIXME close file early
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+ }
564563 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
565573 alloc file emitter = do
566574 c_yaml_emitter_set_output_file emitter file
567575 return ()
@@ -584,7 +592,7 @@ runEmitter allocI closeI =
584592 free emitter
585593 push (emitter, _) e = do
586594 _ <- liftIO $ toEventRaw e $ c_yaml_emitter_emit emitter
587− return C.Processing
595+ return C.IOProcessing
588596 close (_, a) = liftIO $ closeI a
589597
590598data YamlException = YamlException String
yaml.cabal+2−2
@@ -1,5 +1,5 @@
11name: yaml
2−version: 0.5.1.2
2+version: 0.5.2
33license: BSD3
44license-file: LICENSE
55author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
@@ -30,7 +30,7 @@ library
3030 build-depends: base >= 4 && < 5
3131 , transformers >= 0.1 && < 0.3
3232 , bytestring >= 0.9.1.4 && < 0.10
33− , conduit
33+ , conduit >= 0.2 && < 0.3
3434 , aeson >= 0.5
3535 , containers
3636 , unordered-containers