2016-09-20 60 views
5

根据示例eample-1,我使用了Haskell-Chart。哈斯克尔,图表生成内容提交在Haskell-Chart中生成ByteString

toFile def "example1_big.png" $ do 
... 

是否有可能产生以字节字符串的文件,而不是图表的内容? 我在文档中找不到解决方案。

回答

6

不幸的是,这是不可能的,是一种直接的方式。 toFile调用cairo库中的函数,如withPDFSurface,withSVGSurface,这些函数本身调用cairo C库并仅采用文件名。

你总是可以写一个临时文件,这样在后面的阅读内容:

import System.IO.Temp -- from the temporary package 
import qualified Data.ByteString.Char8 as BS 

... 
bs <- withSystemTempFile "chart-XXXXXXX" $ \path _ -> do 
     toFile def path $ do ... 
     BS.readFile path