[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36

John Goerzen jgoerzen at complete.org
Fri Apr 23 14:50:15 UTC 2010


The following commit has been merged in the master branch:
commit f70fe430223f98a90a0a173b7bb8d93b8d5aeea0
Author: John Goerzen <jgoerzen at complete.org>
Date:   Sun Dec 5 02:07:11 2004 +0100

    Adjusted gzip interface slightly
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--0.7--patch-46)

diff --git a/ChangeLog b/ChangeLog
index 4d94bed..368b1bb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,19 @@
 # arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--0.7
 #
 
+2004-12-04 19:07:11 GMT	John Goerzen <jgoerzen at complete.org>	patch-46
+
+    Summary:
+      Adjusted gzip interface slightly
+    Revision:
+      missingh--head--0.7--patch-46
+
+
+    modified files:
+     ChangeLog libsrc/MissingH/FileArchive/GZip.hs
+     testsrc/GZiptest.hs
+
+
 2004-12-04 18:21:15 GMT	John Goerzen <jgoerzen at complete.org>	patch-45
 
     Summary:
diff --git a/libsrc/MissingH/FileArchive/GZip.hs b/libsrc/MissingH/FileArchive/GZip.hs
index aea921e..4afb0e0 100644
--- a/libsrc/MissingH/FileArchive/GZip.hs
+++ b/libsrc/MissingH/FileArchive/GZip.hs
@@ -36,7 +36,7 @@ module MissingH.FileArchive.GZip (
                                   -- * GZip Files
                                   -- $gzipfiles
                                   -- * Types
-                                  Header(..), Section, GZipError, Footer(..),
+                                  Header(..), Section, GZipError(..), Footer(..),
                                   -- * Whole-File Processing
                                   decompress,
                                   read_sections,
@@ -55,7 +55,15 @@ import Data.Char
 import Data.Word
 import MissingH.Bits
 
-type GZipError = String
+data GZipError = CRCError               -- ^ CRC-32 check failed
+               | NotGZIPFile            -- ^ Couldn't find a GZip header
+               | UnknownMethod          -- ^ Compressed with something other than method 8 (deflate)
+               | UnknownError String    -- ^ Other problem arose
+               deriving (Eq, Show)
+
+instance Error GZipError where
+    noMsg = UnknownError ""
+    strMsg = UnknownError
 
 -- | First two bytes of file
 magic = "\x1f\x8b"
@@ -96,27 +104,27 @@ split1 s = (head s, tail s)
 
 {- | Read a GZip file, decompressing all sections that are found.
 
-Returns a decompresed data stream and a Bool indicating whether or not
-all CRC32 values were successfully verified.
+Returns a decompresed data stream and Nothing, or an unreliable string
+and Just (error).  If you get anything other than Nothing, the String
+returned should be discarded.
 -}
-decompress :: String -> Either GZipError (String, Bool)
+decompress :: String -> (String, Maybe GZipError)
 {-
 decompress s = 
     do x <- read_header s
        let rem = snd x
        return $ inflate_string rem
 -}
-
 decompress s = 
     let procs :: [Section] -> (String, Bool)
         procs [] = ([], True)
         procs ((_, content, foot):xs) = 
             let (nexth, nextb) = procs xs in
                 (content ++ nexth, (crc32valid foot) && nextb)
---                (content ++ nexth, (&&) nextb $! (crc32valid foot))
-        in
-        do x <- read_sections s
-           return $ procs x
+        in case read_sections s of
+           Left x -> ("", Just x)
+           Right x -> let (decomp, iscrcok) = procs x
+                          in (decomp, if iscrcok then Nothing else Just CRCError)
 
 {-
 decompress s = do x <- read_sections s
@@ -176,11 +184,11 @@ read_header s =
     let ok = Right "ok" in
     do let (mag, rem) = splitAt 2 s
        if mag /= magic
-          then throwError "Not a GZip file"
+          then throwError NotGZIPFile
           else ok
        let (method, rem2) = split1 rem
        if (ord(method) /= 8)
-          then throwError "Unknown compression method"
+          then throwError UnknownMethod
           else ok
        let (flag_S, rem3) = split1 rem2
        let flag = ord flag_S
diff --git a/testsrc/GZiptest.hs b/testsrc/GZiptest.hs
index 6f9d290..32855d8 100644
--- a/testsrc/GZiptest.hs
+++ b/testsrc/GZiptest.hs
@@ -72,15 +72,15 @@ test_header =
         ]
 
 test_gunzip =
-    let f fn exp = mf fn (Right exp) decompress
+    let f fn exp = mf fn exp decompress
         in
         [
-         f "t1.gz" ("Test 1", True)
-        ,f "t1bad.gz" ("Test 1", False)
-        ,f "t2.gz" ("Test 1Test 2", True)
+         f "t1.gz" ("Test 1", Nothing)
+        ,f "t1bad.gz" ("Test 1", Just CRCError)
+        ,f "t2.gz" ("Test 1Test 2", Nothing)
         ,mf "zeros.gz" True (\x -> case decompress x of
-                                Right (y, _) -> y == replicate 10485760 '\0'
-                                _ -> False)
+                             (y, _) -> y == replicate 10485760 '\0'
+                            )
         ]
 
 tests = TestList [TestLabel "inflate" (TestList test_inflate),

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list