From bb064eb0c7d36118bc8a3bd3871114cba131cb1d Mon Sep 17 00:00:00 2001 From: Tissevert Date: Thu, 23 May 2019 16:27:29 +0200 Subject: [PATCH] Adapt main for new Hufflepdf using strict ByteStrings + replace buggy lines / unlines by correct implementations --- src/Main.hs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index 2a23ba6..1b18b27 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -2,21 +2,28 @@ module Main where import Codec.Compression.Zlib (compress, decompress) -import Data.ByteString.Lazy.Char8 (ByteString) -import qualified Data.ByteString.Lazy.Char8 as BS ( - length, lines, readFile, unlines, writeFile +import Data.ByteString.Char8 (ByteString) +import qualified Data.ByteString.Char8 as BS ( + length, readFile + ) +import qualified Data.ByteString.Lazy.Char8 as Lazy ( + fromStrict, intercalate, pack, split, toStrict, writeFile ) import qualified Data.Map as Map (insert, lookup) import PDF (Document(..), parseDocument, render) import PDF.Object (Content(..), DirectObject(..), Object(..), Name(..), Number(..)) import PDF.TextRendering (TextRendering(..), update) +import Prelude hiding (lines, unlines) import System.Environment (getArgs) import System.IO (hPutStrLn, stderr) revealFlateEncodedText :: ByteString -> ByteString -revealFlateEncodedText = compress . revealText . decompress +revealFlateEncodedText = + Lazy.toStrict . compress . revealText . decompress . Lazy.fromStrict where - revealText = BS.unlines . fmap fill . BS.lines + lines = Lazy.split '\n' + unlines = Lazy.intercalate $ Lazy.pack "\n" + revealText = unlines . fmap fill . lines fill = update $ const Fill revealObject :: Object -> Object @@ -48,4 +55,4 @@ main = do result <- parseDocument <$> BS.readFile inputPath case result of Left parseError -> hPutStrLn stderr $ show parseError - Right doc -> BS.writeFile outputPath . render $ reveal doc + Right doc -> Lazy.writeFile outputPath . render $ reveal doc