compression (empty) → 0.1
raw patch · 10 files changed
+992/−0 lines, 10 filesdep +basedep +mtlbuild-type:Customsetup-changed
Dependencies added: base, mtl
Files
- BSD3 +26/−0
- COPYING +6/−0
- Codec/Compression/Deflate/Inflate.hs +343/−0
- Codec/Compression/GZip/GUnZip.hs +152/−0
- Codec/Compression/LazyStateT.hs +42/−0
- Codec/Compression/UnsafeInterleave.hs +15/−0
- Codec/Compression/Utils.hs +30/−0
- GPL-2 +340/−0
- Setup.hs +8/−0
- compression.cabal +30/−0
+ BSD3 view
@@ -0,0 +1,26 @@+Copyright (c) Ian Lynagh.+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:+1. Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.+2. Redistributions in binary form must reproduce the above copyright+ notice, this list of conditions and the following disclaimer in the+ documentation and/or other materials provided with the distribution.+3. The names of the author may not be used to endorse or promote+ products derived from this software without specific prior written+ permission.++THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF+SUCH DAMAGE.
+ COPYING view
@@ -0,0 +1,6 @@++Copyright (c) Ian Lynagh, 2004, 2007.++This package can be used under either the GPL v2, as in ./GPL-2, or the+3-clause BSD, as in ./BSD3, license.+
+ Codec/Compression/Deflate/Inflate.hs view
@@ -0,0 +1,343 @@++{-+Inflate implementation for Haskell++Copyright 2004, 2007 Ian Lynagh <igloo@earth.li>+Licence: Your choice of GPL version 2 or 3 clause BSD.++This module provides a Haskell implementation of the inflate function,+as described by RFC 1951.+-}++module Codec.Compression.Deflate.Inflate (Octets, inflate) where++import Codec.Compression.LazyStateT+import Codec.Compression.UnsafeInterleave+import Codec.Compression.Utils+-- import Control.Monad+import Control.Monad.State+-- import Data.Bits+import Data.List+import Data.IORef+-- import Data.Word+import Data.ByteString.Lazy (ByteString)+import qualified Data.ByteString.Lazy as BS+import Data.ByteString.Base (fromForeignPtr)+import Foreign++type Octet = Word8 -- The basic inut/output type+type Octets = ByteString -- We use lazy bytestrings rather than [Word8]+ -- for efficiency++type Code = Word16 -- A generic code+type Dist = Code -- A distance code (1-32768)+type LitLen = Code -- A literal/length code (3-258)+type Length = Word8 -- Number of bits needed to identify a code++type Table = InfM Code -- A Huffman table+type Tables = (Table, Table) -- lit/len and dist Huffman tables++data St = St {+ num_bits :: !Word8, -- number of remaining input bits+ bits :: !Word, -- remaining input bits (< 8)+ octets :: !Octets, -- remaining input octets+ history :: !(Ptr Octet), -- last 32768 output words+ loc :: !Word16, -- where in history we are+ var :: !(IORef Octets) -- where to put trailing chars+ }++type InfM a = LazyStateT St IO a++extract_InfM :: IORef Octets -> Octets -> InfM a -> IO a+extract_InfM ref os m+ = do arr <- mallocArray 32768+ let init_state = St {+ num_bits = 0,+ bits = 0,+ octets = os,+ history = arr,+ loc = 0,+ var = ref+ }+ evalLazyStateT m init_state++align_8_bits :: InfM ()+align_8_bits =+ do s <- get+ put $ s { bits = 0, num_bits = 0 }++-- n at most 65535+get_octets :: Word16 -> InfM Octets+get_octets n = do s <- get+ let os = octets s+ n' = fromIntegral n+ if BS.length os < n'+ then error "get_octets: Insufficient remaining"+ else case BS.splitAt n' os of+ (pref, suff) ->+ do put $ s { octets = suff }+ return pref++-- XXX Should we mask on return instead of on store?++-- i at most 16+get_w16 :: Word8 -> InfM Word16+get_w16 0 = return 0+get_w16 i+ = do s <- get+ let n = num_bits s+ if i == n then+ do put $ s { num_bits = 0, bits = 0 }+ return $ fromIntegral $ bits s+ else if i < n then+ do let bs = bits s+ i' = fromIntegral i+ mask = (1 `shiftL` i') - 1+ put $ s { num_bits = n - i, bits = bs `shiftR` i' }+ return $ fromIntegral $ (bs .&. mask)+ -- XXX Could inline from here down+ else do let os = octets s+ bs = fromIntegral $ BS.head os+ let new_bs = bs `shiftL` fromIntegral n+ put $ s { num_bits = num_bits s + 8,+ bits = bits s .|. new_bs,+ octets = BS.tail os }+ get_w16 i++-- i at most 8+get_w8 :: Word8 -> InfM Word8+get_w8 i = do w <- get_w16 i+ return (fromIntegral w)++get_bit :: InfM Bool+get_bit+ = do s <- get+ let n = num_bits s+ if n > 0 then do let bs = bits s+ put $ s { num_bits = n - 1,+ bits = bs `shiftR` 1 }+ return $ testBit bs 0+ else do let os = octets s+ bs = fromIntegral $ BS.head os+ put $ s { num_bits = 7,+ bits = bs `shiftR` 1,+ octets = BS.tail os }+ return $ testBit bs 0++{-+We have 2 ways to provide more output. We can either write a single+octet out or repeat a given number of bits a given distance back in the+history.+-}++output :: Octet -> InfM ()+output w =+ do s <- get+ let l = loc s+ lift $ pokeElemOff (history s) (fromIntegral l) w+ put $ s { loc = (l + 1) `mod` 32768 }++-- len `elem` [3..258]+-- dist `elem` [1..32768]+repeat_w32s :: Word16 -> Word16 -> InfM Octets+repeat_w32s len dist = do+ s <- get+ let l = loc s+ h = history s+ start_index = fromIntegral ((l - dist) `mod` 32768)+ len' = fromIntegral len+ -- XXX This should be roughly a moveArray+ f !0 !_ !_ = return ()+ f num 32768 to = f num 0 to+ f num from 32768 = f num from 0+ f num from to = do peekElemOff h from >>= pokeElemOff h to+ f (num - 1) (from + 1) (to + 1)+ put $ s { loc = (l + len) `mod` 32768 }+ lift $ f len start_index (fromIntegral l)+ fp <- lift $ mallocForeignPtrArray len'+ lift $ withForeignPtr fp $ \p ->+ if (start_index + len') <= 32768+ then copyArray p (h `advancePtr` start_index) len'+ else do let len1 = 32768 - start_index+ len2 = len' - len1+ copyArray p (h `advancePtr` start_index) len1+ copyArray (p `advancePtr` len1) h len2+ return $ BS.fromChunks [fromForeignPtr fp len']++{-+The hardcore stuff!++To inflate an octet stream we use inflate_blocks to do the hard work.+It in turn looks at the first 3 bits to decide whether to just output an+uncompressed segment or pass off the work to inflate_tables and+inflate_codes.+-}++inflate :: IORef Octets -> Octets -> IO Octets+inflate ref os = extract_InfM ref os (inflate_blocks False)++-- Bool is true if we have seen the "last" block marker+inflate_blocks :: Bool -> InfM Octets+inflate_blocks True+ = do align_8_bits -- redundant as we only look at octets+ s <- get+ liftIO $ writeIORef (var s) (octets s)+ return BS.empty+inflate_blocks False+ = do w <- get_w16 3 -- XXX Could be a more efficient type+ let is_last = testBit w 0+ case w `shiftR` 1 of+ 0 ->+ do align_8_bits+ len <- get_w16 16+ nlen <- get_w16 16+ -- check nlen = 1s complement of len+ unless (len + nlen == -1)+ $ error "inflate_blocks: Mismatched lengths"+ ws <- get_octets len+ mapM_ output $ BS.unpack ws -- XXX efficiency+ ws_tail <- unsafeInterleave $ inflate_blocks is_last+ return (ws `myAppend` ws_tail)+ 1 ->+ inflate_codes is_last inflate_trees_fixed+ 2 ->+ do tables <- inflate_tables+ inflate_codes is_last tables+ 3 -> error "inflate_blocks: case 11 reserved"+ _ -> error "inflate_blocks: can't happen"++inflate_tables :: InfM Tables+inflate_tables+ = do hlit <- get_w16 5+ hdist <- get_w16 5+ hclen <- get_w8 4+ let f i = do w <- get_w8 3+ return (w, i)+ order = [16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]+ llc_bs <- mapM f $ genericTake (hclen + 4) order+ let tab = make_table llc_bs+ lit_dist_lengths <- make_lit_dist_lengths tab+ (258 + hlit + hdist)+ (error "inflate_tables dummy")+ -- XXX Use Exactly variant?+ let (lit_lengths, dist_lengths) = genericSplitAt (257 + hlit)+ lit_dist_lengths+ lit_table = make_table (zip lit_lengths [0..])+ dist_table = make_table (zip dist_lengths [0..])+ return (lit_table, dist_table)++{-+make_lit_dist_lengths reads n (at most ~350) dist and length code+lengths.+-}++make_lit_dist_lengths :: Table -> Word16 -> Length -> InfM [Length]+make_lit_dist_lengths _ n _ | n < 0 = error "make_lit_dist_lengths n < 0"+make_lit_dist_lengths _ 0 _ = return []+make_lit_dist_lengths tab n last_thing+ = do c <- tab+ (ls, n', last_thing') <- meta_code n c last_thing+ ws <- make_lit_dist_lengths tab n' last_thing'+ return (ls ++ ws)++meta_code :: Word16 -> Code -> Length -> InfM ([Length], Word16, Length)+meta_code n i _ | i < 16 = let i' = fromIntegral i in return ([i'], n - 1, i')+meta_code n 16 last_thing+ = do w <- get_w16 2+ let l = 3 + w+ return (genericReplicate l last_thing, n - l, last_thing)+meta_code n 17 _ = do w <- get_w16 3+ let l = 3 + w+ return (genericReplicate l 0, n - l, 0)+meta_code n 18 _ = do w <- get_w16 7+ let l = 11 + w+ return (genericReplicate l 0, n - l, 0)+meta_code _ i _ = error $ "meta_code: " ++ show i++inflate_codes :: Bool -> Tables -> InfM Octets+inflate_codes seen_last tabs@(tab_litlen, tab_dist)+ = do i <- tab_litlen;+ if i == 256+ then inflate_blocks seen_last+ else do pref <- if i < 256+ then do let i' = fromIntegral i+ output i'+ return $ BS.singleton i'+ else case lookup i litlens of+ Nothing -> error "do_code_litlen"+ -- num_extra_bits `elem` [0..5]+ Just (base, num_extra_bits) ->+ do extra <- get_w16 num_extra_bits+ -- l `elem` [3..258]+ let l = base + extra+ -- dist `elem` [1..32768]+ dist <- dist_code tab_dist+ repeat_w32s l dist+ o <- unsafeInterleave $ inflate_codes seen_last tabs+ return (pref `myAppend` o)++litlens :: [(Code, (LitLen, Word8))]+litlens = zip [257..285] $ mk_bases 3 litlen_counts ++ [(258, 0)]+ where litlen_counts = [(8,0),(4,1),(4,2),(4,3),(4,4),(4,5)]++dist_code :: Table -> InfM Dist+dist_code tab+ = do code <- tab+ case lookup code dists of+ Nothing -> error "dist_code"+ -- num_extra_bits `elem` [0..13]+ Just (base, num_extra_bits) -> do extra <- get_w16 num_extra_bits+ return (base + extra)++dists :: [(Code, (Dist, Word8))]+dists = zip [0..29] $ mk_bases 1 dist_counts+ where dist_counts = (4,0):map ((,) 2) [1..13]++mk_bases :: Word16 -> [(Int, Word16)] -> [(Word16, Word8)]+mk_bases base counts = snd $ mapAccumL next_base base incs+ where next_base current bs = (current + 2^bs, (current, fromIntegral bs))+ incs = concat $ map (uncurry replicate) counts++-- The fixed tables.++inflate_trees_fixed :: Tables+inflate_trees_fixed = (make_table $ [(8, c) | c <- [0..143]]+ ++ [(9, c) | c <- [144..255]]+ ++ [(7, c) | c <- [256..279]]+ ++ [(8, c) | c <- [280..287]],+ make_table [(5, c) | c <- [0..29]])++{-+The Huffman Tree++As the name suggests, the obvious way to store Huffman trees is in a+tree datastructure. Externally we want to view them as functions though,+so we wrap the tree with \verb!get_code! which takes a list of bits and+returns the corresponding code and the remaining bits. To make a tree+from a list of length code pairs is a simple recursive process.+-}++data Tree = Branch Tree Tree | Leaf Code | Null++make_table :: [(Length, Code)] -> Table+make_table lcs = case make_tree 0 $ sort $ filter ((/= 0) . fst) lcs of+ (tree, []) -> get_code tree+ _ -> error $ "make_table: Left-over lcs from"++get_code :: Tree -> InfM Code+get_code (Branch zero_tree one_tree)+ = do b <- get_bit+ if b then get_code one_tree+ else get_code zero_tree+get_code (Leaf w) = return w+get_code Null = error "get_code Null"++make_tree :: Length -> [(Length, Code)] -> (Tree, [(Length, Code)])+make_tree _ [] = (Null, [])+make_tree i lcs@((l, c):lcs')+ | i == l = (Leaf c, lcs')+ | i < l = let (zero_tree, lcs_z) = make_tree (i+1) lcs+ (one_tree, lcs_o) = make_tree (i+1) lcs_z+ in (Branch zero_tree one_tree, lcs_o)+ | otherwise = error "make_tree: can't happen"+
+ Codec/Compression/GZip/GUnZip.hs view
@@ -0,0 +1,152 @@++module Codec.Compression.GZip.GUnZip (gunzip) where++import Codec.Compression.Deflate.Inflate+import Codec.Compression.LazyStateT+import Codec.Compression.UnsafeInterleave+import Codec.Compression.Utils++import Data.Char+import Data.IORef+import System.IO+import System.IO.Unsafe++import Control.Monad.State+import Control.Monad.Trans+import Data.Bits+import Data.Word+import Data.ByteString.Lazy (ByteString)+import qualified Data.ByteString.Lazy as BS++type GUnZipM a = LazyStateT ByteString IO a++readBytes :: Integral a => a -> GUnZipM ByteString+readBytes n = do xs <- get+ case genericSplitAtExactlyBS n xs of+ Just (ys, zs) ->+ do put zs+ return ys+ Nothing -> failWith $ InsufficientBytes "readBytes"++readNulTerminatedLatin1 :: GUnZipM ByteString+readNulTerminatedLatin1+ = do xs <- get+ case BS.break (0 ==) xs of+ (ys, zs)+ | not (BS.null zs) ->+ do put (BS.tail zs)+ return ys+ _ -> failWith $ InsufficientBytes "readNulTerminatedLatin1"++readWord8 :: GUnZipM Word8+readWord8 = do xs <- get+ case headTail xs of+ Just (x, xs') ->+ do put xs'+ return x+ Nothing -> failWith $ InsufficientBytes "readWord8"++readWord16 :: GUnZipM Word16+readWord16 = do xs0 <- get+ case do (x1, xs1) <- headTail xs0+ (x2, xs2) <- headTail xs1+ return (x1, x2, xs2) of+ Just (x1, x2, xs') ->+ do put xs'+ return ( (fromIntegral x1)+ + shiftL (fromIntegral x2) 8)+ Nothing -> failWith $ InsufficientBytes "readWord16"++readWord32 :: GUnZipM Word32+readWord32 = do xs0 <- get+ case do (x1, xs1) <- headTail xs0+ (x2, xs2) <- headTail xs1+ (x3, xs3) <- headTail xs2+ (x4, xs4) <- headTail xs3+ return (x1, x2, x3, x4, xs4) of+ Just (x1, x2, x3, x4, xs') ->+ do put xs'+ return ( (fromIntegral x1)+ + shiftL (fromIntegral x2) 8+ + shiftL (fromIntegral x3) 16+ + shiftL (fromIntegral x4) 24)+ Nothing -> failWith $ InsufficientBytes "readWord32"++-----++data Error = InsufficientBytes String+ | BadID1 Word8+ | BadID2 Word8+ | UnknownCompressionMethod Word8+ | ReservedFlagBitSet Int+ deriving Show++failWith :: Error -> GUnZipM a+failWith e = error ("Failure: Codec.Compression.GZip.GUnZip: " ++ show e)++readHeader :: GUnZipM () -- XXX Should return Header?+readHeader = do id1 <- readWord8+ unless (id1 == 31) $ failWith (BadID1 id1)+ id2 <- readWord8+ unless (id2 == 139) $ failWith (BadID2 id2)+ cm <- readWord8+ unless (cm == 8) $ failWith (UnknownCompressionMethod cm)+ flg <- readWord8+ -- We currently ignore flg bit 0 (FTEXT)+ when (testBit flg 5) $ failWith (ReservedFlagBitSet 5)+ when (testBit flg 6) $ failWith (ReservedFlagBitSet 6)+ when (testBit flg 7) $ failWith (ReservedFlagBitSet 7)+ _mtime <- readWord32 -- We ignore this for now+ _xfl <- readWord8 -- We ignore this for now+ _os <- readWord8 -- We ignore this for now+ -- We ignore this for now+ _m_fextra <- if testBit flg 2+ then do xlen <- readWord16+ extra <- readBytes xlen+ return (Just extra)+ else return Nothing+ -- We ignore this for now+ _m_fname <- if testBit flg 3+ then liftM Just readNulTerminatedLatin1+ else return Nothing+ -- We ignore this for now+ _m_fcomment <- if testBit flg 4+ then liftM Just readNulTerminatedLatin1+ else return Nothing+ _m_hcrc <- if testBit flg 1+ then liftM Just readWord16+ else return Nothing+ return ()++readFooter :: GUnZipM () -- XXX Should return Footer?+readFooter = do _crc32 <- readWord32 -- We ignore this for now+ _isize <- readWord32 -- We ignore this for now+ return ()++readChunks :: GUnZipM ByteString+readChunks+ = do bs <- get+ if BS.null bs then return BS.empty else do+ readHeader+ xs <- get+ put BS.empty -- We don't want the monad to hold on to the+ -- whole input+ var <- liftIO $ newIORef (error "IORef used before initialised")+ ws <- liftIO $ inflate var xs+ ws' <- unsafeInterleave $ do+ rest <- liftIO $ readIORef var+ put rest+ readFooter+ readChunks+ return (ws `myAppend` ws')++gunzip :: ByteString -> ByteString+gunzip xs = unsafePerformIO $ evalLazyStateT readChunks xs++{-+... (the compressed data)++CRC32 (4 bytes) CRC32 of the uncompressed data+ISIZE (4 bytes) uncompressed data size mod 2^32+-}+
+ Codec/Compression/LazyStateT.hs view
@@ -0,0 +1,42 @@++module Codec.Compression.LazyStateT where++import Control.Monad.State+import Codec.Compression.UnsafeInterleave++data LazyStateT s m a = LazyStateT { runLazyStateT :: s -> m (a, s) }++evalLazyStateT :: Monad m => LazyStateT s m a -> s -> m a+evalLazyStateT m s = do (x, _) <- runLazyStateT m s+ return x++execLazyStateT :: Monad m => LazyStateT s m a -> s -> m s+execLazyStateT m s = do (_, s') <- runLazyStateT m s+ return s'++instance Monad m => Monad (LazyStateT s m) where+ -- (>>=) :: LazyStateT s m a -> (a -> LazyStateT s m b) -> LazyStateT s m b+ LazyStateT v >>= f = LazyStateT $ \s -> do ~(x, s') <- v s+ let LazyStateT y = f x+ y s'+ -- return :: a -> LazyStateT s m a+ return x = LazyStateT $ \s -> return (x, s)+ -- fail :: String -> LazyStateT s m a+ fail str = LazyStateT $ \_ -> fail str++instance MonadTrans (LazyStateT s) where+ lift m = LazyStateT $ \s -> do x <- m+ return (x, s)++instance Monad m => MonadState s (LazyStateT s m) where+ get = LazyStateT $ \s -> return (s, s)+ put s = LazyStateT $ \_ -> return ((), s)++instance MonadIO m => MonadIO (LazyStateT s m) where+ liftIO m = LazyStateT $ \s -> do x <- liftIO m+ return (x, s)++instance UnsafeInterleave m => UnsafeInterleave (LazyStateT s m) where+ unsafeInterleave (LazyStateT v)+ = LazyStateT $ \s -> unsafeInterleave (v s)+
+ Codec/Compression/UnsafeInterleave.hs view
@@ -0,0 +1,15 @@++module Codec.Compression.UnsafeInterleave where++import Control.Monad.ST+import System.IO.Unsafe++class UnsafeInterleave m where+ unsafeInterleave :: m a -> m a++instance UnsafeInterleave IO where+ unsafeInterleave = unsafeInterleaveIO++instance UnsafeInterleave (ST s) where+ unsafeInterleave = unsafeInterleaveST+
+ Codec/Compression/Utils.hs view
@@ -0,0 +1,30 @@++module Codec.Compression.Utils where++import Data.ByteString.Lazy (ByteString)+import qualified Data.ByteString.Lazy as BS+import Data.ByteString.Base (LazyByteString(LPS))+import Data.Word (Word8)++genericSplitAtExactly :: Integral a => a -> [b] -> Maybe ([b], [b])+genericSplitAtExactly 0 xs = return ([], xs)+genericSplitAtExactly (n+1) (x:xs) = do (ys, zs) <- genericSplitAtExactly n xs+ return (x:ys, zs)+genericSplitAtExactly _ _ = Nothing++genericSplitAtExactlyBS :: Integral a+ => a -> ByteString -> Maybe (ByteString, ByteString)+genericSplitAtExactlyBS i bs = let i' = fromIntegral i+ in if i' > BS.length bs+ then Nothing+ else Just (BS.splitAt i' bs)++headTail :: ByteString -> Maybe (Word8, ByteString)+headTail bs = if BS.null bs+ then Nothing+ else Just (BS.head bs, BS.tail bs)++-- XXX The real append is too strict+myAppend :: ByteString -> ByteString -> ByteString+myAppend (LPS xs) (LPS ys) = LPS (xs ++ ys)+
+ GPL-2 view
@@ -0,0 +1,340 @@+ GNU GENERAL PUBLIC LICENSE+ Version 2, June 1991++ Copyright (C) 1989, 1991 Free Software Foundation, Inc.+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA+ Everyone is permitted to copy and distribute verbatim copies+ of this license document, but changing it is not allowed.++ Preamble++ The licenses for most software are designed to take away your+freedom to share and change it. By contrast, the GNU General Public+License is intended to guarantee your freedom to share and change free+software--to make sure the software is free for all its users. This+General Public License applies to most of the Free Software+Foundation's software and to any other program whose authors commit to+using it. (Some other Free Software Foundation software is covered by+the GNU Library General Public License instead.) You can apply it to+your programs, too.++ When we speak of free software, we are referring to freedom, not+price. Our General Public Licenses are designed to make sure that you+have the freedom to distribute copies of free software (and charge for+this service if you wish), that you receive source code or can get it+if you want it, that you can change the software or use pieces of it+in new free programs; and that you know you can do these things.++ To protect your rights, we need to make restrictions that forbid+anyone to deny you these rights or to ask you to surrender the rights.+These restrictions translate to certain responsibilities for you if you+distribute copies of the software, or if you modify it.++ For example, if you distribute copies of such a program, whether+gratis or for a fee, you must give the recipients all the rights that+you have. You must make sure that they, too, receive or can get the+source code. And you must show them these terms so they know their+rights.++ We protect your rights with two steps: (1) copyright the software, and+(2) offer you this license which gives you legal permission to copy,+distribute and/or modify the software.++ Also, for each author's protection and ours, we want to make certain+that everyone understands that there is no warranty for this free+software. If the software is modified by someone else and passed on, we+want its recipients to know that what they have is not the original, so+that any problems introduced by others will not reflect on the original+authors' reputations.++ Finally, any free program is threatened constantly by software+patents. We wish to avoid the danger that redistributors of a free+program will individually obtain patent licenses, in effect making the+program proprietary. To prevent this, we have made it clear that any+patent must be licensed for everyone's free use or not licensed at all.++ The precise terms and conditions for copying, distribution and+modification follow.++ GNU GENERAL PUBLIC LICENSE+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION++ 0. This License applies to any program or other work which contains+a notice placed by the copyright holder saying it may be distributed+under the terms of this General Public License. The "Program", below,+refers to any such program or work, and a "work based on the Program"+means either the Program or any derivative work under copyright law:+that is to say, a work containing the Program or a portion of it,+either verbatim or with modifications and/or translated into another+language. (Hereinafter, translation is included without limitation in+the term "modification".) Each licensee is addressed as "you".++Activities other than copying, distribution and modification are not+covered by this License; they are outside its scope. The act of+running the Program is not restricted, and the output from the Program+is covered only if its contents constitute a work based on the+Program (independent of having been made by running the Program).+Whether that is true depends on what the Program does.++ 1. You may copy and distribute verbatim copies of the Program's+source code as you receive it, in any medium, provided that you+conspicuously and appropriately publish on each copy an appropriate+copyright notice and disclaimer of warranty; keep intact all the+notices that refer to this License and to the absence of any warranty;+and give any other recipients of the Program a copy of this License+along with the Program.++You may charge a fee for the physical act of transferring a copy, and+you may at your option offer warranty protection in exchange for a fee.++ 2. You may modify your copy or copies of the Program or any portion+of it, thus forming a work based on the Program, and copy and+distribute such modifications or work under the terms of Section 1+above, provided that you also meet all of these conditions:++ a) You must cause the modified files to carry prominent notices+ stating that you changed the files and the date of any change.++ b) You must cause any work that you distribute or publish, that in+ whole or in part contains or is derived from the Program or any+ part thereof, to be licensed as a whole at no charge to all third+ parties under the terms of this License.++ c) If the modified program normally reads commands interactively+ when run, you must cause it, when started running for such+ interactive use in the most ordinary way, to print or display an+ announcement including an appropriate copyright notice and a+ notice that there is no warranty (or else, saying that you provide+ a warranty) and that users may redistribute the program under+ these conditions, and telling the user how to view a copy of this+ License. (Exception: if the Program itself is interactive but+ does not normally print such an announcement, your work based on+ the Program is not required to print an announcement.)++These requirements apply to the modified work as a whole. If+identifiable sections of that work are not derived from the Program,+and can be reasonably considered independent and separate works in+themselves, then this License, and its terms, do not apply to those+sections when you distribute them as separate works. But when you+distribute the same sections as part of a whole which is a work based+on the Program, the distribution of the whole must be on the terms of+this License, whose permissions for other licensees extend to the+entire whole, and thus to each and every part regardless of who wrote it.++Thus, it is not the intent of this section to claim rights or contest+your rights to work written entirely by you; rather, the intent is to+exercise the right to control the distribution of derivative or+collective works based on the Program.++In addition, mere aggregation of another work not based on the Program+with the Program (or with a work based on the Program) on a volume of+a storage or distribution medium does not bring the other work under+the scope of this License.++ 3. You may copy and distribute the Program (or a work based on it,+under Section 2) in object code or executable form under the terms of+Sections 1 and 2 above provided that you also do one of the following:++ a) Accompany it with the complete corresponding machine-readable+ source code, which must be distributed under the terms of Sections+ 1 and 2 above on a medium customarily used for software interchange; or,++ b) Accompany it with a written offer, valid for at least three+ years, to give any third party, for a charge no more than your+ cost of physically performing source distribution, a complete+ machine-readable copy of the corresponding source code, to be+ distributed under the terms of Sections 1 and 2 above on a medium+ customarily used for software interchange; or,++ c) Accompany it with the information you received as to the offer+ to distribute corresponding source code. (This alternative is+ allowed only for noncommercial distribution and only if you+ received the program in object code or executable form with such+ an offer, in accord with Subsection b above.)++The source code for a work means the preferred form of the work for+making modifications to it. For an executable work, complete source+code means all the source code for all modules it contains, plus any+associated interface definition files, plus the scripts used to+control compilation and installation of the executable. However, as a+special exception, the source code distributed need not include+anything that is normally distributed (in either source or binary+form) with the major components (compiler, kernel, and so on) of the+operating system on which the executable runs, unless that component+itself accompanies the executable.++If distribution of executable or object code is made by offering+access to copy from a designated place, then offering equivalent+access to copy the source code from the same place counts as+distribution of the source code, even though third parties are not+compelled to copy the source along with the object code.++ 4. You may not copy, modify, sublicense, or distribute the Program+except as expressly provided under this License. Any attempt+otherwise to copy, modify, sublicense or distribute the Program is+void, and will automatically terminate your rights under this License.+However, parties who have received copies, or rights, from you under+this License will not have their licenses terminated so long as such+parties remain in full compliance.++ 5. You are not required to accept this License, since you have not+signed it. However, nothing else grants you permission to modify or+distribute the Program or its derivative works. These actions are+prohibited by law if you do not accept this License. Therefore, by+modifying or distributing the Program (or any work based on the+Program), you indicate your acceptance of this License to do so, and+all its terms and conditions for copying, distributing or modifying+the Program or works based on it.++ 6. Each time you redistribute the Program (or any work based on the+Program), the recipient automatically receives a license from the+original licensor to copy, distribute or modify the Program subject to+these terms and conditions. You may not impose any further+restrictions on the recipients' exercise of the rights granted herein.+You are not responsible for enforcing compliance by third parties to+this License.++ 7. If, as a consequence of a court judgment or allegation of patent+infringement or for any other reason (not limited to patent issues),+conditions are imposed on you (whether by court order, agreement or+otherwise) that contradict the conditions of this License, they do not+excuse you from the conditions of this License. If you cannot+distribute so as to satisfy simultaneously your obligations under this+License and any other pertinent obligations, then as a consequence you+may not distribute the Program at all. For example, if a patent+license would not permit royalty-free redistribution of the Program by+all those who receive copies directly or indirectly through you, then+the only way you could satisfy both it and this License would be to+refrain entirely from distribution of the Program.++If any portion of this section is held invalid or unenforceable under+any particular circumstance, the balance of the section is intended to+apply and the section as a whole is intended to apply in other+circumstances.++It is not the purpose of this section to induce you to infringe any+patents or other property right claims or to contest validity of any+such claims; this section has the sole purpose of protecting the+integrity of the free software distribution system, which is+implemented by public license practices. Many people have made+generous contributions to the wide range of software distributed+through that system in reliance on consistent application of that+system; it is up to the author/donor to decide if he or she is willing+to distribute software through any other system and a licensee cannot+impose that choice.++This section is intended to make thoroughly clear what is believed to+be a consequence of the rest of this License.++ 8. If the distribution and/or use of the Program is restricted in+certain countries either by patents or by copyrighted interfaces, the+original copyright holder who places the Program under this License+may add an explicit geographical distribution limitation excluding+those countries, so that distribution is permitted only in or among+countries not thus excluded. In such case, this License incorporates+the limitation as if written in the body of this License.++ 9. The Free Software Foundation may publish revised and/or new versions+of the General Public License from time to time. Such new versions will+be similar in spirit to the present version, but may differ in detail to+address new problems or concerns.++Each version is given a distinguishing version number. If the Program+specifies a version number of this License which applies to it and "any+later version", you have the option of following the terms and conditions+either of that version or of any later version published by the Free+Software Foundation. If the Program does not specify a version number of+this License, you may choose any version ever published by the Free Software+Foundation.++ 10. If you wish to incorporate parts of the Program into other free+programs whose distribution conditions are different, write to the author+to ask for permission. For software which is copyrighted by the Free+Software Foundation, write to the Free Software Foundation; we sometimes+make exceptions for this. Our decision will be guided by the two goals+of preserving the free status of all derivatives of our free software and+of promoting the sharing and reuse of software generally.++ NO WARRANTY++ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,+REPAIR OR CORRECTION.++ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE+POSSIBILITY OF SUCH DAMAGES.++ END OF TERMS AND CONDITIONS++ How to Apply These Terms to Your New Programs++ If you develop a new program, and you want it to be of the greatest+possible use to the public, the best way to achieve this is to make it+free software which everyone can redistribute and change under these terms.++ To do so, attach the following notices to the program. It is safest+to attach them to the start of each source file to most effectively+convey the exclusion of warranty; and each file should have at least+the "copyright" line and a pointer to where the full notice is found.++ <one line to give the program's name and a brief idea of what it does.>+ Copyright (C) <year> <name of author>++ This program is free software; you can redistribute it and/or modify+ it under the terms of the GNU General Public License as published by+ the Free Software Foundation; either version 2 of the License, or+ (at your option) any later version.++ This program is distributed in the hope that it will be useful,+ but WITHOUT ANY WARRANTY; without even the implied warranty of+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ GNU General Public License for more details.++ You should have received a copy of the GNU General Public License+ along with this program; if not, write to the Free Software+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA+++Also add information on how to contact you by electronic and paper mail.++If the program is interactive, make it output a short notice like this+when it starts in an interactive mode:++ Gnomovision version 69, Copyright (C) year name of author+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.+ This is free software, and you are welcome to redistribute it+ under certain conditions; type `show c' for details.++The hypothetical commands `show w' and `show c' should show the appropriate+parts of the General Public License. Of course, the commands you use may+be called something other than `show w' and `show c'; they could even be+mouse-clicks or menu items--whatever suits your program.++You should also get your employer (if you work as a programmer) or your+school, if any, to sign a "copyright disclaimer" for the program, if+necessary. Here is a sample; alter the names:++ Yoyodyne, Inc., hereby disclaims all copyright interest in the program+ `Gnomovision' (which makes passes at compilers) written by James Hacker.++ <signature of Ty Coon>, 1 April 1989+ Ty Coon, President of Vice++This General Public License does not permit incorporating your program into+proprietary programs. If your program is a subroutine library, you may+consider it more useful to permit linking proprietary applications with the+library. If this is what you want to do, use the GNU Library General+Public License instead of this License.
+ Setup.hs view
@@ -0,0 +1,8 @@++module Main (main) where++import Distribution.Simple++main :: IO ()+main = defaultMain+
+ compression.cabal view
@@ -0,0 +1,30 @@+Name: compression+Version: 0.1+License: OtherLicense+License-File: COPYING+Copyright: Ian Lynagh, 2004, 2007+Author: Ian Lynagh+Maintainer: igloo@earth.li+Stability: experimental+Homepage: http://urchin.earth.li/~ian/cabal/compression/+Synopsis: Common compression algorithms.+Description:+ Currently contains:+ * An implementation of the inflate algorithm from RFC 1951+ (decompression only).+ * An implementation of the gzip algorithm from RFC 1952+ (decompression only).+Category: Codec+Extensions: MultiParamTypeClasses, BangPatterns+Tested-With: GHC==6.6+Build-Depends: base, mtl+Extra-source-files: "BSD3", "GPL-2"+Exposed-modules:+ Codec.Compression.Deflate.Inflate+ Codec.Compression.GZip.GUnZip+Other-modules:+ Codec.Compression.LazyStateT+ Codec.Compression.UnsafeInterleave+ Codec.Compression.Utils+GHC-Options: -O -Wall+