packages feed

snappy-framing (empty) → 0.1.0

raw patch · 6 files changed

+797/−0 lines, 6 filesdep +arraydep +basedep +binarysetup-changed

Dependencies added: array, base, binary, bytestring, snappy

Files

+ LICENSE view
@@ -0,0 +1,373 @@+Mozilla Public License Version 2.0+==================================++1. Definitions+--------------++1.1. "Contributor"+    means each individual or legal entity that creates, contributes to+    the creation of, or owns Covered Software.++1.2. "Contributor Version"+    means the combination of the Contributions of others (if any) used+    by a Contributor and that particular Contributor's Contribution.++1.3. "Contribution"+    means Covered Software of a particular Contributor.++1.4. "Covered Software"+    means Source Code Form to which the initial Contributor has attached+    the notice in Exhibit A, the Executable Form of such Source Code+    Form, and Modifications of such Source Code Form, in each case+    including portions thereof.++1.5. "Incompatible With Secondary Licenses"+    means++    (a) that the initial Contributor has attached the notice described+        in Exhibit B to the Covered Software; or++    (b) that the Covered Software was made available under the terms of+        version 1.1 or earlier of the License, but not also under the+        terms of a Secondary License.++1.6. "Executable Form"+    means any form of the work other than Source Code Form.++1.7. "Larger Work"+    means a work that combines Covered Software with other material, in+    a separate file or files, that is not Covered Software.++1.8. "License"+    means this document.++1.9. "Licensable"+    means having the right to grant, to the maximum extent possible,+    whether at the time of the initial grant or subsequently, any and+    all of the rights conveyed by this License.++1.10. "Modifications"+    means any of the following:++    (a) any file in Source Code Form that results from an addition to,+        deletion from, or modification of the contents of Covered+        Software; or++    (b) any new file in Source Code Form that contains any Covered+        Software.++1.11. "Patent Claims" of a Contributor+    means any patent claim(s), including without limitation, method,+    process, and apparatus claims, in any patent Licensable by such+    Contributor that would be infringed, but for the grant of the+    License, by the making, using, selling, offering for sale, having+    made, import, or transfer of either its Contributions or its+    Contributor Version.++1.12. "Secondary License"+    means either the GNU General Public License, Version 2.0, the GNU+    Lesser General Public License, Version 2.1, the GNU Affero General+    Public License, Version 3.0, or any later versions of those+    licenses.++1.13. "Source Code Form"+    means the form of the work preferred for making modifications.++1.14. "You" (or "Your")+    means an individual or a legal entity exercising rights under this+    License. For legal entities, "You" includes any entity that+    controls, is controlled by, or is under common control with You. For+    purposes of this definition, "control" means (a) the power, direct+    or indirect, to cause the direction or management of such entity,+    whether by contract or otherwise, or (b) ownership of more than+    fifty percent (50%) of the outstanding shares or beneficial+    ownership of such entity.++2. License Grants and Conditions+--------------------------------++2.1. Grants++Each Contributor hereby grants You a world-wide, royalty-free,+non-exclusive license:++(a) under intellectual property rights (other than patent or trademark)+    Licensable by such Contributor to use, reproduce, make available,+    modify, display, perform, distribute, and otherwise exploit its+    Contributions, either on an unmodified basis, with Modifications, or+    as part of a Larger Work; and++(b) under Patent Claims of such Contributor to make, use, sell, offer+    for sale, have made, import, and otherwise transfer either its+    Contributions or its Contributor Version.++2.2. Effective Date++The licenses granted in Section 2.1 with respect to any Contribution+become effective for each Contribution on the date the Contributor first+distributes such Contribution.++2.3. Limitations on Grant Scope++The licenses granted in this Section 2 are the only rights granted under+this License. No additional rights or licenses will be implied from the+distribution or licensing of Covered Software under this License.+Notwithstanding Section 2.1(b) above, no patent license is granted by a+Contributor:++(a) for any code that a Contributor has removed from Covered Software;+    or++(b) for infringements caused by: (i) Your and any other third party's+    modifications of Covered Software, or (ii) the combination of its+    Contributions with other software (except as part of its Contributor+    Version); or++(c) under Patent Claims infringed by Covered Software in the absence of+    its Contributions.++This License does not grant any rights in the trademarks, service marks,+or logos of any Contributor (except as may be necessary to comply with+the notice requirements in Section 3.4).++2.4. Subsequent Licenses++No Contributor makes additional grants as a result of Your choice to+distribute the Covered Software under a subsequent version of this+License (see Section 10.2) or under the terms of a Secondary License (if+permitted under the terms of Section 3.3).++2.5. Representation++Each Contributor represents that the Contributor believes its+Contributions are its original creation(s) or it has sufficient rights+to grant the rights to its Contributions conveyed by this License.++2.6. Fair Use++This License is not intended to limit any rights You have under+applicable copyright doctrines of fair use, fair dealing, or other+equivalents.++2.7. Conditions++Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted+in Section 2.1.++3. Responsibilities+-------------------++3.1. Distribution of Source Form++All distribution of Covered Software in Source Code Form, including any+Modifications that You create or to which You contribute, must be under+the terms of this License. You must inform recipients that the Source+Code Form of the Covered Software is governed by the terms of this+License, and how they can obtain a copy of this License. You may not+attempt to alter or restrict the recipients' rights in the Source Code+Form.++3.2. Distribution of Executable Form++If You distribute Covered Software in Executable Form then:++(a) such Covered Software must also be made available in Source Code+    Form, as described in Section 3.1, and You must inform recipients of+    the Executable Form how they can obtain a copy of such Source Code+    Form by reasonable means in a timely manner, at a charge no more+    than the cost of distribution to the recipient; and++(b) You may distribute such Executable Form under the terms of this+    License, or sublicense it under different terms, provided that the+    license for the Executable Form does not attempt to limit or alter+    the recipients' rights in the Source Code Form under this License.++3.3. Distribution of a Larger Work++You may create and distribute a Larger Work under terms of Your choice,+provided that You also comply with the requirements of this License for+the Covered Software. If the Larger Work is a combination of Covered+Software with a work governed by one or more Secondary Licenses, and the+Covered Software is not Incompatible With Secondary Licenses, this+License permits You to additionally distribute such Covered Software+under the terms of such Secondary License(s), so that the recipient of+the Larger Work may, at their option, further distribute the Covered+Software under the terms of either this License or such Secondary+License(s).++3.4. Notices++You may not remove or alter the substance of any license notices+(including copyright notices, patent notices, disclaimers of warranty,+or limitations of liability) contained within the Source Code Form of+the Covered Software, except that You may alter any license notices to+the extent required to remedy known factual inaccuracies.++3.5. Application of Additional Terms++You may choose to offer, and to charge a fee for, warranty, support,+indemnity or liability obligations to one or more recipients of Covered+Software. However, You may do so only on Your own behalf, and not on+behalf of any Contributor. You must make it absolutely clear that any+such warranty, support, indemnity, or liability obligation is offered by+You alone, and You hereby agree to indemnify every Contributor for any+liability incurred by such Contributor as a result of warranty, support,+indemnity or liability terms You offer. You may include additional+disclaimers of warranty and limitations of liability specific to any+jurisdiction.++4. Inability to Comply Due to Statute or Regulation+---------------------------------------------------++If it is impossible for You to comply with any of the terms of this+License with respect to some or all of the Covered Software due to+statute, judicial order, or regulation then You must: (a) comply with+the terms of this License to the maximum extent possible; and (b)+describe the limitations and the code they affect. Such description must+be placed in a text file included with all distributions of the Covered+Software under this License. Except to the extent prohibited by statute+or regulation, such description must be sufficiently detailed for a+recipient of ordinary skill to be able to understand it.++5. Termination+--------------++5.1. The rights granted under this License will terminate automatically+if You fail to comply with any of its terms. However, if You become+compliant, then the rights granted under this License from a particular+Contributor are reinstated (a) provisionally, unless and until such+Contributor explicitly and finally terminates Your grants, and (b) on an+ongoing basis, if such Contributor fails to notify You of the+non-compliance by some reasonable means prior to 60 days after You have+come back into compliance. Moreover, Your grants from a particular+Contributor are reinstated on an ongoing basis if such Contributor+notifies You of the non-compliance by some reasonable means, this is the+first time You have received notice of non-compliance with this License+from such Contributor, and You become compliant prior to 30 days after+Your receipt of the notice.++5.2. If You initiate litigation against any entity by asserting a patent+infringement claim (excluding declaratory judgment actions,+counter-claims, and cross-claims) alleging that a Contributor Version+directly or indirectly infringes any patent, then the rights granted to+You by any and all Contributors for the Covered Software under Section+2.1 of this License shall terminate.++5.3. In the event of termination under Sections 5.1 or 5.2 above, all+end user license agreements (excluding distributors and resellers) which+have been validly granted by You or Your distributors under this License+prior to termination shall survive termination.++************************************************************************+*                                                                      *+*  6. Disclaimer of Warranty                                           *+*  -------------------------                                           *+*                                                                      *+*  Covered Software is provided under this License on an "as is"       *+*  basis, without warranty of any kind, either expressed, implied, or  *+*  statutory, including, without limitation, warranties that the       *+*  Covered Software is free of defects, merchantable, fit for a        *+*  particular purpose or non-infringing. The entire risk as to the     *+*  quality and performance of the Covered Software is with You.        *+*  Should any Covered Software prove defective in any respect, You     *+*  (not any Contributor) assume the cost of any necessary servicing,   *+*  repair, or correction. This disclaimer of warranty constitutes an   *+*  essential part of this License. No use of any Covered Software is   *+*  authorized under this License except under this disclaimer.         *+*                                                                      *+************************************************************************++************************************************************************+*                                                                      *+*  7. Limitation of Liability                                          *+*  --------------------------                                          *+*                                                                      *+*  Under no circumstances and under no legal theory, whether tort      *+*  (including negligence), contract, or otherwise, shall any           *+*  Contributor, or anyone who distributes Covered Software as          *+*  permitted above, be liable to You for any direct, indirect,         *+*  special, incidental, or consequential damages of any character      *+*  including, without limitation, damages for lost profits, loss of    *+*  goodwill, work stoppage, computer failure or malfunction, or any    *+*  and all other commercial damages or losses, even if such party      *+*  shall have been informed of the possibility of such damages. This   *+*  limitation of liability shall not apply to liability for death or   *+*  personal injury resulting from such party's negligence to the       *+*  extent applicable law prohibits such limitation. Some               *+*  jurisdictions do not allow the exclusion or limitation of           *+*  incidental or consequential damages, so this exclusion and          *+*  limitation may not apply to You.                                    *+*                                                                      *+************************************************************************++8. Litigation+-------------++Any litigation relating to this License may be brought only in the+courts of a jurisdiction where the defendant maintains its principal+place of business and such litigation shall be governed by laws of that+jurisdiction, without reference to its conflict-of-law provisions.+Nothing in this Section shall prevent a party's ability to bring+cross-claims or counter-claims.++9. Miscellaneous+----------------++This License represents the complete agreement concerning the subject+matter hereof. If any provision of this License is held to be+unenforceable, such provision shall be reformed only to the extent+necessary to make it enforceable. Any law or regulation which provides+that the language of a contract shall be construed against the drafter+shall not be used to construe this License against a Contributor.++10. Versions of the License+---------------------------++10.1. New Versions++Mozilla Foundation is the license steward. Except as provided in Section+10.3, no one other than the license steward has the right to modify or+publish new versions of this License. Each version will be given a+distinguishing version number.++10.2. Effect of New Versions++You may distribute the Covered Software under the terms of the version+of the License under which You originally received the Covered Software,+or under the terms of any subsequent version published by the license+steward.++10.3. Modified Versions++If you create software not governed by this License, and you want to+create a new license for such software, you may create and use a+modified version of this License if you rename the license and remove+any references to the name of the license steward (except to note that+such modified license differs from this License).++10.4. Distributing Source Code Form that is Incompatible With Secondary+Licenses++If You choose to distribute Source Code Form that is Incompatible With+Secondary Licenses under the terms of this version of the License, the+notice described in Exhibit B of this License must be attached.++Exhibit A - Source Code Form License Notice+-------------------------------------------++  This Source Code Form is subject to the terms of the Mozilla Public+  License, v. 2.0. If a copy of the MPL was not distributed with this+  file, You can obtain one at http://mozilla.org/MPL/2.0/.++If it is not possible or desirable to put the notice in a particular+file, then You may include the notice in a location (such as a LICENSE+file in a relevant directory) where a recipient would be likely to look+for such a notice.++You may add additional accurate notices of copyright ownership.++Exhibit B - "Incompatible With Secondary Licenses" Notice+---------------------------------------------------------++  This Source Code Form is "Incompatible With Secondary Licenses", as+  defined by the Mozilla Public License, v. 2.0.
+ README.md view
@@ -0,0 +1,25 @@+# Snappy Framing Format++[![Build Status](https://secure.travis-ci.org/kim/snappy-framing.png)](http://travis-ci.org/kim/snappy-framing)++Implementation of the [Snappy framing format](http://code.google.com/p/snappy/source/browse/trunk/framing_format.txt?r=71),+SVN rev 71.++## Build, Install, Use++Build from source using `cabal install`, from Hackage using `cabal install+snappy-framing`.++The library exports a single module, `Codec.Compression.Snappy.Framing`, with a+instance of `Data.Binary` doing all the work. A couple of convenience functions+are also provided, but for serious stream processing use of a streaming library+of your liking (eg. pipes, iteratees, conduit) is recommended.++## Bugs and Contributing++Please report issues via [Github Issues](https://github.com/kim/snappy-framing/issues),+patches are welcome as [Pull Requests](https://github.com/kim/snappy-framing/pulls).++## License++Mozilla Public License Version 2.0, see LICENSE file.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ snappy-framing.cabal view
@@ -0,0 +1,41 @@+name:                snappy-framing+version:             0.1.0+synopsis:            Snappy Framing Format in Haskell+homepage:            https://github.com/kim/snappy-framing+license:             OtherLicense+license-file:        LICENSE+author:              Kim Altintop+maintainer:          kim.altintop@gmail.com+copyright:           Copyright (c) 2013 Kim Altintop+category:            Codec+build-type:          Simple+cabal-version:       >=1.10++description:+  Implementation of the Snappy framing format (SVN revision 71, cf.+  <http://code.google.com/p/snappy/source/browse/trunk/framing_format.txt?r=71>)++extra-source-files:  README.md++source-repository head+  type:     git+  location: git://github.com/kim/snappy-framing.git++library+  default-language:  Haskell2010++  hs-source-dirs:    src++  ghc-options:      -Wall -fwarn-tabs -funbox-strict-fields+  ghc-prof-options: -prof -auto-all++  exposed-modules:   Codec.Compression.Snappy.Framing++  other-modules:     Data.Digest.CRC32C++  build-depends:+      array       >= 0.4+    , base        > 4 && < 5+    , binary      >= 0.7+    , bytestring  >= 0.10+    , snappy      >= 0.2.0.2
+ src/Codec/Compression/Snappy/Framing.hs view
@@ -0,0 +1,256 @@+{-# LANGUAGE OverloadedStrings #-}++-- |+-- Module      : Codec.Compression.Snappy.Framing+-- Copyright   : (c) 2013 Kim Altintop <kim.altintop@gmail.com>+-- License     : This Source Code Form is subject to the terms of+--               the Mozilla Public License, v. 2.0.+--               A copy of the MPL can be found in the LICENSE file or+--               you can obtain it at http://mozilla.org/MPL/2.0/.+-- Maintainer  : Kim Altintop <kim.altintop@gmail.com>+-- Stability   : experimental+-- Portability : non-portable (GHC extensions)+--++module Codec.Compression.Snappy.Framing+    ( -- * Exported Types+      Checksum+    , Chunk (..)+    , DecodeError++    -- * Encoding and Decoding+    , encode+    , encode'+    , decode+    , decode'+    , decodeVerify+    , decodeVerify'+    , decodeM+    , decodeVerifyM++    -- * Utility functions+    , checksum+    , streamIdentifier+    , verify+    ) where++import Control.Applicative+import Data.ByteString     (ByteString)+import Data.Binary         (Binary(..))+import Data.Binary.Get+import Data.Binary.Put+import Data.Bits+import Data.Digest.CRC32C+import Data.Word++import qualified Data.Binary              as Binary+import qualified Data.ByteString          as B+import qualified Data.ByteString.Lazy     as BL+import qualified Codec.Compression.Snappy as Snappy+++type Checksum = Word32++type DecodeError = (ByteOffset, String)++data Chunk = StreamIdentifier+           | Compressed   !Checksum !ByteString+           | Uncompressed !Checksum !ByteString+           | Skippable    !Word8+           | Unskippable  !Word8+    deriving (Eq, Show)+++streamStart :: [Word8]+streamStart = [0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59]++maxUncompressed :: Int+maxUncompressed = 65536++minCompressible :: Int+minCompressible = 18++instance Binary Chunk where+    put StreamIdentifier       = mapM_ put streamStart+    put (Compressed   chk dat) = putWord8 0x00 >> putData chk dat+    put (Uncompressed chk dat) = putWord8 0x01 >> putData chk dat+    put (Skippable    x)       = put x+    put (Unskippable  x)       = put x++    get = do+        chunktype <- getWord8+        case chunktype of+            0xff -> skip (length streamStart - 1) >> return StreamIdentifier+            0x00 -> return . uncurry Compressed   =<< getData+            0x01 -> return . uncurry Uncompressed =<< getData+            x | x >= 0x02 && x <= 0x7f -> return $ Unskippable x+              | x >= 0x80 && x <= 0xfe -> return $ Skippable x+              | otherwise -> error "junk chunk type"++getData :: Get (Checksum, ByteString)+getData = do+    len <- getWord24le+    chk <- getWord32le+    dat <- getByteString . fromIntegral $ len - 4+    return (chk, dat)++putData :: Checksum -> ByteString -> Put+putData chk dat = do+    putWord24le (B.length dat + 4)+    putWord32le chk+    putByteString dat++getWord24le :: Get Word32+getWord24le = do+    (a,b,c) <- (,,) <$> getWord8 <*> getWord8 <*> getWord8+    return $  (fromIntegral a :: Word32)+          .|. (fromIntegral b :: Word32) `shiftL` 8+          .|. (fromIntegral c :: Word32) `shiftL` 16++putWord24le :: Int -> Put+putWord24le x = mapM_ putWord8 bytes+  where+    bytes = [ fromIntegral ((fromIntegral x :: Word32) `shiftR` 0)  :: Word8+            , fromIntegral ((fromIntegral x :: Word32) `shiftR` 8)  :: Word8+            , fromIntegral ((fromIntegral x :: Word32) `shiftR` 16) :: Word8+            ]++-- | Compute a masked CRC32C checksum of the input+checksum :: ByteString -> Checksum+checksum a =+    let chksum = crc32c a+        masked = ((chksum `shiftR` 15) .|. (chksum `shiftL` 17)) + 0xa282ead8+     in masked++-- | Verify a 'Chunk'+--+-- Returns 'Nothing' if the input is an 'Unskippable' chunk, or the checksum+-- verification fails (if the input is a 'Compressed' or 'Uncompressed' chunk).+-- Otherwise, the input 'Chunk' is returned in a 'Just'. Note that 'Compressed'+-- chunks are decompressed into 'Uncompressed' chunks on the fly.+verify :: Chunk -> Maybe Chunk+verify u@(Uncompressed chk d) = if chk == checksum d then Just u else Nothing+verify (Compressed chk d)     = if ok then Just (Uncompressed chk d') else Nothing+  where+    d' = Snappy.decompress d+    ok = chk == checksum d'+verify (Unskippable _)        = Nothing+verify c                      = Just c++-- | Yield a stream identifier (start-of-stream marker)+streamIdentifier :: BL.ByteString+streamIdentifier = Binary.encode StreamIdentifier++-- | Encode a lazy 'BL.ByteString' into a 'Chunk'+--+-- If the input is longer than 'minCompressible' bytes, the resulting chunk is+-- 'Compressed' otherwise 'Uncompressed'. If the input size exceeds+-- 'maxUncompressed' bytes, the leftover input is returned in a 'Just'.+encode :: BL.ByteString -> (Chunk, Maybe BL.ByteString)+encode = go . split+  where+    go (x,xs) = (chunk $ BL.toStrict x, leftover' xs)++    chunk c+      | shouldCompress c = Compressed   (checksum c) (Snappy.compress c)+      | otherwise        = Uncompressed (checksum c) c++    split = BL.splitAt (fromIntegral maxUncompressed)++    leftover' x+      | BL.null x = Nothing+      | otherwise = Just x++-- | Encode a strict 'ByteString' into a 'Chunk'+--+-- If the input is longer than 'minCompressible' bytes, the resulting chunk is+-- 'Compressed' otherwise 'Uncompressed'. If the input size exceeds+-- 'maxUncompressed' bytes, the leftover input is returned in a 'Just'.+encode' :: ByteString -> (Chunk, Maybe ByteString)+encode' = go . split+  where+    go (x,xs) = (chunk x, leftover xs)++    chunk c+      | shouldCompress c = Compressed   (checksum c) (Snappy.compress c)+      | otherwise        = Uncompressed (checksum c) c++    split = B.splitAt maxUncompressed+++-- | Decode a lazy 'BL.ByteString' into a 'Chunk'+decode :: BL.ByteString -> (Either DecodeError Chunk, Maybe ByteString)+decode = dec . feed++-- | Decode a lazy 'BL.ByteString' into a 'Chunk' and 'verify' the result+decodeVerify :: BL.ByteString -> (Either DecodeError Chunk, Maybe ByteString)+decodeVerify = decV . feed++-- | Decode a strict 'ByteString' into a 'Chunk'+decode' :: ByteString -> (Either DecodeError Chunk, Maybe ByteString)+decode' = dec . feed'++-- | Decode a strict 'ByteString' into a 'Chunk' and 'verify' the result+decodeVerify' :: ByteString -> (Either DecodeError Chunk, Maybe ByteString)+decodeVerify' = decV . feed'++-- | Decode drawing input from the given monadic action as needed+decodeM :: Monad m+        => m (Maybe ByteString)+        -- ^ And action that will be run to provide input. If it returns+        -- 'Nothing' it is assumed no more input is available.+        -> m (Either DecodeError Chunk, Maybe ByteString)+        -- ^ Either a parse error or a 'Chunk', along with leftovers if any.+decodeM pull = go (runGetIncremental (get :: Get Chunk))+  where+    go (Partial k)  = go . k =<< pull+    go (Fail r n m) = return (Left (n, m), leftover r)+    go (Done r _ c) = return (Right c,     leftover r)++-- | Like 'decodeM', but 'verify' the result+decodeVerifyM :: Monad m+              => m (Maybe ByteString)+              -> m (Either DecodeError Chunk, Maybe ByteString)+decodeVerifyM pull = go (runGetIncremental (get :: Get Chunk))+  where+    go (Partial k)  = go . k =<< pull+    go (Fail r n m) = return (Left (n, m), leftover r)+    go (Done r n c) = case verify c of+                          Just c' -> return (Right c', leftover r)+                          Nothing -> go (Fail r n "verification failure")++--+-- Internal+--++shouldCompress :: ByteString -> Bool+shouldCompress x = B.length x >= minCompressible+{-# INLINEABLE shouldCompress #-}++feed :: BL.ByteString -> Decoder Chunk+feed = pushChunks $ runGetIncremental get+{-# INLINEABLE feed #-}++feed' :: ByteString -> Decoder Chunk+feed' = pushChunk $ runGetIncremental get+{-# INLINEABLE feed' #-}++dec :: Decoder Chunk -> (Either DecodeError Chunk, Maybe ByteString)+dec (Partial k)  = dec (k Nothing)+dec (Fail r n m) = (Left (n, m), leftover r)+dec (Done r _ c) = (Right c,     leftover r)+{-# INLINEABLE dec #-}++decV :: Decoder Chunk -> (Either DecodeError Chunk, Maybe ByteString)+decV (Partial k)  = decV (k Nothing)+decV (Fail r n m) = (Left (n, m), leftover r)+decV (Done r n c) = case verify c of+                        Just c' -> (Right c', leftover r)+                        Nothing -> decV (Fail r n "verification failure")+{-# INLINEABLE decV #-}++leftover :: ByteString -> Maybe ByteString+leftover x+  | B.null x  = Nothing+  | otherwise = Just x+{-# INLINEABLE leftover #-}
+ src/Data/Digest/CRC32C.hs view
@@ -0,0 +1,100 @@+module Data.Digest.CRC32C+    ( crc32c+    , crc32c_update+    ) where++import Data.Bits+import Data.ByteString    (ByteString)+import Data.Word+import Data.Array.Base    (unsafeAt)+import Data.Array.Unboxed++import qualified Data.ByteString as B+++crc32c :: ByteString -> Word32+crc32c = crc32c_update 0++crc32c_update :: Word32 -> ByteString -> Word32+crc32c_update crc bs = flipd $ step (flipd crc) bs+  where+    flipd = xor 0xffffffff++step :: Word32 -> ByteString -> Word32+step crc bs = B.foldl step' crc bs+  where+    step' acc b = let x = table !!! ((acc .&. 0xff) `xor` fromIntegral b)+                    in x `xor` (acc `shiftR` 8)+{-# INLINEABLE step #-}++(!!!) :: (IArray a e, Ix i, Integral i) => a i e -> i -> e+arr !!! i = unsafeAt arr $ fromIntegral i+{-# INLINEABLE (!!!) #-}++table :: UArray Word32 Word32+table = listArray (0,255) $+    [ 0x00000000, 0xf26b8303, 0xe13b70f7, 0x1350f3f4+    , 0xc79a971f, 0x35f1141c, 0x26a1e7e8, 0xd4ca64eb+    , 0x8ad958cf, 0x78b2dbcc, 0x6be22838, 0x9989ab3b+    , 0x4d43cfd0, 0xbf284cd3, 0xac78bf27, 0x5e133c24+    , 0x105ec76f, 0xe235446c, 0xf165b798, 0x030e349b+    , 0xd7c45070, 0x25afd373, 0x36ff2087, 0xc494a384+    , 0x9a879fa0, 0x68ec1ca3, 0x7bbcef57, 0x89d76c54+    , 0x5d1d08bf, 0xaf768bbc, 0xbc267848, 0x4e4dfb4b+    , 0x20bd8ede, 0xd2d60ddd, 0xc186fe29, 0x33ed7d2a+    , 0xe72719c1, 0x154c9ac2, 0x061c6936, 0xf477ea35+    , 0xaa64d611, 0x580f5512, 0x4b5fa6e6, 0xb93425e5+    , 0x6dfe410e, 0x9f95c20d, 0x8cc531f9, 0x7eaeb2fa+    , 0x30e349b1, 0xc288cab2, 0xd1d83946, 0x23b3ba45+    , 0xf779deae, 0x05125dad, 0x1642ae59, 0xe4292d5a+    , 0xba3a117e, 0x4851927d, 0x5b016189, 0xa96ae28a+    , 0x7da08661, 0x8fcb0562, 0x9c9bf696, 0x6ef07595+    , 0x417b1dbc, 0xb3109ebf, 0xa0406d4b, 0x522bee48+    , 0x86e18aa3, 0x748a09a0, 0x67dafa54, 0x95b17957+    , 0xcba24573, 0x39c9c670, 0x2a993584, 0xd8f2b687+    , 0x0c38d26c, 0xfe53516f, 0xed03a29b, 0x1f682198+    , 0x5125dad3, 0xa34e59d0, 0xb01eaa24, 0x42752927+    , 0x96bf4dcc, 0x64d4cecf, 0x77843d3b, 0x85efbe38+    , 0xdbfc821c, 0x2997011f, 0x3ac7f2eb, 0xc8ac71e8+    , 0x1c661503, 0xee0d9600, 0xfd5d65f4, 0x0f36e6f7+    , 0x61c69362, 0x93ad1061, 0x80fde395, 0x72966096+    , 0xa65c047d, 0x5437877e, 0x4767748a, 0xb50cf789+    , 0xeb1fcbad, 0x197448ae, 0x0a24bb5a, 0xf84f3859+    , 0x2c855cb2, 0xdeeedfb1, 0xcdbe2c45, 0x3fd5af46+    , 0x7198540d, 0x83f3d70e, 0x90a324fa, 0x62c8a7f9+    , 0xb602c312, 0x44694011, 0x5739b3e5, 0xa55230e6+    , 0xfb410cc2, 0x092a8fc1, 0x1a7a7c35, 0xe811ff36+    , 0x3cdb9bdd, 0xceb018de, 0xdde0eb2a, 0x2f8b6829+    , 0x82f63b78, 0x709db87b, 0x63cd4b8f, 0x91a6c88c+    , 0x456cac67, 0xb7072f64, 0xa457dc90, 0x563c5f93+    , 0x082f63b7, 0xfa44e0b4, 0xe9141340, 0x1b7f9043+    , 0xcfb5f4a8, 0x3dde77ab, 0x2e8e845f, 0xdce5075c+    , 0x92a8fc17, 0x60c37f14, 0x73938ce0, 0x81f80fe3+    , 0x55326b08, 0xa759e80b, 0xb4091bff, 0x466298fc+    , 0x1871a4d8, 0xea1a27db, 0xf94ad42f, 0x0b21572c+    , 0xdfeb33c7, 0x2d80b0c4, 0x3ed04330, 0xccbbc033+    , 0xa24bb5a6, 0x502036a5, 0x4370c551, 0xb11b4652+    , 0x65d122b9, 0x97baa1ba, 0x84ea524e, 0x7681d14d+    , 0x2892ed69, 0xdaf96e6a, 0xc9a99d9e, 0x3bc21e9d+    , 0xef087a76, 0x1d63f975, 0x0e330a81, 0xfc588982+    , 0xb21572c9, 0x407ef1ca, 0x532e023e, 0xa145813d+    , 0x758fe5d6, 0x87e466d5, 0x94b49521, 0x66df1622+    , 0x38cc2a06, 0xcaa7a905, 0xd9f75af1, 0x2b9cd9f2+    , 0xff56bd19, 0x0d3d3e1a, 0x1e6dcdee, 0xec064eed+    , 0xc38d26c4, 0x31e6a5c7, 0x22b65633, 0xd0ddd530+    , 0x0417b1db, 0xf67c32d8, 0xe52cc12c, 0x1747422f+    , 0x49547e0b, 0xbb3ffd08, 0xa86f0efc, 0x5a048dff+    , 0x8ecee914, 0x7ca56a17, 0x6ff599e3, 0x9d9e1ae0+    , 0xd3d3e1ab, 0x21b862a8, 0x32e8915c, 0xc083125f+    , 0x144976b4, 0xe622f5b7, 0xf5720643, 0x07198540+    , 0x590ab964, 0xab613a67, 0xb831c993, 0x4a5a4a90+    , 0x9e902e7b, 0x6cfbad78, 0x7fab5e8c, 0x8dc0dd8f+    , 0xe330a81a, 0x115b2b19, 0x020bd8ed, 0xf0605bee+    , 0x24aa3f05, 0xd6c1bc06, 0xc5914ff2, 0x37faccf1+    , 0x69e9f0d5, 0x9b8273d6, 0x88d28022, 0x7ab90321+    , 0xae7367ca, 0x5c18e4c9, 0x4f48173d, 0xbd23943e+    , 0xf36e6f75, 0x0105ec76, 0x12551f82, 0xe03e9c81+    , 0x34f4f86a, 0xc69f7b69, 0xd5cf889d, 0x27a40b9e+    , 0x79b737ba, 0x8bdcb4b9, 0x988c474d, 0x6ae7c44e+    , 0xbe2da0a5, 0x4c4623a6, 0x5f16d052, 0xad7d5351+    ]