Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate ByteString in Haskell-Chart

I use Haskell-Chart according to the example eample-1. Haskell-Chart generates content to file

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

Is it possible generate content of chart to ByteString instead file? I can not find a solution in the documentation.

like image 213
QSpider Avatar asked Sep 20 '16 09:09

QSpider


1 Answers

Unfortunately this is not possible is a direct manner. toFile calls upon functions in the cairo library like withPDFSurface, withSVGSurface which themselves call into the cairo C-library and only take file names.

You can always write to a temporary file and read the contents back in like this:

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
like image 103
ErikR Avatar answered Oct 25 '22 23:10

ErikR