Creating a byte string in a Haskell-Chart

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

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

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

+5
source share
1 answer

Unfortunately, this is not possible directly. toFile calls functions in the cairo library, for example withPDFSurface , withSVGSurface , which themselves call the cairo C library and accept only file names.

You can always write to a temporary file and read the contents as follows:

 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 
+6
source

All Articles