]> gitweb.michael.orlitzky.com - dead/lwn-epub.git/blob - src/Misc.hs
Begin working on image replacemenent.
[dead/lwn-epub.git] / src / Misc.hs
1 module Misc
2 where
3
4 import qualified Data.ByteString.Lazy as B (ByteString, readFile)
5 import System.Directory (getTemporaryDirectory, removeFile)
6 import System.IO (hClose, hPutStr, hSetEncoding, openTempFile, utf8)
7
8 -- | Run a 'String' through the filesystem to convert it to a
9 -- 'ByteString' in the stupidest way possible.
10 string_to_bytestring :: String -> IO B.ByteString
11 string_to_bytestring s = do
12 dir <- getTemporaryDirectory
13 (path, h) <- openTempFile dir "nu1Uideehe"
14 hSetEncoding h utf8
15 hPutStr h s
16 hClose h
17 result <- B.readFile path
18 removeFile path
19 return result