From 0cd0425903799e2de42a519345782262a3276441 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 18 Oct 2017 15:30:02 +0200 Subject: [PATCH] Zip UTF8-support --- src/Handler/Utils/Zip.hs | 14 +++++--------- stack.yaml | 5 ++++- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Handler/Utils/Zip.hs b/src/Handler/Utils/Zip.hs index 918bc93bc..ba23903b9 100644 --- a/src/Handler/Utils/Zip.hs +++ b/src/Handler/Utils/Zip.hs @@ -24,9 +24,6 @@ import qualified Data.ByteString.Lazy as Lazy.ByteString import Data.ByteString (ByteString) import qualified Data.ByteString as ByteString -import qualified Data.Text as Text -import qualified Data.Text.Encoding as Text - import System.FilePath import Data.Time @@ -52,14 +49,13 @@ consumeZip = unZipStream `fuseUpstream` consumeZip' case input of Nothing -> return () Just (Right _) -> throw $ userError "Data chunk in unexpected place when parsing ZIP" - Just (Left e) -> do - zipEntryName' <- fmap Text.unpack . either throw return . Text.decodeUtf8' $ zipEntryName e + Just (Left ZipEntry{..}) -> do contentChunks <- toConsumer accContents let - fileTitle = normalise $ makeValid zipEntryName' - fileModified = localTimeToUTC utc $ zipEntryTime e + fileTitle = normalise $ makeValid zipEntryName + fileModified = localTimeToUTC utc zipEntryTime fileContent - | hasTrailingPathSeparator zipEntryName' = Nothing + | hasTrailingPathSeparator zipEntryName = Nothing | otherwise = Just $ mconcat contentChunks yield $ File{..} consumeZip' @@ -89,7 +85,7 @@ produceZip info = mapC toZipData =$= void (zipStream zipOptions) toZipEntry :: File -> ZipEntry toZipEntry File{..} = ZipEntry - { zipEntryName = Text.encodeUtf8 . Text.pack . bool (dropWhileEnd isPathSeparator) addTrailingPathSeparator isDir . normalise . makeValid $ fileTitle + { zipEntryName = bool (dropWhileEnd isPathSeparator) addTrailingPathSeparator isDir . normalise . makeValid $ fileTitle , zipEntryTime = utcToLocalTime utc fileModified } where diff --git a/stack.yaml b/stack.yaml index 6f06cfe5a..a0b858e37 100644 --- a/stack.yaml +++ b/stack.yaml @@ -12,7 +12,7 @@ packages: extra-dep: true - location: git: https://github.com/pngwjpgh/zip-stream.git - commit: f6a40e6d214653cf405186e72d4e1b79065ec2d0 + commit: 9272bbed000928d500febad1cdc98d1da29d399e extra-dep: true extra-deps: - colonnade-1.1.1 @@ -21,4 +21,7 @@ extra-deps: - uuid-crypto-1.3.0.0 - cryptoids-0.3.0.0 - cryptoids-types-0.0.0 + +- encoding-0.8.2 +- regex-compat-0.93.1 resolver: lts-9.3