Use readFile from ByteString to read binary files

Reading a file that might contain PNG data using `System.IO.readFile`
causes `hGetContents: invalid argument (invalid byte sequence)` due to
file contents not being valid text under the current system locale.
This fixes loading diagrams into Jupyter notebooks.
This commit is contained in:
Manuel Gomez 2015-06-19 17:42:48 -04:30
parent 388d819e16
commit e7a27b42e9

View File

@ -34,11 +34,11 @@ diagramData renderable format = do
renderCairo filename (mkSizeSpec2D (Just imgWidth) (Just imgHeight)) renderable
-- Convert to base64.
imgData <- readFile filename
imgData <- Char.readFile filename
let value =
case format of
PNG -> png (floor imgWidth) (floor imgHeight) $ base64 (Char.pack imgData)
SVG -> svg imgData
PNG -> png (floor imgWidth) (floor imgHeight) $ base64 imgData
SVG -> svg (Char.unpack imgData)
return value