]> gitweb.michael.orlitzky.com - dead/lwn-epub.git/blobdiff - src/Misc.hs
Add a first draft using HXT, HandsomeSoup, and the Haskell epub library.
[dead/lwn-epub.git] / src / Misc.hs
diff --git a/src/Misc.hs b/src/Misc.hs
new file mode 100644 (file)
index 0000000..bec8917
--- /dev/null
@@ -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