@@ -361,6 +361,27 @@ withEmitter f = allocaBytes emitterSize $ \e -> do
361 c_yaml_emitter_delete e
361 c_yaml_emitter_delete e
362 return bs
362 return bs
364+foreign import ccall unsafe "yaml_emitter_set_output_file"
365+ c_yaml_emitter_set_output_file :: Emitter -> File -> IO ()
367+withEmitterFile :: FilePath
368+ -> (Emitter -> IO (Either YamlException ()))
369+ -> IO (Either YamlException ())
370+withEmitterFile fp f = allocaBytes emitterSize $ \e -> do
371+ res <- c_yaml_emitter_initialize e
373+ then return $ Left YamlOutOfMemory
375+ file <- withCString fp $ \fp' -> withCString "w" $ \w' ->
378+ then return $ Left $ YamlFileNotFound fp
380+ c_yaml_emitter_set_output_file e file
382+ c_yaml_emitter_delete e
364foreign import ccall unsafe "yaml_emitter_emit"
385foreign import ccall unsafe "yaml_emitter_emit"
365 c_yaml_emitter_emit :: Emitter -> EventRaw -> IO CInt
386 c_yaml_emitter_emit :: Emitter -> EventRaw -> IO CInt
@@ -501,13 +522,8 @@ encodeFile :: FilePath
501 -> (a -> Maybe (Event, a))
522 -> (a -> Maybe (Event, a))
503 -> IO (Either YamlException ())
524 -> IO (Either YamlException ())
504−encodeFile filePath unfold src = do
525+encodeFile filePath unfold src =
505− res <- withEmitter $ emitEvents unfold src
526+ withEmitterFile filePath $ emitEvents unfold src
507− Left e -> return $ Left e
509− Data.ByteString.writeFile filePath bs
512decode :: B.ByteString
528decode :: B.ByteString
513 -> (a -> Event -> Either a a)
529 -> (a -> Event -> Either a a)