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
Erikr source share