zip-archive 0.2.3.4 → 0.2.3.5
raw patch · 3 files changed
+52/−4 lines, 3 filesdep ~binaryPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: binary
API changes (from Hackage documentation)
Files
- changelog +9/−0
- src/Codec/Archive/Zip.hs +41/−2
- zip-archive.cabal +2/−2
changelog view
@@ -1,3 +1,12 @@+zip-archive 0.2.3.5++ * Allow compilation with binary >= 0.5. Note that toArchiveOrFail+ is not safe when compiled against binary < 0.7; it will never+ return a Left value, and will raise an error if parsing fails,+ just like toArchive. This is documented in the haddocks.+ This is ugly, but justified by the need to have a version+ of zip-archive that compiles against older versions of binary.+ zip-archive 0.2.3.4 * Make sure all path comparisons compare normalized paths.
src/Codec/Archive/Zip.hs view
@@ -72,7 +72,9 @@ import System.IO ( stderr, hPutStrLn ) import qualified Data.Digest.CRC32 as CRC32 import qualified Data.Map as M+#if MIN_VERSION_binary(0,6,0) import Control.Applicative+#endif #ifndef _WINDOWS import System.Posix.Files ( setFileTimes ) #endif@@ -87,6 +89,19 @@ -- from zlib import qualified Codec.Compression.Zlib.Raw as Zlib +#if !MIN_VERSION_binary(0, 6, 0)+manySig :: Word32 -> Get a -> Get [a]+manySig sig p = do+ sig' <- lookAhead getWord32le+ if sig == sig'+ then do+ r <- p+ rs <- manySig sig p+ return $ r : rs+ else return []+#endif++ ------------------------------------------------------------------------ -- | Structured representation of a zip archive, including directory@@ -139,12 +154,19 @@ toArchive :: B.ByteString -> Archive toArchive = decode --- | Like 'toArchive', but returns an 'Either' value instead of raising an error--- if the archive cannot be decoded.+-- | Like 'toArchive', but returns an 'Either' value instead of raising an+-- error if the archive cannot be decoded. NOTE: This function only+-- works properly when the library is compiled against binary >= 0.7.+-- With earlier versions, it will always return a Right value,+-- raising an error if parsing fails. toArchiveOrFail :: B.ByteString -> Either String Archive+#if MIN_VERSION_binary(0,7,0) toArchiveOrFail bs = case decodeOrFail bs of Left (_,_,e) -> Left e Right (_,_,x) -> Right x+#else+toArchiveOrFail bs = Right $ toArchive bs+#endif -- | Writes an 'Archive' structure to a raw zip archive (in a lazy bytestring). fromArchive :: Archive -> B.ByteString@@ -435,9 +457,15 @@ getArchive :: Get Archive getArchive = do+#if MIN_VERSION_binary(0,6,0) locals <- many getLocalFile files <- many (getFileHeader (M.fromList locals)) digSig <- Just `fmap` getDigitalSignature <|> return Nothing+#else+ locals <- manySig 0x04034b50 getLocalFile+ files <- manySig 0x02014b50 (getFileHeader (M.fromList locals))+ digSig <- lookAheadM getDigitalSignature+#endif endSig <- getWord32le unless (endSig == 0x06054b50) $ fail "Did not find end of central directory signature"@@ -690,11 +718,22 @@ -- > size of data 2 bytes -- > signature data (variable size) +#if MIN_VERSION_binary(0,6,0) getDigitalSignature :: Get B.ByteString getDigitalSignature = do getWord32le >>= ensure (== 0x05054b50) sigSize <- getWord16le getLazyByteString (toEnum $ fromEnum sigSize)+#else+getDigitalSignature :: Get (Maybe B.ByteString)+getDigitalSignature = do+ hdrSig <- getWord32le+ if hdrSig /= 0x05054b50+ then return Nothing+ else do+ sigSize <- getWord16le+ getLazyByteString (toEnum $ fromEnum sigSize) >>= return . Just+#endif putDigitalSignature :: Maybe B.ByteString -> Put putDigitalSignature Nothing = return ()
zip-archive.cabal view
@@ -1,5 +1,5 @@ Name: zip-archive-Version: 0.2.3.4+Version: 0.2.3.5 Cabal-Version: >= 1.10 Build-type: Simple Synopsis: Library for creating and modifying zip archives.@@ -31,7 +31,7 @@ Build-depends: base >= 3 && < 5, pretty, containers else Build-depends: base < 3- Build-depends: binary >= 0.7, zlib, filepath, bytestring >= 0.9.0,+ Build-depends: binary >= 0.5, zlib, filepath, bytestring >= 0.9.0, array, mtl, text >= 0.11, old-time, digest >= 0.0.0.1, directory, time Exposed-modules: Codec.Archive.Zip