module EpubParser where import Codec.Archive.Zip (toArchive, findEntryByPath, fromEntry, Archive) import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Lazy.Char8 as C8 openEpub :: FilePath -> IO (Either String Archive) openEpub path = toArchive <$> BL.readFile path >>= \archive -> maybe (pure $ Left "Error reading file") (\entry -> if fromEntry entry == C8.pack "application/epub+zip" then pure (Right archive) else pure (Left "Wrong mimetype")) (findEntryByPath "mimetype" archive) getOpfPath :: Archive -> Maybe FilePath getOpfPath archive = do entry <- findEntryByPath "META-INF/container.xml" archive return "OEBPS/content.opf"