X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Flwn-epub.git;a=blobdiff_plain;f=src%2FMisc.hs;fp=src%2FMisc.hs;h=bec8917c58dcaafc5b3de63fd331e75a23228a13;hp=0000000000000000000000000000000000000000;hb=b591d5f5c3c47d253c24144beae1edf8648cd94b;hpb=8e5616a377196f0a200947173d4c78a3dca8a55f diff --git a/src/Misc.hs b/src/Misc.hs new file mode 100644 index 0000000..bec8917 --- /dev/null +++ b/src/Misc.hs @@ -0,0 +1,19 @@ +module Misc +where + +import qualified Data.ByteString.Lazy as B (ByteString, readFile) +import System.Directory (getTemporaryDirectory, removeFile) +import System.IO (hClose, hPutStr, hSetEncoding, openTempFile, utf8) + +-- | Run a 'String' through the filesystem to convert it to a +-- 'ByteString' in the stupidest way possible. +string_to_bytestring :: String -> IO B.ByteString +string_to_bytestring s = do + dir <- getTemporaryDirectory + (path, h) <- openTempFile dir "nu1Uideehe" + hSetEncoding h utf8 + hPutStr h s + hClose h + result <- B.readFile path + removeFile path + return result